Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
element
    : ...
    ;
catch [RecognitionException re] {
    int ttype = input.get(input.range()).getType();
    // look for anything that really belongs at the start of the rule minus the initial ID
    if ( ttype==COLON || ttype==RETURNS || ttype==CATCH || ttype==FINALLY || ttype==AT ) { 
        RecognitionException missingSemi =
            new v4ParserException("unterminated rule (missing ';') detected at '"+ 
                                  input.LT(1).getText()+" "+input.LT(2).getText()+"'", input);
        reportError(missingSemi);
        throw new ResyncToEndOfRuleBlock();
    }   
    reportError(re);
    recover(input,re);
    retval.tree = (GrammarAST)adaptor.errorNode(input, retval.start, input.LT(-1), re);
}

Upon the above input, ANTLR v4 gives the tasty error message:

Code Block

error(17): A.g:2:4: unterminated rule (missing ';') detected at 'b catch' while looking for rule element

Notes...

"grammar A;;" says

...