How is Lexer#unread(Token) meant to be used?

13 views
Skip to first unread message

Kevin Krumwiede

unread,
May 17, 2017, 1:06:51 PM5/17/17
to SableCC
In 3.7, shouldn't Lexer#unread(Token) do something with this.token?  Perhaps I misunderstand how unread(...) was meant to be used.

Current definition:

protected void unread(@SuppressWarnings("hiding") Token token) throws IOException
{
@SuppressWarnings("hiding") String text = token.getText();
int length = text.length();

for(int i = length - 1; i >= 0; i--)
{
this.eof = false;

this.in.unread(text.charAt(i));
}

this.pos = token.getPos() - 1;
this.line = token.getLine() - 1;
}

Etienne Gagnon

unread,
May 17, 2017, 1:14:21 PM5/17/17
to sab...@googlegroups.com

Hi Kevin,

The unread method pushes back the text of the token into the input PushbackReader. Once that is done, there's nothing more to do with the token.

Etienne

Etienne Gagnon, Ph.D.
http://sablecc.org
--
-- You received this message because you are subscribed to the SableCC group. To post to this group, send email to sab...@googlegroups.com. To unsubscribe from this group, send email to sablecc+u...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/sablecc?hl=en
---
You received this message because you are subscribed to the Google Groups "SableCC" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sablecc+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Etienne Gagnon

unread,
May 17, 2017, 1:24:05 PM5/17/17
to SableCC
Kevin,

I should have explained a bit more.

The unread() method is protected; it is meant to be used by a method such as filter(). It is the responsibility of that other method to manage the this.token field.

Etienne


-- 
Etienne Gagnon, Ph.D.
http://sablecc.org
Reply all
Reply to author
Forward
0 new messages