4
votes

i have problem with @members rule in ANTLR. I want overwrite default error handling, so i read http://www.antlr.org/wiki/display/ANTLR3/Error+reporting+and+recovery and write this simple code for my grammar:

@members {
   def displayRecognitionError(self, tokenNames, e):
      print 'Test'
}

I have no @lexer::members or @parser::members in my grammar. Code (python runtime) from this rule is included only in parser file, not in lexer. It is a bug? I think it is, @members should add content to both - lexer and parser according to documentation. I use Python runtime, 3.1.3.

Btw. is stackoverflow inline code work's for Opera?

1

1 Answers

7
votes

In a combined grammar file, @members is a short-hand for @parser::members.

// combined grammar
grammar Foo;

@members {
  // only parser members here, equivalent to: @parser::members { ... }
}

@lexer::members {
  // lexer members
}

When you use separate lexer- and/or parser grammars, then @members is enough:

parser grammar Foo;

@members {
  // parser members
}

or

lexer grammar Foo;

@members {
  // lexer members
}

Galmi wrote:

Btw. is stackoverflow inline code work's for Opera?

I guess so, but questions about SO itself can be asked on SO-Meta.