[antlr-interest] Fragments and setText appear to not work at all - not even with code from the book

Harald Mueller harald_m_mueller at gmx.de
Wed Nov 21 02:29:57 PST 2007


> Anyway, what you refer to is not a 
> bug in the sense that it was a deliberate design decision for the sake 
> of performance. [...] In other words, "settext" that 
> you do in a fragment rule is irrelevant.

And, anyway, the following also does not work (it replaces the main method and the complete grammar in my original posting):

------------------
  public static void main(String[] args) throws Exception {
    run("{ a { b c }}");
  }
}

a : m=CODE { System.out.println("m:" + m.getText()); }
  ;

CODE
    : '{' ( x=CODE | ~('{'|'}') )* '}'
        {
            setText(getText().substring(1, getText().length()));
            //C#: $text = $text.Substring(1, getText().length()-1);
        }
    ;

------------------

No fragments here, only a simple recursive rule. The output is, as before:

{ a { b c }} ==> a { b c }

So setText doesn't seem to work also for a non-fragment lexer rule called inside another lexer rule ... It appears to me that all this should be checked and output by the ANTLR tool (which probably knows about all these rules), shouldn't it? (ok - I know: it doesn't look into the code blocks, so it allows you to do anything there ... it's at your own risk ... but that means at least documentation, documentation, documentation ...).

Regards
Harald

-- 
GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail


More information about the antlr-interest mailing list