|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.antlr.runtime.BaseRecognizer org.antlr.runtime.tree.TreeParser org.cesta.parsers.java.AbstractTreeParser
public abstract class AbstractTreeParser
Abstract tree parser with some usefull utility functions. Can be used as a parent for all tree parsers, that provide rewrite and original source code should be commented out. Additionally, it support automatic passing of parameters to templates created via getTemplateInstance().
Nested Class Summary | |
---|---|
protected static class |
AbstractTreeParser.runtimeRewriteParams_scope
Scope used to track execution of rewrites. |
Field Summary | |
---|---|
protected java.util.Map<java.lang.String,java.lang.Object> |
parameters
Map of parameters, which were added to transformation |
protected int |
rewriteID
Counts initialized rewrites |
protected java.util.Stack |
runtimeRewriteParams_stack
Stack of runtime parameters (each item represents one rewrite) |
protected org.antlr.runtime.TokenRewriteStream |
tokens
Current token stream, on which is transformation working |
Fields inherited from class org.antlr.runtime.tree.TreeParser |
---|
DOWN, input, UP |
Fields inherited from class org.antlr.runtime.BaseRecognizer |
---|
DEFAULT_TOKEN_CHANNEL, HIDDEN, INITIAL_FOLLOW_STACK_SIZE, MEMO_RULE_FAILED, MEMO_RULE_UNKNOWN, NEXT_TOKEN_RULE_NAME, state |
Constructor Summary | |
---|---|
AbstractTreeParser(org.antlr.runtime.tree.TreeNodeStream input)
Public constructor |
|
AbstractTreeParser(org.antlr.runtime.tree.TreeNodeStream input,
org.antlr.runtime.RecognizerSharedState state)
Public constructor |
Method Summary | |
---|---|
void |
cleanupRewrite()
Should be called after every rewrite. |
void |
clearParams()
Clears all parameters |
AbstractTreeParser.runtimeRewriteParams_scope |
getCurrentRewriteParams()
Current runtime params from top of the stack |
int |
getCurrentStartIndex()
Returns current token start index for tree, on which we are currently working. |
int |
getCurrentStopIndex()
Returns current token stop index for tree, on which we are currently working. |
java.lang.String |
getDefaultTemplateGroup()
Returns default template group, which will be used to load templates. |
java.util.logging.Logger |
getLogger()
Returns default logger, which should be used in parsers. |
int |
getMaxRewriteID()
Returns highest rewrite ID used so far |
protected java.lang.String |
getOriginalCode(org.antlr.runtime.tree.CommonTree tree)
Will return original code of the tree (before any rewrite) |
java.lang.Object |
getParam(java.lang.String name)
Returns previously set parameter with given name |
java.lang.Object |
getParam(java.lang.String name,
java.lang.Object defaultValue)
Returns previously set parameter with given name |
java.lang.Boolean |
getParamB(java.lang.String name)
Helper method for getting Boolean parameters |
java.lang.Boolean |
getParamB(java.lang.String name,
java.lang.Boolean defaultValue)
Helper method for getting Boolean parameters |
java.util.Map<java.lang.String,java.lang.Object> |
getParams()
Returns all set parameters for this transformation |
java.lang.String |
getParamS(java.lang.String name)
Helper method for getting String parameters |
java.lang.String |
getParamS(java.lang.String name,
java.lang.String defaultValue)
Helper method for getting String parameters |
int |
getRewritesCount()
Returns overall number of performed rewrites so far. |
protected int |
getStartIndex(org.antlr.runtime.tree.Tree tree)
Returns current start index (index of first token) of provided tree. |
protected int |
getStopIndex(org.antlr.runtime.tree.Tree tree)
Returns current stop index (index of last token) of provided tree. |
abstract org.antlr.stringtemplate.StringTemplateGroup |
getTemplateLib()
Current template library. |
org.antlr.runtime.TokenRewriteStream |
getTokenRewriteStream()
|
void |
initRewrite()
Initializes rewrite (automatically sets runtime params like ID and current tree). |
void |
performRewrite(java.util.Map ruleParams)
Performs unified rewrite, calls rule from initTransformation and passes default parameters (id of rewrite, originalCode) + requested parameters from provided map. |
protected java.lang.String |
removeIndent(org.antlr.runtime.Token token)
Will remove indent string before token |
void |
setDefaultTemplateLib()
Sets default template library - loads default template group and defines map "params", which will hold all current parameters. |
void |
setParam(java.lang.String name,
java.lang.Object value)
Sets one single parameter |
void |
setParams(java.util.Map<java.lang.String,java.lang.Object> params)
Sets list of parameters. |
abstract void |
setTemplateLib(org.antlr.stringtemplate.StringTemplateGroup templateLib)
Sets current template library. |
Methods inherited from class org.antlr.runtime.tree.TreeParser |
---|
getCurrentInputSymbol, getErrorHeader, getErrorMessage, getMissingSymbol, getSourceName, getTreeNodeStream, matchAny, recoverFromMismatchedToken, reset, setTreeNodeStream, traceIn, traceOut |
Methods inherited from class org.antlr.runtime.BaseRecognizer |
---|
alreadyParsedRule, beginResync, combineFollows, computeContextSensitiveRuleFOLLOW, computeErrorRecoverySet, consumeUntil, consumeUntil, displayRecognitionError, emitErrorMessage, endResync, failed, getBacktrackingLevel, getGrammarFileName, getNumberOfSyntaxErrors, getRuleInvocationStack, getRuleInvocationStack, getRuleMemoization, getRuleMemoizationCacheSize, getTokenErrorDisplay, getTokenNames, match, memoize, mismatchIsMissingToken, mismatchIsUnwantedToken, pushFollow, recover, recoverFromMismatchedSet, reportError, setBacktrackingLevel, toStrings, traceIn, traceOut |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.util.Map<java.lang.String,java.lang.Object> parameters
protected int rewriteID
protected org.antlr.runtime.TokenRewriteStream tokens
protected java.util.Stack runtimeRewriteParams_stack
Constructor Detail |
---|
public AbstractTreeParser(org.antlr.runtime.tree.TreeNodeStream input)
input
- public AbstractTreeParser(org.antlr.runtime.tree.TreeNodeStream input, org.antlr.runtime.RecognizerSharedState state)
input
- state
- Method Detail |
---|
public java.util.Map<java.lang.String,java.lang.Object> getParams()
public java.lang.Object getParam(java.lang.String name)
name
- name of parameter
public java.lang.Object getParam(java.lang.String name, java.lang.Object defaultValue)
name
- name of parameterdefaultValue
- default value
public java.lang.String getParamS(java.lang.String name)
public java.lang.String getParamS(java.lang.String name, java.lang.String defaultValue)
public java.lang.Boolean getParamB(java.lang.String name)
public java.lang.Boolean getParamB(java.lang.String name, java.lang.Boolean defaultValue)
public void setParams(java.util.Map<java.lang.String,java.lang.Object> params)
params
- list of parameterspublic void setParam(java.lang.String name, java.lang.Object value)
name
- name of parametervalue
- value of parameter, any Objectpublic void clearParams()
public int getMaxRewriteID()
public int getRewritesCount()
public java.util.logging.Logger getLogger()
public org.antlr.runtime.TokenRewriteStream getTokenRewriteStream() throws antlr.RecognitionException
antlr.RecognitionException
public AbstractTreeParser.runtimeRewriteParams_scope getCurrentRewriteParams()
public void initRewrite()
public void cleanupRewrite()
public int getCurrentStartIndex()
public int getCurrentStopIndex()
public void performRewrite(java.util.Map ruleParams)
Special parameter "enabled" set to false will disable the rewrite.
ruleParams
- map of parameters that should be passed directly to templateprotected java.lang.String getOriginalCode(org.antlr.runtime.tree.CommonTree tree)
protected int getStartIndex(org.antlr.runtime.tree.Tree tree)
tree
- tree
protected int getStopIndex(org.antlr.runtime.tree.Tree tree)
tree
- tree
protected java.lang.String removeIndent(org.antlr.runtime.Token token)
public abstract org.antlr.stringtemplate.StringTemplateGroup getTemplateLib()
public abstract void setTemplateLib(org.antlr.stringtemplate.StringTemplateGroup templateLib)
templateLib
- Template library to be usedpublic java.lang.String getDefaultTemplateGroup()
public void setDefaultTemplateLib() throws TransformationException
TransformationException
- in case default template group couldn't be loaded
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |