[antlr-interest] pushed antlr build with tree rewriting and composite grammars (java)

David Holroyd dave at badgers-in-foil.co.uk
Sat Jan 12 17:49:35 PST 2008


On Sat, Jan 12, 2008 at 05:25:16PM -0800, Terence Parr wrote:
> >It seems that ANTLR is less happy about me trying to parse 'fragments'
> >now.
> >
> >i.e. if I set up the input "test", and then invoke
> >
> > MyParser.identifier()
> >
> >the generated parser now says
> >
> > NoViableAltException(-1!=[()* loopback of ..blah..]
> >
> >whereas this seemed to work with the earlier ANTLR releases, at least
> >for some rules.

> fragment rules are meant to be called only from other lexer rules; any  
> other usage is "off label" ;)

Sorry; bad choice of wording on my part, these are actually parser
rules.

'Snippet' might be a better term.  So, I want to parse a snippet of the
target language, rather than an entire compilation unit.

e.g., here's the definition of 'identifier',

  identifier 
    :   (   qualifiedIdent -> qualifiedIdent
        )
        (   options{greedy=true;}
        :   poi=propOrIdent[root_0, retval.start] -> $poi
        )*
        -> ^(IDENTIFIER $identifier)
    ;

With the input snippet "testpkg" I invoke the generated identifier()
method directly, and I see

  NoViableAltException(-1!=[()* loopback of 676:3: ( options {greedy=true;} : poi= propOrIdent[root_0, retval.start] -> $poi)*])

I assume the -1 in the message is EOF.


ta,
dave

-- 
http://david.holroyd.me.uk/


More information about the antlr-interest mailing list