本文整理汇总了Java中org.antlr.runtime.tree.TreeAdaptor类的典型用法代码示例。如果您正苦于以下问题:Java TreeAdaptor类的具体用法?Java TreeAdaptor怎么用?Java TreeAdaptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TreeAdaptor类属于org.antlr.runtime.tree包,在下文中一共展示了TreeAdaptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createParser
import org.antlr.runtime.tree.TreeAdaptor; //导入依赖的package包/类
/** Creates a parser for a given term, generating trees of this kind. */
public <P extends Parser> P createParser(Class<P> parserType, I info, String term) {
try {
// find the lexer type
String parserName = parserType.getName();
String lexerName = parserName.substring(0, parserName.indexOf("Parser"))
.concat("Lexer");
@SuppressWarnings("unchecked") Class<? extends Lexer> lexerType =
(Class<? extends Lexer>) Class.forName(lexerName);
Lexer lexer = createLexer(lexerType, info, term);
// instantiate the parser
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
Constructor<P> parserConstructor = parserType.getConstructor(TokenStream.class);
P result = parserConstructor.newInstance(tokenStream);
Method adaptorSetter = parserType.getMethod("setTreeAdaptor", TreeAdaptor.class);
adaptorSetter.invoke(result, new ParseTreeAdaptor<>(this, info, tokenStream));
callInitialise(result, info);
return result;
} catch (Exception e) {
throw toRuntime(e);
}
}
示例2: addAttribute
import org.antlr.runtime.tree.TreeAdaptor; //导入依赖的package包/类
/**
* Add a new attribute to a parent node.
* @param adaptor the tree helper
* @param parent parent node
* @param tokenType the new node token type
* @param tokenText the new node name
* @param value the new node value
* @return a new node that was just added to parent
*/
private Object addAttribute(
final TreeAdaptor adaptor,
final Object parent,
final int tokenType,
final String tokenText, final String value) {
Object node = adaptor.create(tokenType, tokenText);
if (value != null) {
String[] values = value.split("\\s\\|\\s");
for (String avalue : values) {
Object nodeValue = adaptor.create(CobolStructureParser.LITERAL, avalue);
adaptor.addChild(node, nodeValue);
}
}
adaptor.addChild(parent, node);
return node;
}
示例3: buildJDBCUrl
import org.antlr.runtime.tree.TreeAdaptor; //导入依赖的package包/类
public Object buildJDBCUrl(TreeAdaptor adaptor, String dbType, String hostname, String port, String dbname) {
StringBuilder buf = new StringBuilder();
buf.append("'");
buf.append("jdbc:");
if (dbType == null)
throw new ParserException(Pass.FIRST, "Malformed jdbc url: missing dbtype");
buf.append(dbType).append("://");
if (hostname == null)
throw new ParserException(Pass.FIRST, "Malformed jdbc url: missing host");
buf.append(hostname);
if (port != null)
buf.append(":").append(port);
if (dbname != null)
buf.append("/").append(dbname);
buf.append("'");
return adaptor.create(TokenTypes.Character_String_Literal, buf.toString());
}
示例4: buildBooleanExpr
import org.antlr.runtime.tree.TreeAdaptor; //导入依赖的package包/类
public ExpressionNode buildBooleanExpr(TreeAdaptor ta, Token ln, ExpressionNode predicate, Token is, Token not, List<ExpressionNode> is_parameters) {
ExpressionNode out = predicate;
if (is != null) {
BaseTreeAdaptor bta = (BaseTreeAdaptor) ta;
List<ExpressionNode> params = new ArrayList<ExpressionNode>();
params.add(predicate);
Token ftok = is;
if (not != null) {
int newType = findNottableConversion(ftok);
ftok = bta.createToken(newType,ftok.getText());
}
params.addAll(is_parameters);
out = new FunctionCall(new FunctionName(ftok.getText(), ftok.getType(), true),params);
}
if (ln != null) {
out = new FunctionCall(new FunctionName(ln.getText(), ln.getType(), true), out);
}
return out;
}
示例5: createTreeParser
import org.antlr.runtime.tree.TreeAdaptor; //导入依赖的package包/类
/** Creates a tree parser for a given tree of this kind. */
public <P extends TreeParser> P createTreeParser(Class<P> parserType, I info) {
try {
// instantiate the parser
ParseTreeAdaptor<T,I> adaptor = new ParseTreeAdaptor<>(this);
Constructor<P> parserConstructor = parserType.getConstructor(TreeNodeStream.class);
P result = parserConstructor.newInstance(adaptor.createTreeNodeStream(this));
Method adaptorSetter = parserType.getMethod("setTreeAdaptor", TreeAdaptor.class);
adaptorSetter.invoke(result, adaptor);
callInitialise(result, info);
return result;
} catch (Exception e) {
throw toRuntime(e);
}
}
示例6: buildAstForGroupTemplates
import org.antlr.runtime.tree.TreeAdaptor; //导入依赖的package包/类
private TemplateGroupRuleReturnScope buildAstForGroupTemplates(TemplateGroupWrapper group) {
TreeAdaptor adaptor = new CommonTreeAdaptor();
Object tree = adaptor.nil();
for (CompiledST template : group.getCompiledTemplates()) {
adaptor.addChild(tree, template.ast);
}
return new TemplateGroupRuleReturnScope(group, (CommonTree)tree);
}
示例7: buildKeywordEscapeIdentifier
import org.antlr.runtime.tree.TreeAdaptor; //导入依赖的package包/类
public Object buildKeywordEscapeIdentifier(TreeAdaptor adaptor, Object tree) {
if (tree instanceof CommonToken) {
Token tok = (Token) tree;
return adaptor.create(TokenTypes.Regular_Identifier, tok, tok.getText());
} else {
CommonTree ct = (CommonTree)tree;
return adaptor.create(TokenTypes.Regular_Identifier, ct.getToken(), ct.getText());
}
}
示例8: createPrecedenceTree
import org.antlr.runtime.tree.TreeAdaptor; //导入依赖的package包/类
private static ExpressionNode createPrecedenceTree(TranslatorUtils me, TreeAdaptor adaptor, List<ExpressionNode> expressions, List<Token> operators, int startIndex, int stopIndex) {
if (stopIndex == startIndex) {
ExpressionNode out = expressions.get(startIndex);
if (out instanceof ExpressionNodeList)
throw new IllegalStateException("unhandled fake expression");
return out;
}
int pivot = findPivot(operators, startIndex, stopIndex - 1);
Token opToken = operators.get(pivot);
FunctionName fn = new FunctionName(opToken.getText(),opToken.getType(),true);
if (specialOperators.contains(opToken.getType())) {
if (pivot+1 == stopIndex) {
// unpack the rhs
ExpressionNode en = expressions.get(stopIndex);
ArrayList<ExpressionNode> allParams = new ArrayList<ExpressionNode>();
allParams.add(createPrecedenceTree(me,adaptor,expressions,operators,startIndex,pivot));
if (en instanceof ExpressionNodeList) {
ExpressionNodeList enl = (ExpressionNodeList) en;
allParams.addAll(enl.args);
} else {
allParams.add(en);
}
return me.buildFunctionCall(fn, allParams, null, null);
}
}
return me.buildFunctionCall(fn, Arrays.asList(new ExpressionNode[] {
createPrecedenceTree(me,adaptor,expressions,operators,startIndex,pivot),
createPrecedenceTree(me,adaptor,expressions,operators,pivot+1,stopIndex) }), null, null);
}
示例9: collectSpecialNottable
import org.antlr.runtime.tree.TreeAdaptor; //导入依赖的package包/类
public void collectSpecialNottable(TreeAdaptor adaptor, Object mainOp, List<ExpressionNode> params,
Object notOp, List<ExpressionNode> exprs, List<Token> opNodes) {
BaseTreeAdaptor bta = (BaseTreeAdaptor) adaptor;
CommonTree opNode = (CommonTree) mainOp;
CommonTree notNode = (CommonTree) notOp;
CommonToken opToken = null;
if (notNode != null) {
int newType = findNottableConversion(opNode);
opToken = (CommonToken) bta.createToken(newType, opNode.getText());
} else {
opToken = (CommonToken) opNode.getToken();
}
opNodes.add(opToken);
exprs.add(new ExpressionNodeList(params));
}
示例10: buildNottableFunction
import org.antlr.runtime.tree.TreeAdaptor; //导入依赖的package包/类
public FunctionName buildNottableFunction(TreeAdaptor adaptor, Token in) {
BaseTreeAdaptor bta = (BaseTreeAdaptor) adaptor;
int nt = findNottableConversion(in);
Token newTok = bta.createToken(nt,in.getText());
TranslatorUtils me = (TranslatorUtils) this;
return me.buildFunctionName(newTok, false);
}
示例11: execParser
import org.antlr.runtime.tree.TreeAdaptor; //导入依赖的package包/类
public Object execParser(
String ruleName,
String input,
int scriptLine)
throws Exception
{
ANTLRStringStream is = new ANTLRStringStream(input);
Class<? extends TokenSource> lexerClass = Class.forName(lexerClassName).asSubclass(TokenSource.class);
Constructor<? extends TokenSource> lexConstructor = lexerClass.getConstructor(CharStream.class);
TokenSource lexer = lexConstructor.newInstance(is);
is.setLine(scriptLine);
CommonTokenStream tokens = new CommonTokenStream(lexer);
Class<? extends Parser> parserClass = Class.forName(parserClassName).asSubclass(Parser.class);
Constructor<? extends Parser> parConstructor = parserClass.getConstructor(TokenStream.class);
Parser parser = parConstructor.newInstance(tokens);
// set up customized tree adaptor if necessary
if ( adaptorClassName!=null ) {
Method m = parserClass.getMethod("setTreeAdaptor", TreeAdaptor.class);
Class<? extends TreeAdaptor> adaptorClass = Class.forName(adaptorClassName).asSubclass(TreeAdaptor.class);
m.invoke(parser, adaptorClass.newInstance());
}
Method ruleMethod = parserClass.getMethod(ruleName);
// INVOKE RULE
return ruleMethod.invoke(parser);
}
示例12: setTreeAdaptor
import org.antlr.runtime.tree.TreeAdaptor; //导入依赖的package包/类
public void setTreeAdaptor(TreeAdaptor adaptor) {
this.adaptor = adaptor;
}
示例13: getTreeAdaptor
import org.antlr.runtime.tree.TreeAdaptor; //导入依赖的package包/类
public TreeAdaptor getTreeAdaptor() {
return adaptor;
}
示例14: JTreeASTModel
import org.antlr.runtime.tree.TreeAdaptor; //导入依赖的package包/类
public JTreeASTModel(TreeAdaptor adaptor, Object root) {
this.adaptor = adaptor;
this.root = root;
}
示例15: getTreeAdaptor
import org.antlr.runtime.tree.TreeAdaptor; //导入依赖的package包/类
public TreeAdaptor getTreeAdaptor() {
return adaptor;
}