|
antlraux package v0.2.1 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--antlr.Token | +--antlr.CommonToken | +--antlraux.util.LexInfoToken
This subclass of CommonToken
implements
LexInfo
, really allowing the use of
a filename (which is ommited in CommonToken
)
To make your lexer use this class of tokens, you'll have to use
the method setTokenObjectClass:
import antlraux.util.LexInfoToken; ... MyLexer lexer = new MyLexer(new FileInputStream(filename)); lexer.setFilename(filename); lexer.setTokenObjectClass("antlraux.util.LexInfoToken");Warning! By default, the antlr v2.7.2 implementation of lexer does NOT add filename information to the tokens it creates. Tokens are created in method
CharScanner.makeToken(int)
of class antlr.CharScanner,
which is the superClass of every Lexer we can create.
So in order to set the filename in our lexer we'll have to
override it in the grammar definition file of the lexer:
public class MyLexer extends Lexer; options {...} tokens {...} // Code section { public Token makeToken(int type) { // Obtain the token with no filename, and then add it Token result = super.makeToken(type); result.setFilename(getFilename()); return result; } }Once you include this on your lexer LexInfoToken will work perfectly (Keep in mind that this modification might not be necessary in future versions of antlr).
LexInfoAST
,
LexInfo
Field Summary |
Fields inherited from class antlr.CommonToken |
col, line, text |
Fields inherited from class antlr.Token |
badToken, EOF_TYPE, INVALID_TYPE, MIN_USER_TYPE, NULL_TREE_LOOKAHEAD, SKIP |
Fields inherited from interface antlraux.util.LexInfo |
DEFAULT_COLUMN, DEFAULT_FILENAME, DEFAULT_LINE |
Constructor Summary | |
LexInfoToken()
Default constructor. |
|
LexInfoToken(int type,
java.lang.String text)
Only initializes type and text. |
|
LexInfoToken(antlr.Token t)
Copy constructor |
Method Summary | |
void |
copyLexInfo(LexInfo from)
Sets the Lex information |
java.lang.String |
getFilename()
Get the file name for this token |
java.lang.String |
getLexInfoString()
Returns a String in the stype "filename:line:column". |
void |
setFilename(java.lang.String fn)
Set the file name for this token. |
Methods inherited from class antlr.CommonToken |
getColumn, getLine, getText, setColumn, setLine, setText, toString |
Methods inherited from class antlr.Token |
getType, setType |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface antlraux.util.LexInfo |
getColumn, getLine, setColumn, setLine |
Constructor Detail |
public LexInfoToken()
Token
in order to being
able to create them in the CharScanner
public LexInfoToken(int type, java.lang.String text)
public LexInfoToken(antlr.Token t)
Method Detail |
public java.lang.String getFilename()
getFilename
in interface LexInfo
getFilename
in class antlr.Token
public void setFilename(java.lang.String fn)
setFilename
in interface LexInfo
setFilename
in class antlr.Token
public void copyLexInfo(LexInfo from)
copyLexInfo
in interface LexInfo
public java.lang.String getLexInfoString()
FileLineFormatter
, so problems like
filename==null are taken into account.
getLexInfoString
in interface LexInfo
|
antlraux package v0.2.1 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |