Maybe @scopeinit{...} is better?
My goal is to replace this:
attrScope
scope
{
Dictionary<GrammarAST, GrammarAST> actions;
}
@init
{
$attrScope::actions = new Dictionary<GrammarAST, GrammarAST>();
}
: ^( 'scope' name=ID attrScopeAction* attrs=ACTION )
{
AttributeScope scope =
grammar.defineGlobalScope($name.text,$attrs.token);
scope.isDynamicGlobalScope = true;
scope.addAttributes($attrs.text, ';');
foreach ( var action in $attrScope::actions )
scope.DefineNamedAction( action.Key,
action.Value );
}
;
With this:
attrScope
scope
@init // or @scopeinit?
{
actions = new Dictionary<GrammarAST, GrammarAST>();
}
{
Dictionary<GrammarAST, GrammarAST> actions;
}
: ^( 'scope' name=ID attrScopeAction* attrs=ACTION )
{
AttributeScope scope =
grammar.defineGlobalScope($name.text,$attrs.token);
scope.isDynamicGlobalScope = true;
scope.addAttributes($attrs.text, ';');
foreach ( var action in $attrScope::actions )
scope.DefineNamedAction( action.Key,
action.Value );
}
;
For global attribute scopes, the @init would only go at the declaration
of the attribute scope, not in the individual rules that use that scope.
As I briefly mentioned before, I do need this ability for another
feature I'm working on. On a side note, yes, I used my actually
implementation of this feature for the example.
Sam
From: [email protected] [mailto:[email protected]]
On Behalf Of Sam Harwell
Sent: Wednesday, January 21, 2009 10:14 AM
To: [email protected]
Subject: [antlr-dev] @init for global scopes?
I'd like to add a @init{} support for global scopes. The code from the
@init would simply go in the scope class' constructor. Any objections?
Sam
_______________________________________________
antlr-dev mailing list
[email protected]
http://www.antlr.org/mailman/listinfo/antlr-dev