當前位置: 首頁>>代碼示例>>Java>>正文


Java ParseTreeWalker類代碼示例

本文整理匯總了Java中org.antlr.v4.runtime.tree.ParseTreeWalker的典型用法代碼示例。如果您正苦於以下問題:Java ParseTreeWalker類的具體用法?Java ParseTreeWalker怎麽用?Java ParseTreeWalker使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ParseTreeWalker類屬於org.antlr.v4.runtime.tree包,在下文中一共展示了ParseTreeWalker類的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: GraphParser

import org.antlr.v4.runtime.tree.ParseTreeWalker; //導入依賴的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

示例4: parseSqlStream

import org.antlr.v4.runtime.tree.ParseTreeWalker; //導入依賴的package包/類
public static void parseSqlStream(InputStream inputStream, String charsetName,
        String parsedObjectName, List<AntlrError> errors,IProgressMonitor mon, int monitoringLevel,
        Collection<SQLParserBaseListener> listeners) throws IOException, InterruptedException {
    SQLParser parser = makeBasicParser(SQLParser.class, inputStream, charsetName, parsedObjectName, errors);
    parser.addParseListener(new CustomParseTreeListener(
            monitoringLevel, mon == null ? new NullProgressMonitor() : mon));
    try {
        SqlContext ctx = parser.sql();
        for (SQLParserBaseListener listener : listeners) {
            ParseTreeWalker.DEFAULT.walk(listener, ctx);
        }
    } catch (MonitorCancelledRuntimeException mcre){
        throw new InterruptedException();
    } catch (UnresolvedReferenceException ex) {
        errors.add(CustomSQLParserListener.handleUnresolvedReference(ex));
    }
}
 
開發者ID:pgcodekeeper,項目名稱:pgcodekeeper,代碼行數:18,代碼來源:AntlrParser.java

示例5: 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

示例6: 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

示例7: main

import org.antlr.v4.runtime.tree.ParseTreeWalker; //導入依賴的package包/類
public static void main(String[] args) throws Exception  {
    String[] opts = new String[] {"-query"};
    String[] defaults = new String[] {"replace Order set name = \"test\", campaign.id = 10 , booking.no =20.2 where not record# = 1  ; insert Campaign set cid=20, cname=\"go\""};
    String[] paras = Utils.getOpts(args, opts, defaults);
    //String query = paras[0] ;
    String query = "select id, name, bookings from order where id = 10";
    //CharStream input = new UnbufferedTokenStream(new ANTLRInputStream( new StringReader(query)));
    ObjectQueryLexer lexer = new ObjectQueryLexer( new ANTLRInputStream( new StringReader(query)));
    CommonTokenStream token = new CommonTokenStream( lexer);
    ObjectQueryParser objectQueryParser = new ObjectQueryParser( token);
    objectQueryParser.setBuildParseTree( true);
    ParserRuleContext tree = objectQueryParser.script();
    ParseTreeWalker walker  = new ParseTreeWalker();
    System.out.println(walker.getClass().getName()+ " simple "+ walker.getClass().getSimpleName());
    System.out.println( tree.toString()) ;
}
 
開發者ID:viant,項目名稱:CacheStore,代碼行數:17,代碼來源:TestQueryObject.java

示例8: interpret

import org.antlr.v4.runtime.tree.ParseTreeWalker; //導入依賴的package包/類
public void interpret() {

    ProgramContext parseTree = matrixParser.program();

    ParseTreeWalker.DEFAULT.walk(semanticListener, parseTree);

    List<SemanticError> errorList = semanticListener.getSemanticErrors();

    if (matrixParser.getNumberOfSyntaxErrors() > 0) {
      System.err.println("Aborting...");
    } else if (!errorList.isEmpty()) {
      System.err.println("------------------- ERRORS ---------------------");
      errorList.forEach(System.err::println);
    } else {
      CodeExecutor codeExecutor = new CodeExecutor(semanticListener.getSymbolTable(), parseTree);

      try {
        codeExecutor.execute();
      } catch (RuntimeError e) {
        System.err.println("[" + e.getClass().getSimpleName() + "]: " + e.getMessage());
        System.err.println("Aborting...");
      }
    }

  }
 
開發者ID:daergoth,項目名稱:MatrixC,代碼行數:26,代碼來源:Interpreter.java

示例9: storeOperator

import org.antlr.v4.runtime.tree.ParseTreeWalker; //導入依賴的package包/類
/**
 * Special case: STORE operator.
 * 
 * @param queryArray
 * @param i
 * @param file
 * @return
 * @throws Exception
 */
public static ResultSet storeOperator(String[] queryArray, int i, boolean file) throws Exception {
	ParseTree tree = TriALQLParseQuery.parse(queryArray[i] + ";", file);
	TriALQLClassListener extractor = new TriALQLClassListener();
	ParseTreeWalker.DEFAULT.walk(extractor, tree);

	theLastQuery = true;
	if (QueryStruct.oldTableName.get(i).equals(QueryStruct.newTableName.get(i))) {
		// results = ImpalaDaemon.main(QueryStruct.baseQuery.get(i - 1));
		notToDrop = QueryStruct.newTableName.get(i);
	} else {
		parseTree = false;
		queryExecutor(queryArray[i] + ";", file, theLastQuery, parseTree);

		results = ImpalaDaemon.main(QueryStruct.baseQuery.get(i));
	}
	return results;
}
 
開發者ID:martinpz,項目名稱:TriAL-QL-Engine,代碼行數:27,代碼來源:AppImpala.java

示例10: checkForProblems

import org.antlr.v4.runtime.tree.ParseTreeWalker; //導入依賴的package包/類
/**
 * Performs the first stage of assembling a program. But stops once it
 * determines whether the program is valid or not. This is useful when only
 * the validity of the program needs to be known.
 * @param input the program string to assemble
 * @return any problems with the program (empty list if program valid)
 */
public static List<Problem> checkForProblems(String input) {
    StoreProblemLogger log = new StoreProblemLogger();

    input += '\n'; // to parse correctly, must end with a newline

    SimpLexer lexer = new SimpLexer(new ANTLRInputStream(input));
    SimpParser parser = new SimpParser(new CommonTokenStream(lexer));

    // prevent outputting to the console
    lexer.removeErrorListeners();
    parser.removeErrorListeners();

    // try to parse a program from the input
    SimpParser.ProgramContext tree = parser.program();

    ProgramExtractor extractor = new ProgramExtractor(log);
    ParseTreeWalker.DEFAULT.walk(extractor, tree);

    return log.getProblems();
}
 
開發者ID:mbway,項目名稱:Simulizer,代碼行數:28,代碼來源:Assembler.java

示例11: 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

示例12: 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

示例13: compileQueryNoOptimize

import org.antlr.v4.runtime.tree.ParseTreeWalker; //導入依賴的package包/類
/**
 * <p>Create an Elasticsearch query for the given search string but does
 * not apply the {@link ElasticsearchQueryOptimizer} to it.</p>
 * @param search the search string
 * @return the Elasticsearch query (may be null)
 */
protected JsonObject compileQueryNoOptimize(String search) {
  if (search == null || search.isEmpty()) {
    // match everything by default
    return matchAllQuery();
  }
  
  // parse query
  QueryLexer lexer = new QueryLexer(new ANTLRInputStream(search.trim()));
  CommonTokenStream tokens = new CommonTokenStream(lexer);
  QueryParser parser = new QueryParser(tokens);
  QueryContext ctx = parser.query();
  
  // compile query to QueryBuilder
  QueryCompilerListener listener = new QueryCompilerListener();
  ParseTreeWalker.DEFAULT.walk(listener, ctx);
  
  if (listener.result.isEmpty()) {
    return matchAllQuery();
  }
  return listener.result.pop();
}
 
開發者ID:georocket,項目名稱:georocket,代碼行數:28,代碼來源:DefaultQueryCompiler.java

示例14: 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

示例15: processFile

import org.antlr.v4.runtime.tree.ParseTreeWalker; //導入依賴的package包/類
public static Document processFile(String filePath) {
	Pair<Parser, Lexer> pl = parsePHP(filePath);
	PHPParser parser = (PHPParser) pl.a;
	parser.setBuildParseTree(true);
    /* 
     * htmlDocument is the start rule (the top-level rule)
     * for the PHP grammar
     */
	ParserRuleContext tree =   parser.htmlDocument();
	List<String> ruleNames = Arrays.asList(parser.getRuleNames());
	Map<Integer, String> invTokenMap = getInvTokenMap(parser);
	TokenStream tokenStream = parser.getTokenStream();
	ParseTreeDOMSerializer ptSerializer = new ParseTreeDOMSerializer(ruleNames, invTokenMap, tokenStream);
	ParseTreeWalker.DEFAULT.walk(ptSerializer, tree);
	Document result= ptSerializer.getDOMDocument();
	return result;
}
 
開發者ID:wsdookadr,項目名稱:mdetect,代碼行數:18,代碼來源:ParseUtils.java


注:本文中的org.antlr.v4.runtime.tree.ParseTreeWalker類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。