Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't parse valid go file #1

Open
ont opened this issue Sep 8, 2021 · 1 comment
Open

Can't parse valid go file #1

ont opened this issue Sep 8, 2021 · 1 comment

Comments

@ont
Copy link

ont commented Sep 8, 2021

Can't parse very simple file (log from ipython session):

In [1]: import gopygo

In [2]: txt = open('/tmp/test.go').read()

In [3]: txt
Out[3]: 'package main\n\nimport (\n\t"log"\n\n\t"project/internal"\n\n\t"github.com/goava/di"\n)\n\nfunc main() {\n\tdi.SetTracer(&di.StdTracer{})\n\n\t_, err := di.New(\n\t\tinternal.ViperModule,\n\t\tinternal.BoilerModule,\n\t\tinternal.IdentModule,\n\t\tinternal.JwtModule,\n\t\tinternal.EchoModule,\n\t)\n\tif err != nil {\n\t\tlog.Fatalln("error:", err)\n\t}\n}\n'

In [4]: print(txt)
package main

import (
	"log"

	"project/internal"

	"github.com/goava/di"
)

func main() {
	di.SetTracer(&di.StdTracer{})

	_, err := di.New(
		internal.ViperModule,
		internal.BoilerModule,
		internal.IdentModule,
		internal.JwtModule,
		internal.EchoModule,
	)
	if err != nil {
		log.Fatalln("error:", err)
	}
}


In [5]: gopygo.parse(txt)
sly: Syntax error at line 1, token=STRING_LITERAL
sly: Syntax error at line 1, token=RPAREN
sly: Syntax error at line 1, token=LBRACE
sly: Syntax error at line 1, token=NEWLINE
sly: Syntax error at line 1, token=IDENT
sly: Syntax error at line 1, token=IDENT
sly: Syntax error at line 1, token=IDENT
sly: Syntax error at line 1, token=IDENT
sly: Syntax error at line 1, token=RPAREN
sly: Syntax error at line 1, token=RBRACE
@mertyildiran
Copy link
Member

@ont Hi, thank you so much for reporting this issue. The parser does not cover the whole Go grammar as of its current state. The line number tracking of the parser is also broken. Therefore it's hard to tell, exactly on what line it throws a syntax error. I suspect that, it's _, err := di.New( or the following lines.

The parser is defined in the form of Yacc grammar in this file. It might be possible to identify the issue by simplifying the test case and playing with the grammar rules in that file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants