Java 类org.antlr.runtime.tree.TreeAdaptor 实例源码

项目:JavaGraph    文件:ParseTree.java   
/** 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);
    }
}
项目:legstar-cob2xsd    文件:ASTReferenceGraph.java   
/**
 * 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;

}
项目:legstar-core2    文件:ASTReferenceGraph.java   
/**
 * 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;

}
项目:tesora-dve-pub    文件:Utils.java   
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());
}
项目:tesora-dve-pub    文件:Utils.java   
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;
}
项目:JavaGraph    文件:ParseTree.java   
/** 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);
    }
}
项目:goworks    文件:CompiledModelParser.java   
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);
}
项目:tesora-dve-pub    文件:Utils.java   
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());
    }
}
项目:tesora-dve-pub    文件:Utils.java   
public Object buildKeywordEscapeIdentifier(Parser parser, TreeAdaptor adaptor, Object tree) {
    CommonTree ct = (CommonTree)tree;
    String txt = ct.getText();
    if (txt == null) {
        CommonToken leftToken = (CommonToken) parser.getTokenStream().get(ct.getTokenStartIndex());
        CommonToken rightToken = (CommonToken) parser.getTokenStream().get(ct.getTokenStopIndex());
        txt = leftToken.getInputStream().substring(leftToken.getStartIndex(), rightToken.getStopIndex());
    }

    return adaptor.create(TokenTypes.Regular_Identifier, ct.getToken(), /*ct.getText()*/txt);
}
项目:tesora-dve-pub    文件:Utils.java   
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);
}
项目:tesora-dve-pub    文件:Utils.java   
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)); 
}
项目:tesora-dve-pub    文件:Utils.java   
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);
}
项目:templates4j    文件:gUnitBase.java   
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);
}
项目:antlrworks2    文件:CompiledModelParser.java   
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);
}
项目:rview    文件:QueryParser.java   
public void setTreeAdaptor(TreeAdaptor adaptor) {
    this.adaptor = adaptor;
}
项目:rview    文件:QueryParser.java   
public TreeAdaptor getTreeAdaptor() {
    return adaptor;
}
项目:codebuff    文件:JTreeASTModel.java   
public JTreeASTModel(TreeAdaptor adaptor, Object root) {
    this.adaptor = adaptor;
    this.root = root;
}
项目:codebuff    文件:JTreeASTModel.java   
public JTreeASTModel(TreeAdaptor adaptor, Object root) {
    this.adaptor = adaptor;
    this.root = root;
}
项目:codebuff    文件:JTreeASTModel.java   
public JTreeASTModel(TreeAdaptor adaptor, Object root) {
    this.adaptor = adaptor;
    this.root = root;
}
项目:codebuff    文件:JTreeASTModel.java   
public JTreeASTModel(TreeAdaptor adaptor, Object root) {
    this.adaptor = adaptor;
    this.root = root;
}
项目:codebuff    文件:JTreeASTModel.java   
public JTreeASTModel(TreeAdaptor adaptor, Object root) {
    this.adaptor = adaptor;
    this.root = root;
}
项目:codebuff    文件:JTreeASTModel.java   
public JTreeASTModel(TreeAdaptor adaptor, Object root) {
    this.adaptor = adaptor;
    this.root = root;
}
项目:codebuff    文件:JTreeASTModel.java   
public JTreeASTModel(TreeAdaptor adaptor, Object root) {
    this.adaptor = adaptor;
    this.root = root;
}
项目:codebuff    文件:JTreeASTModel.java   
public JTreeASTModel(TreeAdaptor adaptor, Object root) {
    this.adaptor = adaptor;
    this.root = root;
}
项目:codebuff    文件:JTreeASTModel.java   
public JTreeASTModel(TreeAdaptor adaptor, Object root) {
    this.adaptor = adaptor;
    this.root = root;
}
项目:codebuff    文件:JTreeASTModel.java   
public JTreeASTModel(TreeAdaptor adaptor, Object root) {
    this.adaptor = adaptor;
    this.root = root;
}
项目:codebuff    文件:JTreeASTModel.java   
public JTreeASTModel(TreeAdaptor adaptor, Object root) {
    this.adaptor = adaptor;
    this.root = root;
}
项目:codebuff    文件:JTreeASTModel.java   
public JTreeASTModel(TreeAdaptor adaptor, Object root) {
    this.adaptor = adaptor;
    this.root = root;
}
项目:codebuff    文件:JTreeASTModel.java   
public JTreeASTModel(TreeAdaptor adaptor, Object root) {
    this.adaptor = adaptor;
    this.root = root;
}
项目:codebuff    文件:JTreeASTModel.java   
public JTreeASTModel(TreeAdaptor adaptor, Object root) {
    this.adaptor = adaptor;
    this.root = root;
}
项目:codebuff    文件:JTreeASTModel.java   
public JTreeASTModel(TreeAdaptor adaptor, Object root) {
    this.adaptor = adaptor;
    this.root = root;
}
项目:codebuff    文件:JTreeASTModel.java   
public JTreeASTModel(TreeAdaptor adaptor, Object root) {
    this.adaptor = adaptor;
    this.root = root;
}
项目:codebuff    文件:JTreeASTModel.java   
public JTreeASTModel(TreeAdaptor adaptor, Object root) {
    this.adaptor = adaptor;
    this.root = root;
}
项目:cuba    文件:JPAParser.java   
public void setTreeAdaptor(TreeAdaptor adaptor) {
    this.adaptor = adaptor;
}
项目:cuba    文件:JPAParser.java   
public TreeAdaptor getTreeAdaptor() {
    return adaptor;
}
项目:FinanceAnalytics    文件:ExprParser.java   
public void setTreeAdaptor(TreeAdaptor adaptor) {
    this.adaptor = adaptor;
}
项目:FinanceAnalytics    文件:ExprParser.java   
public TreeAdaptor getTreeAdaptor() {
    return adaptor;
}
项目:binnavi    文件:MemoryExpressionParser.java   
public TreeAdaptor getTreeAdaptor() {
  return adaptor;
}
项目:binnavi    文件:MemoryExpressionParser.java   
public void setTreeAdaptor(final TreeAdaptor adaptor) {
  this.adaptor = adaptor;
}
项目:binnavi    文件:ConditionParser.java   
public TreeAdaptor getTreeAdaptor() {
  return adaptor;
}