当前位置: 首页>>代码示例>>Java>>正文


Java ParseTree类代码示例

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


ParseTree类属于org.antlr.v4.runtime.tree包,在下文中一共展示了ParseTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: eval

import org.antlr.v4.runtime.tree.ParseTree; //导入依赖的package包/类
@Override
public Sequence eval(final Sequence[] args, final Sequence contextSequence) throws XPathException {
    final ANTLRInputStream is = new ANTLRInputStream(args[0].getStringValue());

    final CorpusQLLexer lexer = new CorpusQLLexer(is);
    final CommonTokenStream tokens = new CommonTokenStream(lexer);
    final CorpusQLParser parser = new CorpusQLParser(tokens);

    final ParseTree tree = parser.query();

    final MemTreeBuilder builder = new MemTreeBuilder();
    builder.startDocument();

    final CorpusQLXMLVisitor xmlVisitor = new CorpusQLXMLVisitor(builder);
    xmlVisitor.visit(tree);

    builder.endDocument();

    return builder.getDocument();
}
 
开发者ID:BCDH,项目名称:cql-module,代码行数:21,代码来源:CQLParserFunction.java

示例2: enterPattern_matcher

import org.antlr.v4.runtime.tree.ParseTree; //导入依赖的package包/类
@Override
public void enterPattern_matcher(SQLParser.Pattern_matcherContext ctx) {
  super.enterPattern_matcher(ctx);
  for (int i = 0; i < ctx.getChildCount(); i++) {
    ParseTree child = ctx.getChild(i);
    if (child instanceof TerminalNodeImpl) {
      if (isNot(child.getText())) {
        currentPredicate.negate();
      }
      break;
    }
  }

  if (currentPredicate.isNegated()) {
    currentPredicate.setOperator("not like");
  } else {
    currentPredicate.setOperator("like");
  }
  skipNextTerminal = true;
}
 
开发者ID:glytching,项目名称:dragoman,代码行数:21,代码来源:AbstractWhereClauseListener.java

示例3: callSql

import org.antlr.v4.runtime.tree.ParseTree; //导入依赖的package包/类
public PlanNode callSql(String sqlstring, ArrayList list) throws FileNotFoundException, IOException {
	
	for (int i=0; i< list.size() ; i++) {
		sqlstring = sqlstring.replaceFirst("\\?", (String) list.get(i));
	}
	ANTLRInputStream input = new ANTLRInputStream( new   ByteArrayInputStream(sqlstring.getBytes()));
	
	PLSQLLexer lexer = new PLSQLLexer(input);
	CommonTokenStream tokens = new CommonTokenStream(lexer);
	PLSQLParser parser = new PLSQLParser(tokens);
	parser.setBuildParseTree(true);
	ParseTree tree = parser.sql_statement();
       ParseTreeWalker walker  = new ParseTreeWalker();
       SQLModel model = new SQLModel();
       walker.walk(new MyListener(model), tree);
       
	
       
       return model.current;
}
 
开发者ID:sabotage,项目名称:SQLParser,代码行数:21,代码来源:SQLParser.java

示例4: GraphParser

import org.antlr.v4.runtime.tree.ParseTree; //导入依赖的package包/类
public GraphParser(InputStream is) throws GraphParserException {
	DOTLexer lexer = null;
	DOTParser parser = null;
	try {
		lexer = new DOTLexer(new ANTLRInputStream(is));
		lexer.addErrorListener(new ErrorListener());
		
		parser = new DOTParser(new CommonTokenStream(lexer));
		parser.setErrorHandler(new ExceptionErrorStrategy());
		parser.addErrorListener(new ErrorListener());
		
		ParseTree tree = parser.graph();
		ParseTreeWalker.DEFAULT.walk(new NodeListener(), tree);
		ParseTreeWalker.DEFAULT.walk(new EdgeListener(), tree);
	}
	catch (Throwable t) {
		if (mErrMsg != null) throw new GraphParserException(mErrMsg, t);
		if (lexer != null) {
			mErrMsg = "at line " + lexer.getLine() + ":" + lexer.getCharPositionInLine();
			throw new GraphParserException(mErrMsg, t);
		}
		throw new GraphParserException(t);
	}
	
	if (mErrMsg != null) throw new GraphParserException(mErrMsg);
}
 
开发者ID:paypal,项目名称:digraph-parser,代码行数:27,代码来源:GraphParser.java

示例5: getFunctionTypeEndingWithVariadic

import org.antlr.v4.runtime.tree.ParseTree; //导入依赖的package包/类
public Expression getFunctionTypeEndingWithVariadic(String varName, ParseTree node) {
    String[] params = varName.split("\\$");
    if(params.length < 2) return null;

    for(int i = params.length - 1; i >= 1; i--) {

        String param = params[i];
        for(int j = i + 1; j < params.length; j++) if(!params[j].equals(param)) return null;

        String subVarName = "";
        for(int j = 0; j < i; j++) subVarName += (j > 0 ? "$" : "") + params[j];
        subVarName += "$_Array";
        CacheObject cache = findCache(subVarName, node);
        /*if(cache != null && cache.type instanceof FunctionType) {
            List<AbstractType> parameterTypes = ((FunctionType)cache.type).parameterTypes;
            if(!parameterTypes.get(parameterTypes.size() - 1).resulting(null).swiftType().equals(param.split("_")[1])) continue;
            return new Expression(subVarName, cache.type);
        }*/
    }
    return null;
}
 
开发者ID:marcelganczak,项目名称:ts-swift-transpiler,代码行数:22,代码来源:EntityCache.java

示例6: visitApiFacets

import org.antlr.v4.runtime.tree.ParseTree; //导入依赖的package包/类
@Override
public Object visitApiFacets(RAMLParser.ApiFacetsContext ctx) {
    // TODO move creation of security schemes to 1 pass
    final RAMLParser.SecuritySchemesFacetContext securitySchemesFacet = ctx.securitySchemesFacet();
    if (securitySchemesFacet != null) {
        visitSecuritySchemesFacet(securitySchemesFacet);
    }

    for (int i = 0; i < ctx.getChildCount(); i++) {
        final ParseTree child = ctx.getChild(i);
        if (child != securitySchemesFacet) {
            child.accept(this);
        }
    }

    return scope.eObject();
}
 
开发者ID:vrapio,项目名称:rest-modeling-framework,代码行数:18,代码来源:ApiConstructor.java

示例7: cloneExprContext

import org.antlr.v4.runtime.tree.ParseTree; //导入依赖的package包/类
/**
 * Cloning expression to create new same expression.
 */
public static ExprContext cloneExprContext(final ExprContext expr) {

  final ExprContext clone = createContextType(expr);

  clone.copyFrom(expr);

  for (final ParseTree child : expr.children) {
    if (child instanceof TerminalNode) {
      clone.addChild(new TerminalNodeImpl(((TerminalNode) child).getSymbol()));
    } else if (child instanceof ExprContext) {
      final ExprContext cloneChild = cloneExprContext((ExprContext) child);
      clone.addChild(cloneChild);
      setLeftRight(clone, cloneChild);
    } else if (child instanceof Token) {
      clone.addChild(new CommonToken((Token) child));
    }
  }
  return clone;
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:23,代码来源:Utilities.java

示例8: checkValidYangFileForNoSyntaxError

import org.antlr.v4.runtime.tree.ParseTree; //导入依赖的package包/类
/**
 * Checks that no exception is generated for YANG file with valid syntax.
 */
@Test
public void checkValidYangFileForNoSyntaxError() throws IOException {

    ANTLRInputStream input = new ANTLRFileStream("src/test/resources/YangFileWithoutSyntaxError.yang");

    // Create a lexer that feeds off of input char stream.
    GeneratedYangLexer lexer = new GeneratedYangLexer(input);
    // Create a buffer of tokens pulled from the lexer.
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    // Create a parser that feeds off the tokens buffer.
    GeneratedYangParser parser = new GeneratedYangParser(tokens);
    // Remove console error listener.
    parser.removeErrorListeners();
    // Create instance of customized error listener.
    ParseTreeErrorListener parseTreeErrorListener = new ParseTreeErrorListener();
    // Add customized error listener to catch errors during parsing.
    parser.addErrorListener(parseTreeErrorListener);
    // Begin parsing YANG file and generate parse tree.
    ParseTree tree = parser.yangfile();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:24,代码来源:ParseTreeErrorListenerTest.java

示例9: checkInvalidYangFileForSyntaxError

import org.antlr.v4.runtime.tree.ParseTree; //导入依赖的package包/类
/**
 * Checks that exception is generated for YANG file with invalid syntax.
 */
@Test
public void checkInvalidYangFileForSyntaxError() throws IOException {

    // Get the exception occurred during parsing.
    thrown.expect(ParserException.class);
    thrown.expect(CustomExceptionMatcher.errorLocation(3, 0));
    thrown.expectMessage("no viable alternative at input 'yang-version 1\\nnamespace'");

    ANTLRInputStream input = new ANTLRFileStream("src/test/resources/YangFileWithSyntaxError.yang");

    // Create a lexer that feeds off of input char stream.
    GeneratedYangLexer lexer = new GeneratedYangLexer(input);
    // Create a buffer of tokens pulled from the lexer.
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    // Create a parser that feeds off the tokens buffer.
    GeneratedYangParser parser = new GeneratedYangParser(tokens);
    // Remove console error listener.
    parser.removeErrorListeners();
    // Create instance of customized error listener.
    ParseTreeErrorListener parseTreeErrorListener = new ParseTreeErrorListener();
    // Add customized error listener to catch errors during parsing.
    parser.addErrorListener(parseTreeErrorListener);
    // Begin parsing YANG file and generate parse tree.
    ParseTree tree = parser.yangfile();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:29,代码来源:ParseTreeErrorListenerTest.java

示例10: AntlrBridge

import org.antlr.v4.runtime.tree.ParseTree; //导入依赖的package包/类
public AntlrBridge(String input){
//		String inputFile = null;
//		if ( input.length()>0 ) inputFile = input;
//		InputStream is = input;
//		if ( inputFile!=null ) is = new FileInputStream(inputFile);
		ANTLRInputStream antlrInput = new ANTLRInputStream(input);
		SequenceAnalyzerLexer lexer = new SequenceAnalyzerLexer(antlrInput);
		CommonTokenStream tokens = new CommonTokenStream(lexer);
		SequenceAnalyzerParser parser = new SequenceAnalyzerParser(tokens);
		ParseTree tree = parser.prog(); // parse

		CommandObjectVisitor coVisitor = new CommandObjectVisitor();
		coVisitor.visit(tree);
		
		Stack<CommandObject> commandObjectStack = coVisitor.commandObjectStack;
		
		commandExecutor.executeStack(commandObjectStack);
	}
 
开发者ID:Streus,项目名称:Project-SADS,代码行数:19,代码来源:AntlrBridge.java

示例11: inform

import org.antlr.v4.runtime.tree.ParseTree; //导入依赖的package包/类
private void inform(String match, String key, String value, ParseTree ctx) {
    Set<MatcherAction> relevantActions = informMatcherActions.get(match.toLowerCase(Locale.ENGLISH));
    if (verbose) {
        if (relevantActions == null) {
            LOG.info("--- Have (0): {}", match);
        } else {
            LOG.info("+++ Have ({}): {}", relevantActions.size(), match);

            int count = 1;
            for (MatcherAction action : relevantActions) {
                LOG.info("+++ -------> ({}): {}", count, action.toString());
                count++;
            }
        }
    }

    if (relevantActions != null) {
        for (MatcherAction matcherAction : relevantActions) {
            matcherAction.inform(key, value, ctx);
        }
    }
}
 
开发者ID:nielsbasjes,项目名称:yauaa,代码行数:23,代码来源:UserAgentAnalyzerDirect.java

示例12: walk

import org.antlr.v4.runtime.tree.ParseTree; //导入依赖的package包/类
@Override
public WalkResult walk(ParseTree tree, String value) {
    String actualValue = getActualValue(tree, value);
    String filteredValue;
    if (tree.getChildCount() == 1 && (
          tree.getChild(0) instanceof SingleVersionContext ||
          tree.getChild(0) instanceof SingleVersionWithCommasContext)) {
        filteredValue = VersionSplitter.getInstance().getSplitRange(actualValue, firstWord, lastWord);
    } else {
        filteredValue = WordSplitter.getInstance().getSplitRange(actualValue, firstWord, lastWord);
    }
    if (filteredValue == null) {
        return null;
    }
    return walkNextStep(tree, filteredValue);
}
 
开发者ID:nielsbasjes,项目名称:yauaa,代码行数:17,代码来源:StepWordRange.java

示例13: getGenerator

import org.antlr.v4.runtime.tree.ParseTree; //导入依赖的package包/类
@SuppressWarnings("unchecked")
static public Generator<ParseTree> getGenerator(ParseTree ctx) throws OrcaException {
    Class<?> klass = ctx.getClass();
    Generator<ParseTree> generator = _generatorByName.get(klass);
    if (generator == null) {
        String key = StringUtils.removeStart(klass.getSimpleName(), "FishParser$");
        key = StringUtils.removeEnd(key, "Context");
        key += "Generator";
        try {
            key = InstructionGenerator.class.getPackage().getName() + "." + key;
            Class<?> generatorClass = Class.forName(key);
            generator = (Generator<ParseTree>)generatorClass.newInstance();
            _generatorByName.put(klass, generator);
        }
        catch (Exception x) {
            throw new OrcaException("instruction geneartor is not found: " + key, x);
        }
    }
    return generator;
}
 
开发者ID:waterguo,项目名称:antsdb,代码行数:21,代码来源:InstructionGenerator.java

示例14: earliestAncestorWithChildStartingAtCharPos

import org.antlr.v4.runtime.tree.ParseTree; //导入依赖的package包/类
/** Walk upwards from node until we find a child of p at t's char position.
 *  Don't see alignment with self, t, or element *after* us.
 *  return null if there is no such ancestor p.
 */
public static Pair<ParserRuleContext,Integer> earliestAncestorWithChildStartingAtCharPos(ParserRuleContext node, Token t, int charpos) {
	ParserRuleContext p = node;
	while ( p!=null ) {
		// check all children of p to see if one of them starts at charpos
		for (int i = 0; i<p.getChildCount(); i++) {
			ParseTree child = p.getChild(i);
			Token start;
			if ( child instanceof ParserRuleContext ) {
				start = ((ParserRuleContext) child).getStart();
			}
			else { // must be token
				start = ((TerminalNode)child).getSymbol();
			}
			// check that we don't see alignment with self or element *after* us
			if ( start.getTokenIndex()<t.getTokenIndex() && start.getCharPositionInLine()==charpos ) {
				return new Pair<>(p,i);
			}
		}
		p = p.getParent();
	}
	return null;
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:27,代码来源:Trainer.java

示例15: visitATTR_OPER_EXPR

import org.antlr.v4.runtime.tree.ParseTree; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * <p>
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public String visitATTR_OPER_EXPR(ScimFilterParser.ATTR_OPER_EXPRContext ctx) {

    logger.info(" ScimGroupFilterVisitor.visitATTR_OPER_EXPR() ");

    ParseTree parent = ctx.getParent();
    while (parent != null) {

        if (parent.getClass().getSimpleName().equalsIgnoreCase(ScimFilterParser.LBRAC_EXPR_RBRACContext.class.getSimpleName())) {

            logger.info("********** PARENT = " + parent.getClass().getSimpleName());

            String attrName = ((ScimFilterParser.LBRAC_EXPR_RBRACContext)parent).ATTRNAME() + "." + ctx.ATTRNAME().getText();
            return attrOperCriteriaResolver(attrName, visit(ctx.operator()), visit(ctx.expression()));

        } else {
            parent = parent.getParent();
        }
    }

    return attrOperCriteriaResolver(ctx.ATTRNAME().getText(), visit(ctx.operator()), visit(ctx.expression()));
}
 
开发者ID:AgarwalNeha1,项目名称:gluu,代码行数:31,代码来源:ScimGroupFilterVisitor.java


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