• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java TreeAdaptor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.antlr.runtime.tree.TreeAdaptor的典型用法代码示例。如果您正苦于以下问题:Java TreeAdaptor类的具体用法?Java TreeAdaptor怎么用?Java TreeAdaptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TreeAdaptor类属于org.antlr.runtime.tree包,在下文中一共展示了TreeAdaptor类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
    }
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:23,代码来源:ParseTree.java


示例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;
    
}
 
开发者ID:legsem,项目名称:legstar-cob2xsd,代码行数:27,代码来源:ASTReferenceGraph.java


示例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());
}
 
开发者ID:Tesora,项目名称:tesora-dve-pub,代码行数:18,代码来源:Utils.java


示例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;
}
 
开发者ID:Tesora,项目名称:tesora-dve-pub,代码行数:20,代码来源:Utils.java


示例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);
    }
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:16,代码来源:ParseTree.java


示例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);
}
 
开发者ID:tunnelvisionlabs,项目名称:goworks,代码行数:10,代码来源:CompiledModelParser.java


示例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());
	}
}
 
开发者ID:Tesora,项目名称:tesora-dve-pub,代码行数:10,代码来源:Utils.java


示例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);
}
 
开发者ID:Tesora,项目名称:tesora-dve-pub,代码行数:34,代码来源:Utils.java


示例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)); 
}
 
开发者ID:Tesora,项目名称:tesora-dve-pub,代码行数:16,代码来源:Utils.java


示例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);
}
 
开发者ID:Tesora,项目名称:tesora-dve-pub,代码行数:8,代码来源:Utils.java


示例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);
}
 
开发者ID:danishdynamite,项目名称:templates4j,代码行数:31,代码来源:gUnitBase.java


示例12: setTreeAdaptor

import org.antlr.runtime.tree.TreeAdaptor; //导入依赖的package包/类
public void setTreeAdaptor(TreeAdaptor adaptor) {
    this.adaptor = adaptor;
}
 
开发者ID:jruesga,项目名称:rview,代码行数:4,代码来源:QueryParser.java


示例13: getTreeAdaptor

import org.antlr.runtime.tree.TreeAdaptor; //导入依赖的package包/类
public TreeAdaptor getTreeAdaptor() {
    return adaptor;
}
 
开发者ID:jruesga,项目名称:rview,代码行数:4,代码来源:QueryParser.java


示例14: JTreeASTModel

import org.antlr.runtime.tree.TreeAdaptor; //导入依赖的package包/类
public JTreeASTModel(TreeAdaptor adaptor, Object root) {
    this.adaptor = adaptor;
    this.root = root;
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:5,代码来源:JTreeASTModel.java


示例15: getTreeAdaptor

import org.antlr.runtime.tree.TreeAdaptor; //导入依赖的package包/类
public TreeAdaptor getTreeAdaptor() {
  return adaptor;
}
 
开发者ID:google,项目名称:binnavi,代码行数:4,代码来源:MemoryExpressionParser.java


示例16: setTreeAdaptor

import org.antlr.runtime.tree.TreeAdaptor; //导入依赖的package包/类
public void setTreeAdaptor(final TreeAdaptor adaptor) {
  this.adaptor = adaptor;
}
 
开发者ID:google,项目名称:binnavi,代码行数:4,代码来源:MemoryExpressionParser.java



注:本文中的org.antlr.runtime.tree.TreeAdaptor类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java OFGroupMod类代码示例发布时间:2022-05-21
下一篇:
Java ScreenUtils类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap