antlr / antlr3

antlr v3 repository (pulled from p4 with history from //depot/code/antlr/antlr3-main
http://www.antlr.org
241 stars 170 forks source link

Antlr 3.4 error compiling to Java target #34

Closed rajah9 closed 11 years ago

rajah9 commented 12 years ago

I am getting four Java compile error on a grammar.

I'm using Eclipse Indigo SR2 and these plugins:

I am having Eclipse place the generated Java code in a package antlr-generated. The build path for antlr-generated includes antlr-3.4-complete.jar.

Here is my grammar (line numbers added):

/* Entry point */
 8: swiftMessage: block4 ;

10: block4: STARTBLOCK '4:' tag_value_pair+ ENDMESSAGEBLOCK ;

12: tag_value_pair :   NEWLINE tag value ;

16: tag :  COLON '1'..'9' '0'..'9' ('A'..'Z')?  ;

18: value :   COLON ('a'..'z' | 'A'..'Z' | '0'..'9' | ' ' | ',' | '.' )* ;

20: STARTBLOCK : '{' ;

22: ENDMESSAGEBLOCK : '-}' ;

24: NEWLINE : '\n' ;

26: COLON: ':' ; 

Here is the generated SwiftBugParser code (portions of comments ommitted; four errors noted):

    // $ANTLR start "tag"
    // \\SwiftBug.g:16:1: tag : COLON '1' .. '9' '0' .. '9' ( 'A' .. 'Z' )? ;
    public final void tag() throws RecognitionException {
        try {
            // \\SwiftBug.g:16:5: ( COLON '1' .. '9' '0' .. '9' ( 'A' .. 'Z' )? )
            // \\SwiftBug.g:16:8: COLON '1' .. '9' '0' .. '9' ( 'A' .. 'Z' )?
            {
            match(input,COLON,FOLLOW_COLON_in_tag68); 

            matchRange('1','9');  // FIRST ERROR, LINE 193

            matchRange('0','9');  // SECOND ERROR, LINE 195

            // \\SwiftBug.g:16:32: ( 'A' .. 'Z' )?
            int alt2=2;
            int LA2_0 = input.LA(1);

            if ( () ) {           // THIRD ERROR, LINE 201
                alt2=1;
            }
            switch (alt2) {
                case 1 :
                    // \\SwiftBug.g:
                    {
                    if (  ) {     // FOURTH ERROR, LINE 208
                        input.consume();
                        state.errorRecovery=false;
                    }
                    else {
                        MismatchedSetException mse = new MismatchedSetException(null,input);
                        throw mse;
                    }

                    }
                    break;

            }

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
            // do for sure before leaving
        }
        return ;
    }
    // $ANTLR end "tag"

I am getting these four Java compilation errors:

Description Resource    Path    Location    Type
The method matchRange(char, char) is undefined for the type SwiftBugParser  SwiftBugParser.java /SwiftMessage/antlr-generated   line 193    Java Problem
The method matchRange(char, char) is undefined for the type SwiftBugParser  SwiftBugParser.java /SwiftMessage/antlr-generated   line 195    Java Problem
Syntax error on token "(", Expression expected after this token SwiftBugParser.java /SwiftMessage/antlr-generated   line 201    Java Problem
Syntax error on token "(", Expression expected after this token SwiftBugParser.java /SwiftMessage/antlr-generated   line 208    Java Problem

The declaration is public class SwiftBugParser extends Parser, so I am not sure why matchRange is not understood.

I can see that there is no boolean expression being evaluated for the third and fourth errors. Perhaps the ? (match 0 or 1 instances) is a problem.

parrt commented 12 years ago

Yep, range .. makes no sense in the parser. I just don't have an error message for it. Ter

sharwell commented 11 years ago

Added issue antlr/antlr3#59 to address the error message.