[antlr-interest] Cannot find lexer rule

wolfgang hämmer wolfgang at haemmer.net
Thu Sep 27 00:14:04 PDT 2012


Dear all,

I have got an irritating problem with a very simple grammar. May be I can't
see the forest because I am standing at a tree ;-)

Here my grammar: (it is an excerpt)

grammar SRC_REP_FILE;

options {
    language=Java;
    backtrack=true;
    memoize=true;
    output=AST;
}

start_rule
    :
    'PUT' SQUARED_BRACKED_EXPRESSION
    ;

SQUARED_BRACKED_EXPRESSION
    :
    '[' ~('[')* ']'
    ;

WS    :
    (' '| '\r' | '\t' | '\n')   {$channel=HIDDEN;}
    ;


Here my input:

      PUT [<TR>]


And here the results:

line 3:0 mismatched character '<EOF>' expecting ']'
line 3:0 missing SQUARED_BRACKED_EXPRESSION at '<EOF>'


What I am trying to do is to parse an expression like


      PUT
        [
<HTML>
  <HEAD>
    <TITLE>[ATS_TEST_REP.PAGE_TITLE(ATS_TEST_REP.C_REP_TYPE_TEST_CASE,
FALSE, TOP.PAR_COMPO_ID)]</TITLE>
    [ATS_TEST_REP.CSS]
  </HEAD>
  <BODY>
    <H1>[ATS_TEST_REP.PAGE_TITLE(ATS_TEST_REP.C_REP_TYPE_TEST_CASE, FALSE,
TOP.PAR_COMPO_ID)]</H1>
    <TABLE>
      <TR>
        <TH CLASS="MODULE">MODULE</TH>
        <TH CLASS="COMPO">COMPO</TH>
        <TH CLASS="TC">TEST CASE</TH>
        <TH CLASS="CNT">TEST CASE/STEP #</TH>
      </TR>
        ]


in a code where the '[' and ']' occur in other places. I would like to hide
the lexer rule

SQUARED_BRACKED_EXPRESSION
    :
    '[' ~('[')* ']'
    ;

from the rest of the grammer and call it explicitely from a parser rule like

put_statement
    :
    PUT SQUARED_BRACKED_EXPRESSION
    ;

The problem is that I cannot use a 'fragment' as 'fragment' lexer rules can
only be called from other lexer rules.


More information about the antlr-interest mailing list