[antlr-interest] Rewrite rule problem

Roger Jack rjack at elegancetech.com
Mon Nov 5 05:39:01 PST 2012


Below are 3 rules from a grammar that I'm working on:

Snippet qualified_open_type_name: 
'Global' (PERIOD identifier_or_keyword type_arity_list?)+ 
-> 'Global' ^(PERIOD identifier_or_keyword type_arity_list?)+;

type_arity_list: OPEN_PARENTHESIS 'Of' comma_list? CLOSE_PARENTHESIS 
-> ^('Of' comma_list?);

comma_list: COMMA+;

When I call the qualified_open_type_name rule, I get the following results:

input: Global.AnId1.AnId2
tree: Global (. (ID AnId1)) (. (ID AnId2)) <- This is correct.

input: Global.AnId1 (Of ,,,).AnId2
tree: Global (. (ID AnId1) (Of , , ,)) (. (ID AnId2) (Of , , ,)) <- 
Incorrect. The last (Of , , ,) should not be there.

Is my grammar incorrect? Is this a known bug? If it matters I'm using C# 
as the output language.

Thanks!

-- 
Roger Jack



More information about the antlr-interest mailing list