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


Java CommonTokenStream类代码示例

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


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

示例1: parse

import org.antlr.v4.runtime.CommonTokenStream; //导入依赖的package包/类
/**
 * @throws InvalidQueryException if the given query contains invalid characters or is incomplete
 */
public SqlGrammarParser.SelectStatementContext parse(String query) {
    log.trace("About to parse [{}]", query);
    long now = currentTimeMillis();

    CharStream input = CharStreams.fromString(query);
    SqlGrammarLexer lexer = new SqlGrammarLexer(input);
    TokenStream tokenStream = new CommonTokenStream(lexer);
    SqlGrammarParser parser = new SqlGrammarParser(tokenStream);

    parser.removeErrorListeners();
    parser.addErrorListener(new RaiseExceptionErrorListener());

    SqlGrammarParser.SelectStatementContext result = parser.selectStatement();

    log.trace("Successfully parsed [{}] into [{}] in [{}ms]",
            query, result.toStringTree(parser), currentTimeMillis() - now);

    return result;
}
 
开发者ID:michalwojciechowski,项目名称:coherence-sql,代码行数:23,代码来源:SqlParser.java

示例2: parseString

import org.antlr.v4.runtime.CommonTokenStream; //导入依赖的package包/类
@Override
public SortedMap<Integer, String> parseString(String fieldString) {
    CharStream is = CharStreams.fromString(fieldString);
    DrawGrammarLexer lex = new DrawGrammarLexer(is);
    CommonTokenStream tokens = new CommonTokenStream(lex);
    DrawGrammarParser parser = new DrawGrammarParser(tokens);
    palette = Palette.makeDefaultPalette("DarkSpectrum");
    final SortedMap<Integer, String> resultMap;
    try {
        resultMap = parser.root().map;
    } catch (RecognitionException | NullPointerException | StringIndexOutOfBoundsException | RasterFormatException re) {
        //Something wrong with the parsing do not update.
        return null;
    }
    return resultMap;
}
 
开发者ID:fusiled,项目名称:bitbox,代码行数:17,代码来源:PainterLogic.java

示例3: main

import org.antlr.v4.runtime.CommonTokenStream; //导入依赖的package包/类
/**
 * @param args the command line arguments
 * @throws java.io.IOException
 * @throws java.net.URISyntaxException
 */
public static void main(String[] args) throws IOException, URISyntaxException {
    final String entryPoint;
    final URL res;
    switch (args.length) {
    case 2:
        res = Paths.get(args[0]).toUri().toURL();
        entryPoint = args[1];
        break;
    default:
        System.err.println("Supply two parameters in the following order:\n- file name of the main function\n- name of the main function\n\nFor example: hello.ct main:argc:argv");
        return;
    }
    final CharStream inp = CharStreams.fromStream(res.openStream());
    final GrammarLexer lex = new GrammarLexer(inp);
    final TokenStream toks = new CommonTokenStream(lex);
    final GrammarParser parser = new GrammarParser(toks);
    System.out.println(new Translator(res.toURI()).generate(parser.program(), entryPoint));
}
 
开发者ID:plankp,项目名称:CTalk,代码行数:24,代码来源:App.java

示例4: generateAST

import org.antlr.v4.runtime.CommonTokenStream; //导入依赖的package包/类
private BooleanExpListNode generateAST(String code) {
    FormalPropertyDescriptionLexer l = new FormalPropertyDescriptionLexer(new ANTLRInputStream(code));
    CommonTokenStream ts = new CommonTokenStream(l);
    FormalPropertyDescriptionParser p = new FormalPropertyDescriptionParser(ts);

    BooleanExpScope declaredVars = new BooleanExpScope();

    preAndPostConditionsDescription.getSymbolicVariableList().forEach((v) -> {
        declaredVars.addTypeForId(v.getId(), v.getInternalTypeContainer());
    });

    return translator.generateFromSyntaxTree(
            p.booleanExpList(),
            electionDescription.getInputType().getType(),
            electionDescription.getOutputType().getType(),
            declaredVars);
}
 
开发者ID:Skypr,项目名称:BEAST,代码行数:18,代码来源:CBMCCodeGenerator.java

示例5: link

import org.antlr.v4.runtime.CommonTokenStream; //导入依赖的package包/类
/**
 * Returns an ExecutableCode that can then be run by the processor. If the given code contains
 * data section, linker will only generate memory addresses. Without loading process, referenced
 * data will be unpredictable.
 *
 * @param code The code that will be linked.
 *
 * @return The executable code.
 *
 * @throws LabelError If an undefined label used or duplicate labels exist.
 * @see Loader#load(Linker.ExecutableCode)
 */
public ExecutableCode link(String code) throws LabelError {
    definedBranches.clear();
    definedData.clear();
    addressBook.clear();
    secondPass = false;
    this.code = parseCode(code);
    AssemblerLexer lexer = new AssemblerLexer(CharStreams.fromString(code));
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    AssemblerParser parser = new AssemblerParser(tokens);
    AssemblerParser.ProgContext program = parser.prog();
    visit(program);
    secondPass = true;
    visit(program);
    List<Data> temp = new ArrayList<>(definedData.size());
    definedData.forEach((label, data) -> {
        temp.add(data);
    });
    return new ExecutableCode(this.code, temp);
}
 
开发者ID:kasirgalabs,项目名称:ETUmulator,代码行数:32,代码来源:Linker.java

示例6: buildAntlrTree

import org.antlr.v4.runtime.CommonTokenStream; //导入依赖的package包/类
private SourceContext buildAntlrTree(String source) {
    ANTLRInputStream stream = new ANTLRInputStream(source);
    PainlessLexer lexer = new EnhancedPainlessLexer(stream, sourceName);
    PainlessParser parser = new PainlessParser(new CommonTokenStream(lexer));
    ParserErrorStrategy strategy = new ParserErrorStrategy(sourceName);

    lexer.removeErrorListeners();
    parser.removeErrorListeners();

    if (settings.isPicky()) {
        setupPicky(parser);
    }

    parser.setErrorHandler(strategy);

    return parser.source();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:Walker.java

示例7: callSql

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

示例8: GraphParser

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

示例9: parseInputStream

import org.antlr.v4.runtime.CommonTokenStream; //导入依赖的package包/类
private void parseInputStream(CharStream inputStream, OboParseResultListener listener) {
  final OboLexer l = new OboLexer(inputStream);
  final Antlr4OboParser p = new Antlr4OboParser(new CommonTokenStream(l));

  p.addErrorListener(new BaseErrorListener() {
    @Override
    public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line,
        int charPositionInLine, String msg, RecognitionException e) {
      throw new IllegalStateException("Failed to parse at line " + line + " due to " + msg, e);
    }
  });

  if (debug) {
    p.addErrorListener(new DiagnosticErrorListener());
  }

  p.addParseListener(new OboParserListener(listener));

  p.oboFile();
}
 
开发者ID:Phenomics,项目名称:ontolib,代码行数:21,代码来源:OboParser.java

示例10: parse

import org.antlr.v4.runtime.CommonTokenStream; //导入依赖的package包/类
public EObject parse(final String typeExpression, final Scope scope) {
    final CharStream charStream = CharStreams.fromString(typeExpression);
    final TypeExpressionLexer lexer = new TypeExpressionLexer(charStream);
    final TokenStream tokenStream = new CommonTokenStream(lexer);
    final TypeExpressionParser typeExpressionParser = new TypeExpressionParser(tokenStream);

    lexer.removeErrorListeners();
    typeExpressionParser.removeErrorListeners();

    final ParserErrorCollector errorCollector = new ParserErrorCollector();
    lexer.addErrorListener(errorCollector);
    typeExpressionParser.addErrorListener(errorCollector);

    final TypeExpressionParser.Type_exprContext typeExpr = typeExpressionParser.type_expr();

    final EObject anyType = new TypeExpressionBuilder(scope, ARRAY_TYPE).visit(typeExpr);
    scope.getResource().getErrors().addAll(errorCollector.getErrors());

    return anyType;
}
 
开发者ID:vrapio,项目名称:rest-modeling-framework,代码行数:21,代码来源:TypeExpressionConstructor.java

示例11: doLoad

import org.antlr.v4.runtime.CommonTokenStream; //导入依赖的package包/类
@Override
protected void doLoad(final InputStream inputStream, final Map<?, ?> options) throws IOException {
    final BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
    final Optional<AbstractConstructor> optionalRootConstructor = getRootConstructor(bufferedInputStream);

    if (optionalRootConstructor.isPresent()) {
        final AbstractConstructor rootConstructor = optionalRootConstructor.get();
        final RAMLCustomLexer lexer = new RAMLCustomLexer(uri, getURIConverter());
        final TokenStream tokenStream = new CommonTokenStream(lexer);
        final RAMLParser parser = new RAMLParser(tokenStream);

        parser.removeErrorListeners();
        final ParserErrorCollector errorCollector = new ParserErrorCollector();
        parser.addErrorListener(errorCollector);

        try {
            rootConstructor.construct(parser, resourceScope);
            validate();
        } catch (final Exception e) {
            getErrors().addAll(errorCollector.getErrors());
            throw e;
        }
    }
}
 
开发者ID:vrapio,项目名称:rest-modeling-framework,代码行数:25,代码来源:RamlResource.java

示例12: api

import org.antlr.v4.runtime.CommonTokenStream; //导入依赖的package包/类
@Ignore
@Test
public void api() {
    final File apiFile = new File("/Users/mkoester/Development/commercetools-api-reference/api.raml");
    assumeTrue(apiFile.exists());

    final URI apiUri = URI.createURI(apiFile.toURI().toString());
    final URIConverter uriConverter = new RamlResourceSet().getURIConverter();
    final RAMLCustomLexer lexer = new RAMLCustomLexer(apiUri, uriConverter);
    final TokenStream tokenStream = new CommonTokenStream(lexer);

    final RAMLParser parser = new RAMLParser(tokenStream);
    final Resource resource = new RamlResourceSet().createResource(apiUri);

    final Scope scope = Scope.of(resource);
    final TypeDeclarationResolver resolver = new TypeDeclarationResolver();
    resolver.resolve(parser.api(), scope);

    assertThat(resource.getErrors()).isEmpty();
}
 
开发者ID:vrapio,项目名称:rest-modeling-framework,代码行数:21,代码来源:TypeDeclarationResolverTest.java

示例13: scriptValidation

import org.antlr.v4.runtime.CommonTokenStream; //导入依赖的package包/类
public void scriptValidation(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	String content=req.getParameter("content");
	if(StringUtils.isNotBlank(content)){
		ScriptType type=ScriptType.valueOf(req.getParameter("type"));
		ANTLRInputStream antlrInputStream=new ANTLRInputStream(content);
		RuleParserLexer lexer=new RuleParserLexer(antlrInputStream);
		CommonTokenStream steam=new CommonTokenStream(lexer);
		RuleParserParser parser=new RuleParserParser(steam);
		parser.removeErrorListeners();
		ScriptErrorListener errorListener=new ScriptErrorListener();
		parser.addErrorListener(errorListener);
		switch(type){
		case Script:
			parser.ruleSet();
			break;
		case DecisionNode:
			parser.condition();
			break;
		case ScriptNode:
			parser.actions();
			
		}
		List<ErrorInfo> infos=errorListener.getInfos();
		writeObjectToJson(resp, infos);
	}
}
 
开发者ID:youseries,项目名称:urule,代码行数:27,代码来源:CommonServletHandler.java

示例14: build

import org.antlr.v4.runtime.CommonTokenStream; //导入依赖的package包/类
public RuleSet build(String script) throws IOException{
	ANTLRInputStream antlrInputStream=new ANTLRInputStream(script);
	RuleParserLexer lexer=new RuleParserLexer(antlrInputStream);
	CommonTokenStream tokenStream=new CommonTokenStream(lexer);
	RuleParserParser parser=new RuleParserParser(tokenStream);
	ScriptDecisionTableErrorListener errorListener=new ScriptDecisionTableErrorListener();
	parser.addErrorListener(errorListener);
	BuildRulesVisitor visitor=new BuildRulesVisitor(contextBuilders,tokenStream);
	RuleSet ruleSet=visitor.visitRuleSet(parser.ruleSet());
	rebuildRuleSet(ruleSet);
	String error=errorListener.getErrorMessage();
	if(error!=null){
		throw new RuleException("Script parse error:"+error);
	}
	return ruleSet;
}
 
开发者ID:youseries,项目名称:urule,代码行数:17,代码来源:DSLRuleSetBuilder.java

示例15: evaluate

import org.antlr.v4.runtime.CommonTokenStream; //导入依赖的package包/类
public static String evaluate(String templateString, Map<String, Object> environment) {
    final Scanner s = new Scanner(templateString);
    // TODO: This is a hack that fails if a string literal contains "}"
    // TODO: It's because i couldn't be bothered nesting grammars.
    s.useDelimiter("((?!\\\\)\\$\\{)|(})");

    StringBuilder ret = new StringBuilder();
    boolean isInsideExpr = templateString.startsWith("${");
    while(s.hasNext()) {
        final String str = s.next();

        if (isInsideExpr) {
            final JsLikeExpressionLexer lexer = new JsLikeExpressionLexer(CharStreams.fromString(str));
            final CommonTokenStream tokenStream = new CommonTokenStream(lexer);
            final JsLikeExpressionParser parser = new JsLikeExpressionParser(tokenStream);


            final TemplateStringEvaluatorVisitor visitor = new TemplateStringEvaluatorVisitor(environment);

            ret.append(parser.expression().accept(visitor).toString());
        } else {
            ret.append(str);
        }

        isInsideExpr = !isInsideExpr;
    }

    return ret.toString();
}
 
开发者ID:adamkewley,项目名称:jobson,代码行数:30,代码来源:TemplateStringEvaluator.java


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