|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.antlr.runtime.tree.BaseTree
org.antlr.runtime.tree.CommonTree
org.antlr.tool.GrammarAST
public class GrammarAST
Grammars are first converted to ASTs using this class and then are converted to NFAs via a tree walker. The reader may notice that I have made a very non-OO decision in this class to track variables for many different kinds of nodes. It wastes space for nodes that don't need the values and OO principles cry out for a new class type for each kind of node in my tree. I am doing this on purpose for a variety of reasons. I don't like using the type system for different node types; it yields too many damn class files which I hate. Perhaps if I put them all in one file. Most importantly though I hate all the type casting that would have to go on. I would have all sorts of extra work to do. Ick. Anyway, I'm doing all this on purpose, not out of ignorance. ;)
| Field Summary | |
|---|---|
protected Map<String,Object> |
blockOptions
If this is a BLOCK node, track options here |
org.stringtemplate.v4.ST |
code
if this is a TOKEN_REF or RULE_REF node, this is the code ST generated for this node. |
String |
enclosingRuleName
|
NFAState |
followingNFAState
Rule ref nodes, token refs, set, and NOT set refs need to track their location in the generated NFA so that local FOLLOW sets can be computed during code gen for automatic error recovery. |
int |
ID
|
DFA |
lookaheadDFA
If this is a decision node, what is the lookahead DFA? |
NFAState |
NFAStartState
What NFA start state was built from this node? |
NFAState |
NFATreeDownState
This is used for TREE_BEGIN nodes to point into the NFA. |
int |
outerAltNum
if this is an ACTION node, this is the outermost enclosing alt num in rule. |
Set<GrammarAST> |
rewriteRefsDeep
|
Set<GrammarAST> |
rewriteRefsShallow
If this is a BLOCK node for a rewrite rule, track referenced elements here. |
protected IntSet |
setValue
If this is a SET node, what are the elements? |
Map<String,Object> |
terminalOptions
|
| Fields inherited from class org.antlr.runtime.tree.CommonTree |
|---|
childIndex, parent, startIndex, stopIndex, token |
| Fields inherited from class org.antlr.runtime.tree.BaseTree |
|---|
children |
| Fields inherited from interface org.antlr.runtime.tree.Tree |
|---|
INVALID_NODE |
| Constructor Summary | |
|---|---|
GrammarAST()
|
|
GrammarAST(int t,
String txt)
|
|
GrammarAST(Token token)
|
|
| Method Summary | |
|---|---|
void |
_findAllType(int ttype,
List<GrammarAST> nodes)
|
static List<Tree> |
descendants(Tree root)
|
static List<Tree> |
descendants(Tree root,
boolean insertDownUpNodes)
|
static GrammarAST |
dup(Tree t)
|
Tree |
dupNode()
|
static GrammarAST |
dupTree(GrammarAST t)
|
static GrammarAST |
dupTreeNoActions(GrammarAST t,
GrammarAST parent)
Duplicate a tree, assuming this is a root node of a tree-- duplicate that node and what's below; ignore siblings of root node. |
boolean |
equals(Object ast)
Make nodes unique based upon Token so we can add them to a Set; if not a GrammarAST, check type. |
List<GrammarAST> |
findAllType(int ttype)
|
GrammarAST |
findFirstType(int ttype)
|
GrammarAST |
getBlockALT(int i)
|
Object |
getBlockOption(String key)
|
Map<String,Object> |
getBlockOptions()
|
int |
getCharPositionInLine()
|
GrammarAST[] |
getChildrenAsArray()
|
GrammarAST |
getLastChild()
|
GrammarAST |
getLastSibling()
|
int |
getLine()
|
DFA |
getLookaheadDFA()
|
GrammarAST |
getNextSibling()
|
NFAState |
getNFAStartState()
|
IntSet |
getSetValue()
|
String |
getText()
|
int |
getType()
|
int |
hashCode()
Make nodes unique based upon Token so we can add them to a Set; if not a GrammarAST, check type. |
boolean |
hasSameTreeStructure(Tree other)
See if tree has exact token types and structure; no text |
void |
initialize(int i,
String s)
|
void |
initialize(Token token)
|
void |
initialize(Tree ast)
|
String |
setBlockOption(Grammar grammar,
String key,
Object value)
Save the option key/value pair and process it; return the key or null if invalid option. |
void |
setBlockOptions(Map<String,Object> blockOptions)
|
void |
setCharPositionInLine(int value)
|
void |
setLine(int line)
|
void |
setLookaheadDFA(DFA lookaheadDFA)
|
void |
setNFAStartState(NFAState nfaStartState)
|
String |
setOption(Map options,
Set legalOptions,
Grammar grammar,
String key,
Object value)
|
void |
setOptions(Grammar grammar,
Map options)
|
void |
setSetValue(IntSet setValue)
|
String |
setTerminalOption(Grammar grammar,
String key,
Object value)
|
void |
setText(String text)
|
void |
setTokenBoundaries(Token startToken,
Token stopToken)
Track start/stop token for subtree root created for a rule. |
void |
setTreeEnclosingRuleNameDeeply(String rname)
|
void |
setType(int type)
|
| Methods inherited from class org.antlr.runtime.tree.CommonTree |
|---|
getChildIndex, getParent, getToken, getTokenStartIndex, getTokenStopIndex, isNil, setChildIndex, setParent, setTokenStartIndex, setTokenStopIndex, setUnknownTokenBoundaries, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public int ID
public String enclosingRuleName
public DFA lookaheadDFA
public NFAState NFAStartState
public NFAState NFATreeDownState
public NFAState followingNFAState
protected IntSet setValue
protected Map<String,Object> blockOptions
public Set<GrammarAST> rewriteRefsShallow
public Set<GrammarAST> rewriteRefsDeep
public Map<String,Object> terminalOptions
public int outerAltNum
public org.stringtemplate.v4.ST code
| Constructor Detail |
|---|
public GrammarAST()
public GrammarAST(int t,
String txt)
public GrammarAST(Token token)
| Method Detail |
|---|
public Map<String,Object> getBlockOptions()
public void setBlockOptions(Map<String,Object> blockOptions)
blockOptions -
public void initialize(int i,
String s)
public void initialize(Tree ast)
public void initialize(Token token)
public DFA getLookaheadDFA()
public void setLookaheadDFA(DFA lookaheadDFA)
public NFAState getNFAStartState()
public void setNFAStartState(NFAState nfaStartState)
public String setBlockOption(Grammar grammar,
String key,
Object value)
public String setTerminalOption(Grammar grammar,
String key,
Object value)
public String setOption(Map options,
Set legalOptions,
Grammar grammar,
String key,
Object value)
public Object getBlockOption(String key)
public void setOptions(Grammar grammar,
Map options)
public String getText()
getText in interface TreegetText in class CommonTreepublic void setType(int type)
public void setText(String text)
public int getType()
getType in interface TreegetType in class CommonTreepublic int getLine()
getLine in interface TreegetLine in class CommonTreepublic int getCharPositionInLine()
getCharPositionInLine in interface TreegetCharPositionInLine in class CommonTreepublic void setLine(int line)
public void setCharPositionInLine(int value)
public IntSet getSetValue()
public void setSetValue(IntSet setValue)
public GrammarAST getLastChild()
public GrammarAST getNextSibling()
public GrammarAST getLastSibling()
public GrammarAST[] getChildrenAsArray()
public static List<Tree> descendants(Tree root)
public static List<Tree> descendants(Tree root,
boolean insertDownUpNodes)
public GrammarAST findFirstType(int ttype)
public List<GrammarAST> findAllType(int ttype)
public void _findAllType(int ttype,
List<GrammarAST> nodes)
public boolean equals(Object ast)
equals in class Objectpublic int hashCode()
hashCode in class Objectpublic boolean hasSameTreeStructure(Tree other)
public static GrammarAST dup(Tree t)
public Tree dupNode()
dupNode in interface TreedupNode in class CommonTree
public static GrammarAST dupTreeNoActions(GrammarAST t,
GrammarAST parent)
public static GrammarAST dupTree(GrammarAST t)
public void setTreeEnclosingRuleNameDeeply(String rname)
public void setTokenBoundaries(Token startToken,
Token stopToken)
public GrammarAST getBlockALT(int i)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||