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


Java ParseTreeWalker.walk方法代码示例

本文整理汇总了Java中org.antlr.v4.runtime.tree.ParseTreeWalker.walk方法的典型用法代码示例。如果您正苦于以下问题:Java ParseTreeWalker.walk方法的具体用法?Java ParseTreeWalker.walk怎么用?Java ParseTreeWalker.walk使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.antlr.v4.runtime.tree.ParseTreeWalker的用法示例。


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

示例1: parse

import org.antlr.v4.runtime.tree.ParseTreeWalker; //导入方法依赖的package包/类
private void parse(
    SQLParserListener sqlParserListener,
    ErrorListener errorListener,
    ParserRuleContext entryPoint) {
  ParseTreeWalker walker = new ParseTreeWalker();

  walker.walk(sqlParserListener, entryPoint);

  // if the parser call raised any exceptions then lets throw
  errorListener
      .getException()
      .ifPresent(
          ex -> {
            throw ex;
          });
}
 
开发者ID:glytching,项目名称:dragoman,代码行数:17,代码来源:BaseParser.java

示例2: callSql

import org.antlr.v4.runtime.tree.ParseTreeWalker; //导入方法依赖的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

示例3: getScript

import org.antlr.v4.runtime.tree.ParseTreeWalker; //导入方法依赖的package包/类
public Script getScript() {
    Script script =  new Script(struct.getGMLName() + "_" + name, "");

    List<String> args = new ArrayList<>();
    if (context.idList() != null) {
        for (IdContext id : context.idList().id()) {
            args.add(id.getText());
            script.addParameter(id.getText(), "");
        }
    }

    ParseTreeWalker walker = new ParseTreeWalker();
    walker.walk(new StaticAnalyzer(), context.block());

    //walker.walk(new ScriptWriter(script), context.block());

    return script;
}
 
开发者ID:GMWolf,项目名称:gmstruct,代码行数:19,代码来源:Function.java

示例4: walkTree

import org.antlr.v4.runtime.tree.ParseTreeWalker; //导入方法依赖的package包/类
public void walkTree() {
    try {
        init();
        QueryLexer lexer = new QueryLexer(new ANTLRInputStream(new StringReader(queryStr)));
        CommonTokenStream token = new CommonTokenStream(lexer);
        QueryParser parser = new QueryParser(token);
        parser.setBuildParseTree(true);
        QueryParser.ScriptContext tree = parser.script(); // parse
        ParseTreeWalker parseTreeWalker = new ParseTreeWalker();
        parseTreeWalker.walk( this, tree);
        //check for key# if size = 1
        checkPredicateStack();
    } catch (Exception ex) {
        logger.error(ex.getMessage());
        throw new QueryException( ex.getMessage(), ex );
    }
}
 
开发者ID:viant,项目名称:CacheStore,代码行数:18,代码来源:QueryListenerImpl.java

示例5: parse

import org.antlr.v4.runtime.tree.ParseTreeWalker; //导入方法依赖的package包/类
/**
 * Parses a source file using ANTLR4, and walks over the parse tree to
 * interpret this source file as a Java object.
 * 
 * @param c
 *            input character stream
 * @param path
 *            location of the file
 * @return an interpreted source file, or null in case of an error.
 */
@Nullable
private ReoFile<T> parse(CharStream c, String path) {
	ReoLexer lexer = new ReoLexer(c);
	CommonTokenStream tokens = new CommonTokenStream(lexer);
	ReoParser parser = new ReoParser(tokens);

	ErrorListener errListener = new ErrorListener(m);
	parser.removeErrorListeners();
	parser.addErrorListener(errListener);
	ParseTree tree = parser.file();
	if (errListener.hasError)
		return null;
	ParseTreeWalker walker = new ParseTreeWalker();
	listener.setFileName(path);
	walker.walk(listener, tree);
	return listener.getMain();
}
 
开发者ID:ReoLanguage,项目名称:Reo,代码行数:28,代码来源:Interpreter.java

示例6: compileFiles

import org.antlr.v4.runtime.tree.ParseTreeWalker; //导入方法依赖的package包/类
private void compileFiles(List<RawFile> files, OOPSourceCodeModel srcModel, List<String> projectFileTypes) {
    for (RawFile file : files) {
        try {
            CharStream charStream = new ANTLRInputStream(file.content());
            GolangLexer lexer = new GolangLexer(charStream);
            TokenStream tokens = new CommonTokenStream(lexer);
            GolangParser parser = new GolangParser(tokens);
            SourceFileContext sourceFileContext = parser.sourceFile();
            parser.setErrorHandler(new BailErrorStrategy());
            parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
            ParseTreeWalker walker = new ParseTreeWalker();
            GolangBaseListener listener = new GoLangTreeListener(srcModel, projectFileTypes, file);
            walker.walk(listener, sourceFileContext);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:Zir0-93,项目名称:clarpse,代码行数:19,代码来源:ClarpseGoCompiler.java

示例7: parse

import org.antlr.v4.runtime.tree.ParseTreeWalker; //导入方法依赖的package包/类
/**
 * Parse the given Thrift {@code text}, using the given {@code location}
 * to anchor parsed elements withing the file.
 * @param location the {@link Location} of the data being parsed.
 * @param text the text to be parsed.
 * @param reporter an {@link ErrorReporter} to collect warnings.
 * @return a representation of the parsed Thrift data.
 */
public static ThriftFileElement parse(Location location, String text, ErrorReporter reporter) {
    ANTLRInputStream charStream = new ANTLRInputStream(text);
    AntlrThriftLexer lexer = new AntlrThriftLexer(charStream);
    CommonTokenStream tokenStream = new CommonTokenStream(lexer);
    AntlrThriftParser antlrParser = new AntlrThriftParser(tokenStream);

    ThriftListener thriftListener = new ThriftListener(tokenStream, reporter, location);

    ParseTreeWalker walker = new ParseTreeWalker();
    walker.walk(thriftListener, antlrParser.document());

    if (reporter.hasError()) {
        String errorReports = Joiner.on('\n').join(reporter.formattedReports());
        String message = String.format(Locale.US, "Syntax errors in %s:\n%s", location, errorReports);
        throw new IllegalStateException(message);
    }

    return thriftListener.buildFileElement();
}
 
开发者ID:Microsoft,项目名称:thrifty,代码行数:28,代码来源:ThriftParser.java

示例8: main

import org.antlr.v4.runtime.tree.ParseTreeWalker; //导入方法依赖的package包/类
/**
 * @param args
 * @throws IOException 
 * @throws SQLException 
 */
public static void main(String[] args) throws IOException, SQLException {
	
       TPKBLexer lexer = new TPKBLexer(new ANTLRFileStream("test.kb"));
       TPKBParser parser = new TPKBParser(new CommonTokenStream(lexer));
       
       TPKBClassListener listener = new TPKBClassListener();
       
       ParseTree tree = parser.tpkb();
       ParseTreeWalker walker = new ParseTreeWalker();
       walker.walk(listener, tree);
       
       MySQLEngine engine = new MySQLEngine();
       engine.processTSubRaw();
       engine.processTIsRaw();
       
       double Z = engine.computeZ();
       System.out.println("Z = "+Z);
       
       Z = engine.computeZWithEvidence();
       System.out.println("Z(E) = "+Z);     
}
 
开发者ID:mniepert,项目名称:TPKB,代码行数:27,代码来源:TPKB.java

示例9: main

import org.antlr.v4.runtime.tree.ParseTreeWalker; //导入方法依赖的package包/类
public static void main(String[] args) {
	String code =
		"int x;\n" +
		"A b;\n";
	ANTLRInputStream input = new ANTLRInputStream(code);
	LangLexer lexer = new LangLexer(input);
	CommonTokenStream tokens = new CommonTokenStream(lexer);
	LangParser parser = new LangParser(tokens);
	ParseTree tree = parser.file(); // start up

	System.out.println(tree.toStringTree(parser));

	ParseTreeWalker walker = new ParseTreeWalker();
	Gen listener = new Gen();
	walker.walk(listener, tree);

	ST output = listener.file.getTemplate();
	System.out.println(output.render());
}
 
开发者ID:parrt,项目名称:cs652,代码行数:20,代码来源:Trans.java

示例10: main

import org.antlr.v4.runtime.tree.ParseTreeWalker; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
	ANTLRInputStream input = new ANTLRFileStream("colleges.csv");
	CSVLexer lexer = new CSVLexer(input);
	CommonTokenStream tokens = new CommonTokenStream(lexer);
	CSVParser parser = new CSVParser(tokens);
	ParseTree tree = parser.file();
	System.out.println(tree.toStringTree(parser));

	ParseTreeWalker walker = new ParseTreeWalker();
	CSVLoader loader = new CSVLoader();
	walker.walk(loader, tree);

	for (List<String> row : loader.data) {
		System.out.println(row);
	}
}
 
开发者ID:parrt,项目名称:cs652,代码行数:17,代码来源:Load.java

示例11: processInput

import org.antlr.v4.runtime.tree.ParseTreeWalker; //导入方法依赖的package包/类
private static void processInput(String line, RuntimeContext runtimeCtx) {
    ANTLRInputStream input = new ANTLRInputStream(line);
    EQLLexer lexer = new EQLLexer(input);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    EQLParser parser = new EQLParser(tokens);

    // combine these two into one
    parser.addErrorListener(new EQLErrorListener());

    ParseTreeWalker walker = new ParseTreeWalker();
    EQLWalker esq = new EQLWalker(runtimeCtx);

    try {
        EQLParser.StmtsContext stmts = parser.stmts();
        walker.walk(esq, stmts);
    } catch (Throwable t) {
        // catch parse errors. ANTLR will display a message for me.
        System.out.println(t.getMessage());
    }

}
 
开发者ID:metadave,项目名称:eql,代码行数:22,代码来源:EQLConsole.java

示例12: extract

import org.antlr.v4.runtime.tree.ParseTreeWalker; //导入方法依赖的package包/类
/**
 * Returns a map, containing clazzName and count of methods, for the given
 * file.
 * 
 * Based upon the <a href=
 * "https://theantlrguy.atlassian.net/wiki/display/ANTLR4/Parse+Tree+Listeners">ANTLR-Tutorial</a>
 * 
 * @param importFile
 *            The file to import.
 * @return A map containing the clazzName and count of methods, extracted
 *         from {@code importFile}.
 * @throws Exception
 *             IO- and ANTLR-Exceptions, not catched for simplicity.
 */
public Map<String, Integer> extract(File importFile) throws Exception {

	/** Prepare input for ANTLR. */
	InputStream is = new FileInputStream(importFile.getAbsolutePath());
	ANTLRInputStream input = new ANTLRInputStream(is);
	JavaLexer lexer = new JavaLexer(input);
	CommonTokenStream tokens = new CommonTokenStream(lexer);
	JavaParser parser = new JavaParser(tokens);

	/** Parse. */
	ParseTree tree = parser.compilationUnit();

	/** Create standard walker. */
	ParseTreeWalker walker = new ParseTreeWalker();

	/** Initiate walk of tree with listener. */
	Listener listener = new Listener(parser);
	walker.walk(listener, tree);

	/** Save the results. */
	Map<String, Integer> result = new HashMap<>();
	result.put(listener.getClazzName(), listener.getMethodCount());

	return result;
}
 
开发者ID:meyer-sven,项目名称:antlr4-java-example,代码行数:40,代码来源:Extractor.java

示例13: graph

import org.antlr.v4.runtime.tree.ParseTreeWalker; //导入方法依赖的package包/类
@Override
public void graph() {
    // first pass to extract defs
    super.graph();

    // second pass to extract refs
    firstPass = false;
    for (Map.Entry<File, ParseTree> entry : trees.entrySet()) {
        processingPath.push(PathUtil.relativizeCwd(entry.getKey().toPath()));
        LOGGER.info("Extracting refs from {}", getCurrentFile());
        try {
            ParseTreeWalker walker = new ParseTreeWalker();
            walker.walk(new SwiftParseTreeListener(this), entry.getValue());
        } catch (Exception e) {
            LOGGER.error("Failed to process {} - unexpected error", getCurrentFile(), e);
        } finally {
            processingPath.pop();
        }
    }
}
 
开发者ID:alexsaveliev,项目名称:srclib-basic,代码行数:21,代码来源:LanguageImpl.java

示例14: build

import org.antlr.v4.runtime.tree.ParseTreeWalker; //导入方法依赖的package包/类
/**
 * Fire off the full parse of the input and return the resulting DOM object.
 * Any errors encountered during the parse will be logged in the Log class.
 * <p>
 * @see Log
 * <p>
 * @return the DOM built by parsing the string or file.
 */
@Override
public DOM build() {
  ParserErrorListener parserListener = new ParserErrorListener(dom);
  ISELexer lexer = new ISELexer(ais);
  lexer.removeErrorListeners();
  lexer.addErrorListener(parserListener);

  CommonTokenStream tokenStream = new CommonTokenStream(lexer);

  ISEParser parser = new ISEParser(tokenStream);
  parser.removeErrorListeners();
  parser.addErrorListener(parserListener);

  ParseTreeWalker ptw = new ParseTreeWalker();
  tokens = parser.getTokenStream();
  ParseTree pt = parser.document();
  ptw.walk(this, pt);
  dom.index();
  return dom;
}
 
开发者ID:ubermichael,项目名称:isetools,代码行数:29,代码来源:DOMBuilder.java

示例15: expand

import org.antlr.v4.runtime.tree.ParseTreeWalker; //导入方法依赖的package包/类
public static List<String> expand(String s) {
    BraceExpansionLexer lexer = new BraceExpansionLexer(
            new ANTLRInputStream(s)
    );

    // Get a list of matched tokens
    CommonTokenStream tokens = new CommonTokenStream(lexer);

    // Pass the tokens to the parser
    BraceExpansionParser parser = new BraceExpansionParser(tokens);

    // Specify our entry point
    BraceExpansionParser.RootContext context = parser.root();

    // Walk it and attach our listener
    ParseTreeWalker walker = new ParseTreeWalker();
    Value<List<String>> value = new Value<List<String>>();
    ParseTreeListener listener = new AntlrBraceListener(value);
    walker.walk(listener, context);
    List<String> strings = value.getValue();
    return strings;
}
 
开发者ID:AndersDJohnson,项目名称:brace-expansion-java,代码行数:23,代码来源:BraceExpansion.java


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