[antlr-interest] adding node to AST
Donal Murtagh
donalmurtagh at yahoo.co.uk
Fri Dec 2 04:07:45 PST 2005
Hi,
I'm trying to build an AST for the following type of block:
SubscriptionManager:2
{}
I need to check that the SubscriptionManager token *does* end with :INT, and add it as a node.
I'm trying to do this with this rule:
subscriptionManager!
{ boolean oldSubMgr = true; }
: x:"SubscriptionManager" (":" sm:INT { oldSubMgr = false; } )?
{
#subscriptionManager = #x;
if(oldSubMgr) {
throw new Exception("bad format");
}
}
LBRACE!
RBRACE!
;
However the ":2" is missing from the node - presumably because x only matches
"SubscriptionManager".
I previously tried to add the node in the usual way, using '^' (with the '!' removed from the rule
name and the line "#subscriptionManager = #x;" omitted).
I tried all of the following, but no luck:
x^:"SubscriptionManager" (":" sm:INT { oldSubMgr = false; } )?
x:"SubscriptionManager" (":" sm:INT { oldSubMgr = false; } )?^
x:("SubscriptionManager" (":" sm:INT { oldSubMgr = false; } )?)^
Many thanks in advance for any help!
Cheers,
Don
___________________________________________________________
WIN ONE OF THREE YAHOO! VESPAS - Enter now! - http://uk.cars.yahoo.com/features/competitions/vespa.html
More information about the antlr-interest
mailing list