[antlr-interest] Cannot find lexer rule

Jim Idle jimi at temporal-wave.com
Thu Sep 27 03:37:30 PDT 2012


The issue is that this is in fact a far from trivial problem from a
grammar point of view. You will really need to hand code this. Trigger
the lexer with '[' then embed code to parse the HTML, work out how
many characters that is, input.consume() that many characters, look
for the ] you could use an island grammar to parse the HTML, but that
is non trivial and there are already some good free HTML parsers out
there.

You might find that you don't actually need an ANTLR grammar at all.

Jim

On Sep 27, 2012, at 15:14, "wolfgang hämmer" <wolfgang at haemmer.net> wrote:

> 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.
>
> 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