Coder Social home page Coder Social logo

igo's Introduction

iGo, Intermediate Golang

This project provides an intermediate source representation of go source files.

Most of the code comes directly from the standard library of pkg/go however the core part, parser and scanner has been heavily modified, the igo ast instead is pretty much unchanged to allow an easily swap with the original one.

The aim of this project is to provide an alternative go fmt which means the you will be able to write as you like and then distribute in the standard go way (*.go formatted files).

It's in beta stage

How it works?

You can TRY IT on play.igolang.io or with the cli:

usage: igo [compile|parse|build] [flags] [path ...]
  -comments=true: print comments
  -dest="": destination directory
  -tabs=true: indent with tabs
  -tabwidth=8: tab width
$ igo parse # will convert any *.go file in *.igo
$ igo compile # will convert *.igo source code in *.go

Note that build currently is not yet implemented.

Manually convert go code:

import
	"bytes"
	"fmt"
	"github.com/DAddYE/igo/from_go"
	"go/parser"
	"go/token"
	"io/ioutil"
	"log"
	"testing"

func ExampleFromGo()
  # Initialize the scanner.
  fset := token.NewFileSet() # positions are relative to fset

  const filename = "../ast/ast.go"

  src, err := ioutil.ReadFile(filename)
  if err != nil
    log.Fatalf("%s", err)


  file, err := parser.ParseFile(fset, filename, src, parser.ParseComments)
  if err != nil
    fmt.Println(err)
    return

  # Print the function body into buffer buf.
  # The file set is provided to the printer so that it knows
  # about the original source formatting and can add additional
  # line breaks where they were present in the source.
  var buf bytes.Buffer
  from_go.Fprint(&buf, fset, file)

  # Print the cleaned-up body text to stdout.
  fmt.Println(&buf)

Manually convert iGo code:

import
	"bytes"
	"fmt"
	"github.com/DAddYE/igo/parser"
	"github.com/DAddYE/igo/to_go"
	"github.com/DAddYE/igo/token"
	"io/ioutil"
	"log"
	"testing"

func ExampleToGo()
	# Initialize the scanner.
	fset := token.NewFileSet() # positions are relative to fset

	const filename = "../ast/ast.igo"

	src, err := ioutil.ReadFile(filename)
	if err != nil
		log.Fatalf("%s", err)

	file, err := parser.ParseFile(fset, filename, src, parser.ParseComments)
	if err != nil
		fmt.Println(err)
		return

	# Print the function body into buffer buf.
	# The file set is provided to the printer so that it knows
	# about the original source formatting and can add additional
	# line breaks where they were present in the source.
	var buf bytes.Buffer
	to_go.Fprint(&buf, fset, file)

	# Print the cleaned-up body text to stdout.
	fmt.Println(&buf)

How looks like?

Just browse *.igo files, but soon I'll make a ebnf notation.

What will change?

Pretty much really few things, golang itself is almost perfect, this parser will allow you to skip some annoyance. Nothing more.

Editors

  • Vim
  • add yours ...

What's left?

In my roadmap there is:

  • Builds (aka igo build|run|test)
  • Add GoCode like for editors
  • iGo format (aka igo fmt)
  • iGo doc (aka igo doc)
  • Expose ast (aka little macros)
  • Expose __filename__, __fname__

Other info

This project was partially influenced by Nimrod which I highly suggest to try.

License MIT/BSD-style

Author Davide D'Agostino (@DAddYE) and The Go Authors

igo's People

Contributors

daddye avatar vendethiel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

igo's Issues

How about removing brackets of calling functions?

Hi, I love your project. I made my attempt too before, by stupidly adding curly brackets by counting indentations. And here is it: https://github.com/Cirru/goose .

I didn't learn the skills of parsing the whole language. Also, I'm still wondering about how it would be if we remove some more brackets from Go's syntax, like Ruby, in which f(a, b) can be write like f a, b.

May I ask your opinion about it?

Very cool project, how is compatibility nowadays?

This is a great idea. Love whitespace significant style of Python, Boo and Nim. Saves a literal ton of code.

Anyone using this in the pipeline for real projects now or in the past? Experiences?

Can it be used with the latest Golang?

Short function declaration bug (BadDecl)

Using short function declaration seems to cause parsing error of next function.

package main

func hello(text string)
    fmt.Println(text)

func hello2(text string): fmt.Println(text)

func main()
    return

Gives

package main

func hello(text string) {
    fmt.Println(text)
}
func hello2(text string)    { fmt.Println(text) }

BadDecl

Note BadDecl instead of main function definition.

Request for `igo run`

Since I have been using CoffeeScript for a long time, there are some practice that I think maybe some of them fit igo too.

  • In CoffeeScript, running coffee enters interactive mode there's another igo for that. But for Go, repl might be less useful.
  • When a user runs coffee file.coffee, code in that file is evaluated directly, just like it's just a language and steps of debugging does not contain something like "convert it to another language".
  • Putting .js and .coffee file side by side is quite painful when the projects get larger. Because theres a lot of changes people click by mistake.

I suppose igo run would make it a lot simpler for people to use igo.

igo/parser panics on empty string input.

The standard parser does not panic with same input. It returns an error.

package main

import (
    igo_parser "github.com/daddye/igo/parser"
    igo_token "github.com/daddye/igo/token"

    "fmt"
)

func main() {
    fset := igo_token.NewFileSet()
    _, err := igo_parser.ParseFile(fset, "", "", igo_parser.ParseComments|igo_parser.AllErrors)
    // Above panics.
    fmt.Println(err)
}
package main

import (
    "go/parser"
    "go/token"

    "fmt"
)

func main() {
    fset := token.NewFileSet()
    _, err := parser.ParseFile(fset, "", "", parser.ParseComments|parser.AllErrors)
    // No panic, but non-nil error.
    fmt.Println(err)
}

image

Import path case mismatch.

Your github username has upper case letters in it, which leads to an import path like:

"github.com/DAddYE/igo/from_go"

For example, if you go to http://godoc.org/github.com/DAddYE/igo/from_go it works. But http://godoc.org/github.com/daddye/igo/from_go is not found.

However, you use "github.com/daddye/igo/..." imports internally, which works. But when someone imports your package like via its actual import path with upper case letters, they get this error:

can't load package: case-insensitive import collision: "github.com/DAddYE/igo/token" and "github.com/daddye/igo/token"

I think the best thing to do is to change all your internal imports to be "github.com/DAddYE/igo/..." to match the spelling of your GitHub username (unless you're planning to change your GitHub username from DAddYE to daddye). That should avoid this and other unexpected problems from happening.

project status?

just a quick question - is this dead or still under development?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.