francoispqt / gojay

high performance JSON encoder/decoder with stream API for Golang
MIT License
2.11k stars 112 forks source link

expected 'IDENT', found '/' #120

Open OGKevin opened 5 years ago

OGKevin commented 5 years ago

When generating a struct with 1 string field or any number of fields, i manage to get

4:9: expected 'IDENT', found '/' error.

e.g.

type Show struct { 
 SomeString string
}

and then

//go:generate gojay -s $GOFILE -p true -t Show -o $GOFILE.gojay.go

On top of the file generates that error.

Any ideas what might be causing this?

syllabix commented 5 years ago

this error is returned from the call to the standard libs format.Source at line 123 in generator.go. If you provide a path including the filename to -s and do not specify what package the generated output should be in - gojay will output a package name that is invalid source code - effectively the full path to the directory the target file is in.

// Code generated by Gojay. DO NOT EDIT. package /Users/myuser/go/src/github.com/foo/my-package

This does appear to be a bug and not user error as the -pkg flag is not required. That said - the workaround with the existing version is to provide a valid package name to the -pkg flag or not provide the filename to the -s flag and ensure that -o is set to the correct destination.

the bug itself appears to be at line 241 in generator.go where the output package name is not set correctly. happy to open a simple PR for this one if it is the case

zorro786 commented 3 years ago

Thank you @syllabix for the workaround!!