Excluding Certain Elements From A Specified Set In Parsing Expressive Grammar (PEG.js)?
I am writing a lexer for Haskell using JavaScript and Parsing Expression Grammar, the implementation I use being PEG.js. I have a problem with making it work for reserved words, as
Solution 1:
!reserved ident
is a perfectly acceptable technique in any PEG implementation, and PEG.js seems to support it as well. Btw, you should add !id
after the definition of reserved
.
Solution 2:
As far as I know, PEG rules are positional. That basically means that rules are tried deterministically from the first to the last one. That said, you just need to put the "reserved" rule before declaring the "identifier" one.
Post a Comment for "Excluding Certain Elements From A Specified Set In Parsing Expressive Grammar (PEG.js)?"