Hi,
For lexical error position problem, I think that the easiest,
backward-compatible solution would be to create an InvalidToken
with a position and a single character of text (the character at
the error location). Note that there must be such a character;
otherwise EOF would have been found. Then, we could attach this
token to the LexerException. What do you think?
As for making generated classes modifiable, I think that this is a
Java-language problem.
One needs "aspects" or, even better, class refinement (often
called "open classes") to be able to add new features to an
existing class, without having to modify the original source file.
I haven't found a clean and simple way to provide this
functionality in Java.
Using class factories does not work, because of static typing. In
other words, even if SableCC allowed users to define their own
subclasses of Node and use a usere provided factory to create AST
nodes, the walker (DepthFIrstAdapter) methods would still use the
generated classes/interface as arguments for [case|in|out]XXX
methods. So, one would need to use a type cast to access any new
feature of the node class. e.g.
public void caseAIfStatement(AIfStatement node) {
MyIfStatement mine = (MyIfStatement) node;
mine.newMethod();
}
Class refinement (open classes) allows to add new methods to
existing types. e.g.
refine class AIfStatement{
public void newMethod() { ... }
}
so that you can, later, cleanly write:
public void caseAIfStatement(AIfStatement node) {
node.newMethod();
}
without any typing error.
Etienne
Etienne Gagnon, Ph.D.
http://sablecc.org