[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: the comment filter example

> Etienne's thesis has an example in the lexer part that shows how to make a
> subclass of the lexer that overwrites filter().
> One small remark: the signature of filter() has changed since then: it
> throws exceptions.

Hmmm... The thesis the official document, as can be found in McGill
University's theses library.  As such, I cannot change it and still call
it a thesis.  

I'll have to change this document and its title (thus, create a new
document which is not called "thesis"), if I want to change it to keep
it in synch with SableCC.  When enough changes will be required, I'll
probably do so.  For now, it is too much trouble for minor things that
will test users ability to adapt their code;-)

> Question:
> setText in all the generated tokens throws RuntimeExceptions. So the example
> that does comment.setText() wouldn't even work anymore. What's the
> alternative if I want to change token text in filter() ?

This has already come up.


  hello = 'hello';


  hello = 'h' 'ello';  // equivalent, but setText works...

This is because "fixed text" tokens are treated specially.  As soon as a
token is defined by a regular expression that is not a single string,
setText() works.

> thanks,

You're welcome.

Etienne M. Gagnon, M.Sc.                     e-mail: egagnon@j-meg.com
Author of SableCC:                 http://www.sable.mcgill.ca/sablecc/