The G parameter that gets passed in to each rule stands for
"Greedy", and determines whether or not that rule is to consume
newlines after the last terminal in that rule. We need to pass it
everywhere so it can go all the way to the last terminal deep
inside the parse tree, which can then decide whether or not to
consume whitespace.
The vast majority of terminals will consume newlines; only rules
which occur in {} blocks won't have their terminals consume newlines,
and only the *last* terminal in the rule will be affected.
That's why the parser does terminals-consume-newlines-by-default,
and leaves it up to the dev to thread the G variable where-ever
we want the opposite behavior.
Parser for Scala syntax.
The
Gparameter that gets passed in to each rule stands for "Greedy", and determines whether or not that rule is to consume newlines after the last terminal in that rule. We need to pass it everywhere so it can go all the way to the last terminal deep inside the parse tree, which can then decide whether or not to consume whitespace.The vast majority of terminals will consume newlines; only rules which occur in {} blocks won't have their terminals consume newlines, and only the *last* terminal in the rule will be affected. That's why the parser does terminals-consume-newlines-by-default, and leaves it up to the dev to thread the
Gvariable where-ever we want the opposite behavior.