[antlr-interest] Re: Taking control of the input stream
Ric Klaren
klaren at cs.utwente.nl
Thu Sep 19 02:09:09 PDT 2002
On Wed, Sep 18, 2002 at 08:51:32PM -0000, weitzman_d wrote:
> LITERAL : "{" num:NUMBER "}" CRLF
> {
> int length = Integer.parseInt(num.getText());
> InputBuffer buf = getInputBuffer();
> buf.mark();
> buf.fill(length);
> for (int i = 0; i < length; i++) {
> buf.consume();
> }
> String value = buf.getLAChars().substring(0, length);
> buf.commit();
> System.out.println("Matched literal [" + value + "]");
> setText(value);
> }
> ;
I guess that will work. You btw can ommit the mark and commit. Another
option is maybe using a closure rule with a predicate to break out of it (I
think you need a prerelease antlr to do this)
Cheers,
Ric
--
-----+++++*****************************************************+++++++++-------
---- Ric Klaren ----- klaren at cs.utwente.nl ----- +31 53 4893722 ----
-----+++++*****************************************************+++++++++-------
"Evil will always triumph, because Good is dumb." --- Spaceballs
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list