Hi Franck,

On Sat, Nov 26, 2011 at 8:54 AM, franck102 <franck...@yahoo.com> wrote:

> The grammar below won't compile, this looks like a bug to me?
> ...


No bug, syntactic predicates and rule parameters can't be mixed. You can
use rule scopes instead:

---------------------------------

grammar Test;

options {
  output=AST;
  backtrack=true;
  ASTLabelType=CommonTree;
}

program
scope { String x; }
@init { $program::x = null; }
  :  'raw'? (ID {$program::x=$ID.text;} -> ID) (rule -> rule)*
  |  'raw' ID
  ;

rule
  :  'some' ID {System.out.println("called from: " + $program::x);}
  ;

ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*;
WS : (' ' | '\t' | '\r' | '\n') {$channel=HIDDEN;};

---------------------------------

If you now parse "raw A some B", then "called from: A" will be printed to
your console.

Also, you're trying to pass the tree of `program` as a parameter, but that
tree hasn't been constructed yet, AFAIK (and will therefor be `null`).
That's why my example shows how to use rule scopes with a simple string.

Regards,

Bart.

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 il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to