|
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.BaseAST | +--antlr.CommonAST | +--antlraux.util.LexInfoAST
This subclass of CommonAST
implements
LexInfo
, so it can return the
filename, line and column of its information. It
also provides additional navigation methods.
In order to use LexInfoAST in your parser or tree parser, you'll have to
use the method Parser.setASTNodeClass(String)
:
import antlraux.util.LexInfoAST; ... MyLexer lexer = new MyLexer(new FileInputStream(filename)); lexer.setFilename(filename); MyParser parser = new MyParser(lexer); parser.setFilename(filename); parser.setASTNodeClass("antlraux.util.LexInfoAST");In order to obtain the right filenames, you'll also have to specify a Token type different from the default (
CommonToken
),
for example LexInfoToken
(you should read that link if you're
using antlr ver. 2.7.2 at least; there's a little problem with filenames).
When working with ASTs that are not of the default type
(CommonAST
) in tree parsers, it is usually usefull
using the ASTLabelType option:
header { import antlraux.util.LexInfoAST; } class MyTreeParser extends TreeParser; options{ ASTLabelType = antlraux.util.LexInfoAST; }This makes a lot of authomatic castings to LexInfoAST, saving a lot of writing to the programmer. But it only works for grammars that parse trees of type LexInfoAST (or subclasses of it).
LexInfoToken
,
LexInfo
,
Serialized FormField Summary | |
protected static boolean |
verboseStringConversion
|
Fields inherited from class antlr.BaseAST |
down, right |
Fields inherited from interface antlraux.util.LexInfo |
DEFAULT_COLUMN, DEFAULT_FILENAME, DEFAULT_LINE |
Constructor Summary | |
LexInfoAST()
Default constructor. |
|
LexInfoAST(antlr.collections.AST ast)
Calls initialize(antlr.collections.AST) |
|
LexInfoAST(int type,
java.lang.String text)
Calls CommonAST.initialize(int,String) |
|
LexInfoAST(antlr.Token tok)
Calls initialize(antlr.Token) |
Method Summary | |
void |
addChildLeft(antlr.collections.AST newFirstChild)
Similar to AST.addChild(AST), but this one inserts the child at the beginning of the children list, instead of at the end. |
void |
addChildLeftWithSiblings(antlr.collections.AST newFirstChild)
Similar to addChildLeft(AST) ,
but conservating newFirstChild's sibling list.
|
void |
addSibling(antlr.collections.AST newLastSibling)
Adds a sibling to the sibling list, without erasing |
void |
copyLexInfo(LexInfo from)
Copies filename, line and column from "from" |
int |
getColumn()
Get the file name for this node |
java.lang.String |
getFilename()
Get the file name for this node |
antlr.collections.AST |
getLastChild()
Returns the last child of the children, or null if there are no children |
antlr.collections.AST |
getLastSibling()
It returns the last sibling of the sibling list. |
java.lang.String |
getLexInfoString()
Returns a string representing the lexInfo of the AST (filename:line:column). |
int |
getLine()
Get the file name for this node |
antlr.collections.AST |
getPrevChild(antlr.collections.AST child)
It returns the sibling that precedes "child" in the children list. |
void |
initialize(antlr.collections.AST ast)
Firstly this method calls super.initialize(ast) Then it checks if ast is instanceof LexInfoAST . |
void |
initialize(antlr.Token t)
Firstly this method calls super.initialize(token) Then it copies filename, line and column information from the Token. |
boolean |
replaceChild(antlr.collections.AST prevAST,
antlr.collections.AST newAST)
Replaces a child node (prevAST) with another one (newAST) This method erases any siblings of newAST and adds the current tree's children as siblings |
boolean |
replaceChildWithSiblings(antlr.collections.AST prevAST,
antlr.collections.AST newAST)
Similar to replaceChild(AST,AST) ,
but conservating newAST's sibling list (current tree's
children are added after that list). |
void |
setColumn(int column)
Set the file name for this node |
void |
setFilename(java.lang.String fn)
Set the file name for this node. |
void |
setLine(int line)
Set the file name for this node |
static void |
setVerboseStringConversion(boolean b)
When set to true, adds information to toString() |
protected static void |
tabulate(int t,
java.lang.StringBuffer sb)
|
java.lang.String |
toString()
Returns a String representing the information in the root of the node. |
java.lang.String |
toStringList()
|
java.lang.String |
toStringList(int tabLevel)
Print out a child-sibling tree in LISP notation |
java.lang.String |
toStringTree()
|
Methods inherited from class antlr.CommonAST |
getText, getType, initialize, setText, setType |
Methods inherited from class antlr.BaseAST |
addChild, decode, encode, equals, equalsList, equalsListPartial, equalsTree, equalsTreePartial, findAll, findAllPartial, getFirstChild, getNextSibling, getNumberOfChildren, removeChildren, setFirstChild, setNextSibling, setVerboseStringConversion, xmlSerialize, xmlSerializeNode, xmlSerializeRootClose, xmlSerializeRootOpen |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected static boolean verboseStringConversion
Constructor Detail |
public LexInfoAST()
public LexInfoAST(antlr.Token tok)
initialize(antlr.Token)
public LexInfoAST(int type, java.lang.String text)
CommonAST.initialize(int,String)
public LexInfoAST(antlr.collections.AST ast)
initialize(antlr.collections.AST)
Method Detail |
public void initialize(antlr.collections.AST ast)
LexInfoAST
. If yes, it copies its
lex info using
copyLexInfo(antlraux.util.LexInfo)
initialize
in interface antlr.collections.AST
initialize
in class antlr.CommonAST
ast
- The AST whose information is to be copiedpublic void initialize(antlr.Token t)
initialize
in interface antlr.collections.AST
initialize
in class antlr.CommonAST
t
- The token whose information is to be copiedpublic java.lang.String getFilename()
getFilename
in interface LexInfo
public int getColumn()
getColumn
in interface LexInfo
public int getLine()
getLine
in interface LexInfo
public void setFilename(java.lang.String fn)
setFilename
in interface LexInfo
public void setColumn(int column)
setColumn
in interface LexInfo
public void setLine(int line)
setLine
in interface LexInfo
public void copyLexInfo(LexInfo from)
copyLexInfo
in interface LexInfo
from
- The lex info providerpublic java.lang.String getLexInfoString()
getLexInfoString
in interface LexInfo
public antlr.collections.AST getPrevChild(antlr.collections.AST child)
child
- the child whose left sibling is being
searched
public antlr.collections.AST getLastChild()
public antlr.collections.AST getLastSibling()
public void addSibling(antlr.collections.AST newLastSibling)
newLastSibling
- The new last sibling. If it is
null then the method does nothingpublic void addChildLeft(antlr.collections.AST newFirstChild)
newFirstChild
- the new first childpublic void addChildLeftWithSiblings(antlr.collections.AST newFirstChild)
addChildLeft(AST)
,
but conservating newFirstChild's sibling list.
If null==newFirstChild, then the children
list will be erased.
newFirstChild
- the new first childpublic boolean replaceChild(antlr.collections.AST prevAST, antlr.collections.AST newAST)
prevAST
- the AST that is going to be substitutednewAST
- the new AST
public boolean replaceChildWithSiblings(antlr.collections.AST prevAST, antlr.collections.AST newAST)
replaceChild(AST,AST)
,
but conservating newAST's sibling list (current tree's
children are added after that list).
prevAST
- the AST that is going to be substitutednewAST
- the new AST
public static void setVerboseStringConversion(boolean b)
toString()
public java.lang.String toString()
setVerboseStringConversion(boolean)
has been set to true, it adds the lex information of
the AST (using getLexInfoString()
)
toString
in interface antlr.collections.AST
toString
in class antlr.BaseAST
protected static void tabulate(int t, java.lang.StringBuffer sb)
public java.lang.String toStringList()
toStringList
in interface antlr.collections.AST
toStringList
in class antlr.BaseAST
public java.lang.String toStringList(int tabLevel)
public java.lang.String toStringTree()
toStringTree
in interface antlr.collections.AST
toStringTree
in class antlr.BaseAST
|
antlraux package v0.2.1 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |