Closed SparkFountain closed 3 years ago
Thanks for the suggestion! Should have been added long ago. Added in commit 700dc8. Will update issue when released
Released v.2.0.0 with this + many other changes
Unfortunately, this still does not seem to work in tsPEG 2.1.0.
Version Check:
$ tspeg --version
2.1.0
Grammar:
// this is a test comment
SUM := head=FAC tail={ op='\+|-' sm=FAC }*
FAC := head=ATOM tail={ op='\*|/' sm=ATOM }*
ATOM := _ val=INT _ | _ '\(' val=SUM '\)' _
INT := val='[0-9]+'
_ := '\s*'
Error Message:
SyntaxErr {
pos: { overallPos: 0, line: 1, offset: 0 },
exprules: [ 'GRAM' ],
expmatches: [ '---', '[a-zA-Z_]+' ]
}
Will investigate
Works on my machine. Can I see the command you ran to get this error?
<21:16>eoin@eoin-pc:/tmp/tspegtst$ cat tst.peg
// this is a test comment
SUM := head=FAC tail={ op='\+|-' sm=FAC }*
FAC := head=ATOM tail={ op='\*|/' sm=ATOM }*
ATOM := _ val=INT _ | _ '\(' val=SUM '\)' _
INT := val='[0-9]+'
_ := '\s*'
<21:16>eoin@eoin-pc:/tmp/tspegtst$ tspeg --version
2.1.0
<21:16>eoin@eoin-pc:/tmp/tspegtst$ tspeg tst.peg out.ts && echo "no errors"
no errors
<21:16>eoin@eoin-pc:/tmp/tspegtst$
Okay, probably it's because of the file ending. My grammar file was named "calculator.gram". After changing it to "calculator.peg" it works without any errors.
Thank you for your fast response and help @EoinDavey !
Glad I could help, but I don't think that the file extension should affect this.
<13:34>eoin@eoin-XPS:/tmp/tspegtst$ cat tst.gram
// this is a test comment
SUM := head=FAC tail={ op='\+|-' sm=FAC }*
FAC := head=ATOM tail={ op='\*|/' sm=ATOM }*
ATOM := _ val=INT _ | _ '\(' val=SUM '\)' _
INT := val='[0-9]+'
_ := '\s*'
<13:34>eoin@eoin-XPS:/tmp/tspegtst$ tspeg --version
2.1.0
<13:34>eoin@eoin-XPS:/tmp/tspegtst$ tspeg tst.gram out.ts
<13:35>eoin@eoin-XPS:/tmp/tspegtst$
My suspicion is that you may have a local version of tsPEG that is out of date (i.e. the version that is installed in the .node_modules directory) different from the global version (the version installed with npm i -g tspeg
). What do you get if you run npx tspeg --version
?
I found out there seems to be an issue with the file itself. When I created a new file in my IDE (VS Code) and copy-pasted the whole calculator grammar, tsPEG did not compile at all.
Conclusion: There must not be any file header, otherwise tsPEG parses that content and throws an error.
@EoinDavey Is it possible for you to ignore file headers and only read the actual file content?
I don't understand what you are saying about file headers, there should be no file header in a plain source code text file.
To aid in solving this problem could you provide the following information:
tspeg calculator.peg out.ts
or similar).Thanks
tspeg my-grammar.peg parser.ts
You are right, there should not be any file header in an empty file. However, VS Code seems to write some file header automatically when I create a new file with ending .peg or .gram. Of course, I can create my files with touch
instead, but it would be easier for developers if they could use their preferred IDE's and tsPEG would just ignore (erroneous) file headers anyway.
I am not aware of any issue that would cause VSCode to add headers to files as you describe, there is also no way to "ignore file headers". Attaching the my-grammar.peg
file or another file that is not compiling for you is the only way forward I see here
I like the simplicity of tsPEG very much. What would be helpful for me to develop bigger grammars and to not lose track is the possibility to add comments in .gram files.
Could you please add some kind of comment syntax (e. g.
#
or//
), at least for single lines or even multiple lines, which will simply be ignored by the parser generator? Would appreciate that very much :)