[antlr-interest] Rewrite rule in Habelitz Java grammar ignored?

Jim Idle jimi at temporal-wave.com
Fri Jul 20 12:22:33 PDT 2012


Did you try:

javaSource
     :   compilationUnit EOF
         ->  ^(JAVA_SOURCE compilationUnit)


And insure that you are invoking the parser via the javaSource rule?

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Jason Veldicott
> Sent: Friday, July 20, 2012 12:04 PM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Rewrite rule in Habelitz Java grammar
> ignored?
>
> Hi,
>
> I'm trying to get Habelitz's
> (http://www.habelitz.com<http://www.habelitz.com/index.php?option=com_c
> ontent&task=view&id=12&Itemid=8>)
> Java
> grammar running, java.g, and have encountered a problem in which the
> following top-level parser rule:
>
> javaSource
>     :   compilationUnit
>         ->  ^(JAVA_SOURCE compilationUnit)
>
>
> does not produce an AST rooted with JAVA_SOURCE, but instead with a
> node named ANNOTATION_LIST, which comes later in the grammar.  A longer
> listing of the produced AST appears at end of this post.
>
> It seems the rewrite part of this rule is ignored.  I need it not to
> be, otherwise the accompanying JavaTreeParser.g (by Habelitz) results
> in this
> error:
>
> JavaTreeParser.g: node from line 0:0 mismatched tree node:
> ANNOTATION_LIST expecting JAVA_SOURCE
>
>
> Any suggestion as to what my be going wrong here would be much
> appreciated.
>
> Thanks
>
> Jason
>
>
> tree=ANNOTATION_LIST (import (. (. java io) File)) (class
> (MODIFIER_LIST
> public) Test1 (CLASS_TOP_LEVEL_SCOPE (VOID_METHOD_DECL (MODIFIER_LIST
> public) test FORMAL_PARAM_LIST (BLOCK_SCOPE (EXPR (METHOD_CALL (. (.
> System
> out) println) (ARGUMENT_LIST (EXPR "testing")))))))) null
>      ANNOTATION_LIST
>      import
>           .
>                .
>                     java
>                     io
>                File
>      class
>           MODIFIER_LIST
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address


More information about the antlr-interest mailing list