Greetings.
I continue to wrestle with rewrite rules for AST construction. I am trying to
treat semicolon and newline as equivalent separators, and gather a sequence of
expressions as children of a single AST node. The grammar looks like
=======
grammar Test;
options {output=AST;}
prog: expr EOF!;
expr: (term->term) (((NL|SC) term)+ -> ^(NL $expr term+))?;
term: ID
| ->ID // empty treated as no-name ID
;
fragment
SP : ' '|'\t';
SC : ';';
ID : SP*
('a'..'z'|'A'..'Z'|'_')
('0'..'9'|'a'..'z'|'A'..'Z'|'_')*
;
NL : ('\r'|'\n')+;
=======
The problem is that if the sequence does *not* include newline, then i get
RewriteEmptyStreamException on the NL in the rewrite rule; i.e. "a;\n" works,
but "a;" does not.
What particularly baffles me is that if i build the node with any token other
than NL or SC (e.g. SP), then the rule *always* works.
Could someone please explain what is going on?
Thanks
TJ
--
Trevor John Thompson net: [email protected]
Quidquid Latine dictum sit, altum videtur.
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en.