[antlr-interest] Defining a function in antlr javascript

John B. Brodie jbb at acm.org
Thu Apr 29 11:35:18 PDT 2010


Greetings!

On Thu, 2010-04-29 at 14:29 -0400, Kunal Sawlani wrote:
> Hi All,
> I have been using the javascript target of ANTLR to generate a recognizer
> for my web page. It is working as expected, so I wanted to factor the code,
> to move some common functionality to a function inside the @members section.
> For some reason,
> this definition is not getting picked up, and the recognizer reports that
> the function is not defined. Any idea whether, this a bug in the javascript
> target?
> I am using the normal function definition, i.e., function doSomething(){}
> inside the @members section.
> 
> Has anyone run into this issue? Any help would be great!

It is hard to really know for sure without seeing your grammar (or
rather the smallest subset of your grammar that exhibits the problem).

But off-hand are you calling your "doSomething" function from your Lexer
rule(s)?

@members only includes stuff into the parser portion of a combined
grammar. use @lexer::members to incorporate stuff into the lexer portion
of a combined grammar.

hope this helps, if not maybe post an example grammar....
   -jbb





More information about the antlr-interest mailing list