Hi!
2012/6/27 Steve Ross <
sxr...@gmail.com>:
Emitting desired output directly from parsing actions is a valid
technique. It is useful mainly for small and simple parsers where
processing some kind of parser output in a separate piece of code
would just add needless complexity.
Generating an abstract input representation and generating the output
from it as a separate step outside the parser is more suitable for
bigger parser or parsers that require more processing/transformations
(and thus more code). In such cases, separating the concerns can help
readability and maintainability of the code. Moreover, you can write
the output-emitting code in pure JavaScript so you can use all the
features your editor/IDE provides for it that may not be available for
PEG.js grammars.
Note that I wouldn't recommend using PEG.js's native tree format as an
input to output generation code. It is much better to create some more
abstract representation, e.g. a tree of JavaScript objects. Look at
the "examples" directory in PEG.js how such parsers can look like.
--
David Majda
Entropy fighter
http://majda.cz/