Example #1
0
// ParseExpr is a convenience function for obtaining the AST of an expression x.
// The position information recorded in the AST is undefined. The filename used
// in error messages is the empty string.
//
func ParseExpr(x string) (ast.Expr, error) {
	var p parser
	p.init(token.NewFileSet(), "", []byte(x), 0)

	// Set up pkg-level scopes to avoid nil-pointer errors.
	// This is not needed for a correct expression x as the
	// parser will be ok with a nil topScope, but be cautious
	// in case of an erroneous x.
	p.openScope()
	p.pkgScope = p.topScope
	e := p.parseRhsOrType()
	p.closeScope()
	assert(p.topScope == nil, "unbalanced scopes")

	if p.errors.Len() > 0 {
		p.errors.Sort()
		return nil, p.errors.Err()
	}

	return e, nil
}
Example #2
0
	printer "github.com/DAddYE/igo/to_go"

	"github.com/DAddYE/igo/ast"
	"github.com/DAddYE/igo/parser"
	"github.com/DAddYE/igo/scanner"
	"github.com/DAddYE/igo/token"

	"io"
	"io/ioutil"
	"os"
	"strings"
)

var (
	IgoPositions   = make(map[string]*printer.Positions)
	igoFileSet     = token.NewFileSet() // per process FileSet
	igoParserMode  parser.Mode
	igoPrinterMode printer.Mode
)

func igoReport(err error) {
	scanner.PrintError(os.Stderr, err)
	exitCode = 2
}

func igoInit() {
	igoParserMode = parser.Mode(0)
	if *comments {
		igoParserMode |= parser.ParseComments
	}
	igoParserMode |= parser.AllErrors