Hi,
during the weekend, two big changes landed in PEG.js's master:
position tracking redesign and lexer-level rules simplification.
Position tracking redesign
--------------------------
I changed the "line" and "column" variables that contained current
line and column to functions. This allowed computing position data
lazily and without any significant performance degradation in case the
data is not needed. As a result, position tracking does not need to be
enabled explicitly anymore (the "trackLineAndColumn" option is gone)
and the code generator got somewhat simpler.
Commits:
https://github.com/dmajda/pegjs/compare/da9ab1bf17...28860e88df
Lexer-level rules simplification
--------------------------------
This feature introduces a new prefix operator: "$". Applied to an
expression, it changes its match result from whatever it was to a
string the expression matched in the input. For example, while parser
generated from this grammar:
start = "a"+
will return ["a", "a", "a"] given input "aaa", a parser generated from
this grammar:
start = $"a"+
will return just "aaa".
This is useful mostly for "lexical" rules at the bottom of many
grammars. For example, instead of:
identifier = first:[a-zA-Z_] rest:[a-zA-Z0-9_]* {
return first + rest.join("");
}
you can now just write:
identifier = $([a-zA-Z_] [a-zA-Z0-9_]*)
The feature also opens room for some interesting optimizations.
While I am pretty sure about the feature itself, I am not 100%
convinced about the syntax -- the current one resembles shell/Makefile
variables too much for my taste. I welcome any suggestions.
Commits:
https://github.com/dmajda/pegjs/compare/4e46a6e46e...c54483bb17
--
David Majda
Entropy fighter
http://majda.cz/