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


Java ANTLRInputStream类代码示例

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


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

示例1: eval

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

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

示例3: buildAntlrTree

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

示例4: callSql

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

示例5: GraphParser

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

示例6: scriptValidation

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

示例7: build

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

示例8: makeBasicParser

import org.antlr.v4.runtime.ANTLRInputStream; //导入依赖的package包/类
private static <T extends Parser> T makeBasicParser(Class<T> parserClass,
        ANTLRInputStream stream, String parsedObjectName, List<AntlrError> errors) {
    Lexer lexer;
    Parser parser;
    if (parserClass.isAssignableFrom(SQLParser.class)) {
        lexer = new SQLLexer(stream);
        parser = new SQLParser(new CommonTokenStream(lexer));
    } else if (parserClass.isAssignableFrom(IgnoreListParser.class)) {
        lexer = new IgnoreListLexer(stream);
        parser = new IgnoreListParser(new CommonTokenStream(lexer));
    } else {
        throw new IllegalArgumentException("Unknown parser class: " + parserClass);
    }

    CustomAntlrErrorListener err = new CustomAntlrErrorListener(parsedObjectName, errors);
    lexer.removeErrorListeners();
    lexer.addErrorListener(err);
    parser.removeErrorListeners();
    parser.addErrorListener(err);

    return parserClass.cast(parser);
}
 
开发者ID:pgcodekeeper,项目名称:pgcodekeeper,代码行数:23,代码来源:AntlrParser.java

示例9: itShouldGenerateLingualQuery

import org.antlr.v4.runtime.ANTLRInputStream; //导入依赖的package包/类
@Test
public void itShouldGenerateLingualQuery() throws ParseException {
	String dateInString = "2012-01-10 00:00:00";
	remoteFilterJson.setCondition("(f1  not in ('1') and f2 = '"+dateInString+"') or (f3=23.23 and f4=1234.123)");
	String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
	SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT);
	formatter.setTimeZone(TimeZone.getDefault());
	Date date = formatter.parse(dateInString);
	formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
	dateInString = formatter.format(date);

	ANTLRInputStream stream = new ANTLRInputStream(remoteFilterJson.getCondition());
	QueryParserLexer lexer = new QueryParserLexer(stream);
	CommonTokenStream tokenStream = new CommonTokenStream(lexer);
	QueryParserParser parser = new QueryParserParser(tokenStream);
	parser.removeErrorListeners();
	LingualQueryCreator customVisitor = new LingualQueryCreator(remoteFilterJson.getSchema());
	String lingualExpression = customVisitor.visit(parser.eval());
	Assert.assertEquals(
			"((\"f1\" is not null and \"f1\" not in('1'))  and  \"f2\" = timestamp '"+dateInString+"')  or  (\"f3\" = cast(23.23 as float)  and  \"f4\" = cast(1234.123 as double))",
			lingualExpression);
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:23,代码来源:LingualQueryCreatorTest.java

示例10: itShouldGenerateLingualQueryWithNotLikeClause

import org.antlr.v4.runtime.ANTLRInputStream; //导入依赖的package包/类
@Test
public void itShouldGenerateLingualQueryWithNotLikeClause() throws ParseException {
	String dateInString = "2012-01-10 00:00:00";
	remoteFilterJson.setCondition("(f1 not like 'condition' and f2 = '"+dateInString+"') or (f3=23.23 and f4=1234.123)");
	String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
	SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT);
	formatter.setTimeZone(TimeZone.getDefault());
	Date date = formatter.parse(dateInString);
	formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
	dateInString = formatter.format(date);

	ANTLRInputStream stream = new ANTLRInputStream(remoteFilterJson.getCondition());
	QueryParserLexer lexer = new QueryParserLexer(stream);
	CommonTokenStream tokenStream = new CommonTokenStream(lexer);
	QueryParserParser parser = new QueryParserParser(tokenStream);
	parser.removeErrorListeners();
	LingualQueryCreator customVisitor = new LingualQueryCreator(remoteFilterJson.getSchema());
	String lingualExpression = customVisitor.visit(parser.eval());

	Assert.assertEquals(
			"((\"f1\" is not null and \"f1\" not like 'condition')  and  \"f2\" = timestamp '"+dateInString+"')  or  (\"f3\" = cast(23.23 as float)  and  \"f4\" = cast(1234.123 as double))",
			lingualExpression);
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:24,代码来源:LingualQueryCreatorTest.java

示例11: itShouldGenerateLingualQueryWithBetweenClause

import org.antlr.v4.runtime.ANTLRInputStream; //导入依赖的package包/类
@Test
public void itShouldGenerateLingualQueryWithBetweenClause() {

	remoteFilterJson.setCondition("f3 between 10 and 20 and f3 BETWEEN 10 AND 20");

	ANTLRInputStream stream = new ANTLRInputStream(remoteFilterJson.getCondition());
	QueryParserLexer lexer = new QueryParserLexer(stream);
	CommonTokenStream tokenStream = new CommonTokenStream(lexer);
	QueryParserParser parser = new QueryParserParser(tokenStream);
	parser.removeErrorListeners();
	LingualQueryCreator customVisitor = new LingualQueryCreator(remoteFilterJson.getSchema());
	String lingualExpression = customVisitor.visit(parser.eval());
	Assert.assertEquals(
			"\"f3\" between  cast(10 as float)  and  cast(20 as float)  and  \"f3\" BETWEEN  cast(10 as float)  AND  cast(20 as float)",
			lingualExpression);
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:17,代码来源:LingualQueryCreatorTest.java

示例12: itShouldGenerateLingualQueryWithMultipleCondition

import org.antlr.v4.runtime.ANTLRInputStream; //导入依赖的package包/类
@Test
public void itShouldGenerateLingualQueryWithMultipleCondition() {

	remoteFilterJson.setCondition("f1 = 'or maybe' AND f1 <> 'or mat' and f3 between 10 and 20");

	ANTLRInputStream stream = new ANTLRInputStream(remoteFilterJson.getCondition());
	QueryParserLexer lexer = new QueryParserLexer(stream);
	CommonTokenStream tokenStream = new CommonTokenStream(lexer);
	QueryParserParser parser = new QueryParserParser(tokenStream);
	parser.removeErrorListeners();
	LingualQueryCreator customVisitor = new LingualQueryCreator(remoteFilterJson.getSchema());
	String lingualExpression = customVisitor.visit(parser.eval());
	Assert.assertEquals(
			"\"f1\" = 'or maybe'  AND  \"f1\" <> 'or mat'  and  \"f3\" between  cast(10 as float)  and  cast(20 as float)",
			lingualExpression);
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:17,代码来源:LingualQueryCreatorTest.java

示例13: itShouldGenerateLingualQueryForBetweenClauseAndTimestampDataType

import org.antlr.v4.runtime.ANTLRInputStream; //导入依赖的package包/类
@Test
public void itShouldGenerateLingualQueryForBetweenClauseAndTimestampDataType() throws ParseException {
	String dateInString1 = "1999-12-31 18:30:00";
	String dateInString2 = "2000-01-11 18:30:00";
	remoteFilterJson.setCondition("f2 between '"+dateInString1+"' AND '"+dateInString2+"'");
	String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
	SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT);
	formatter.setTimeZone(TimeZone.getDefault());
	Date date1 = formatter.parse(dateInString1);
	Date date2 = formatter.parse(dateInString2);
	formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
	dateInString1 = formatter.format(date1);
	dateInString2 = formatter.format(date2);

	ANTLRInputStream stream = new ANTLRInputStream(remoteFilterJson.getCondition());
	QueryParserLexer lexer = new QueryParserLexer(stream);
	CommonTokenStream tokenStream = new CommonTokenStream(lexer);
	QueryParserParser parser = new QueryParserParser(tokenStream);
	parser.removeErrorListeners();
	LingualQueryCreator customVisitor = new LingualQueryCreator(remoteFilterJson.getSchema());
	String lingualExpression = customVisitor.visit(parser.eval());
	Assert.assertEquals("\"f2\" between timestamp '"+dateInString1+"' AND  timestamp '"+dateInString2+"'", lingualExpression);
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:24,代码来源:LingualQueryCreatorTest.java

示例14: checkValidYangFileForNoSyntaxError

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

示例15: checkInvalidYangFileForSyntaxError

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


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