diff --git a/README.md b/README.md index 4ff15e657..ab9bcc5fc 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,11 @@ How do we do this in the Go language? ```go package main +import "fmt" + func main() { a := []float64{1, 2, 3.4} - println(a) + fmt.Println(a) } ``` diff --git a/cl/class_file.go b/cl/class_file.go index 9f532d7e4..2dcc98bc8 100644 --- a/cl/class_file.go +++ b/cl/class_file.go @@ -39,7 +39,7 @@ type gmxInfo struct { var ( gmxTypes = map[string]gmxInfo{ - ".gmx": {".spx", []string{"github.com/goplus/spx", "math"}}, + ".gmx": {".spx", []string{"github.com/goplus/spx"}}, } ) diff --git a/cl/compile_test.go b/cl/compile_test.go index dc5abf07c..c9af6c52a 100644 --- a/cl/compile_test.go +++ b/cl/compile_test.go @@ -2353,6 +2353,14 @@ var a = math.Round(1.2) `) } +func _TestLocalImport(t *testing.T) { + gopClTest(t, `import "./internal/spx" + +var a = spx.TestIntValue +`, ` +`) +} + func TestImportUnused(t *testing.T) { gopClTest(t, `import "fmt" diff --git a/parser/parser.go b/parser/parser.go index 73ab20be0..494912315 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -1340,7 +1340,7 @@ func (p *parser) isCommand(x ast.Expr) bool { case token.IDENT, token.RARROW, token.STRING, token.INT, token.FLOAT, token.IMAG, token.CHAR, token.RAT: return true - case token.SUB, token.NOT, token.AND, token.MUL, token.ARROW, token.XOR: + case token.SUB, token.NOT, token.AND, token.MUL, token.ARROW, token.XOR, token.ADD: if x.End() == p.pos { // x-y return false } diff --git a/printer/gop_test.go b/printer/gop_test.go index 258a4fa0d..ff4b68ed5 100644 --- a/printer/gop_test.go +++ b/printer/gop_test.go @@ -29,6 +29,10 @@ import ( "github.com/goplus/gop/token" ) +func init() { + printer.SetDebug(printer.DbgFlagAll) +} + func TestNoPkgDecl(t *testing.T) { var dst bytes.Buffer fset := token.NewFileSet() diff --git a/printer/nodes.go b/printer/nodes.go index 8afad5ad3..60ba7ecef 100644 --- a/printer/nodes.go +++ b/printer/nodes.go @@ -37,6 +37,20 @@ import ( "github.com/goplus/gop/token" ) +const ( + DbgFlagAll = 1 +) + +var ( + debugFormat bool +) + +func SetDebug(flags int) { + if flags != 0 { + debugFormat = true + } +} + // Formatting issues: // - better comment formatting for /*-style comments at the end of a line (e.g. a declaration) // when the comment spans multiple lines; if such a comment is just two lines, formatting is @@ -1320,6 +1334,11 @@ func (p *printer) stmt(stmt ast.Stmt, nextIsRBrace bool) { p.stmt(s.Stmt, nextIsRBrace) case *ast.ExprStmt: + if debugFormat { + if e, ok := s.X.(*ast.CallExpr); ok { + log.Println("==> ExprStmt", e.Fun) + } + } const depth = 1 p.expr0(s.X, depth) @@ -1335,6 +1354,9 @@ func (p *printer) stmt(stmt ast.Stmt, nextIsRBrace bool) { p.print(s.TokPos, s.Tok) case *ast.AssignStmt: + if debugFormat { + log.Println("==> AssignStmt", s.Lhs) + } var depth = 1 if len(s.Lhs) > 1 && len(s.Rhs) > 1 { depth++ @@ -1912,6 +1934,9 @@ func (p *printer) distanceFrom(startPos token.Pos, startOutCol int) int { } func (p *printer) funcDecl(d *ast.FuncDecl) { + if debugFormat { + log.Println("==> Format Func", d.Name.Name) + } p.setComment(d.Doc) if p.unnamedFuncName == d.Name.Name {