use of org.antlr.runtime.ANTLRStringStream in project drools by kiegroup.
the class DrlExprParser method parse.
/**
* Parse an expression from text
*/
public ConstraintConnectiveDescr parse(final String text) {
ConstraintConnectiveDescr constraint = null;
try {
DRLLexer lexer = DRLFactory.getDRLLexer(new ANTLRStringStream(text), languageLevel);
CommonTokenStream input = new CommonTokenStream(lexer);
RecognizerSharedState state = new RecognizerSharedState();
helper = new ParserHelper(input, state, languageLevel);
DRLExpressions parser = DRLFactory.getDRLExpressions(input, state, helper, languageLevel);
parser.setBuildDescr(true);
// setting initial value just in case
parser.setLeftMostExpr(null);
BaseDescr expr = parser.conditionalOrExpression();
if (expr != null && !parser.hasErrors()) {
constraint = ConstraintConnectiveDescr.newAnd();
constraint.addOrMerge(expr);
}
} catch (RecognitionException e) {
helper.reportError(e);
}
return constraint;
}
use of org.antlr.runtime.ANTLRStringStream in project yamcs-studio by yamcs.
the class FormulaAst method createParser.
/**
* Creates a parser for the given text.
*
* @param text the string to be parsed
* @return the new parser
*/
static FormulaParser createParser(String text) {
CharStream stream = new ANTLRStringStream(text);
FormulaLexer lexer = new FormulaLexer(stream);
TokenStream tokenStream = new CommonTokenStream(lexer);
return new FormulaParser(tokenStream);
}
use of org.antlr.runtime.ANTLRStringStream in project ceylon-compiler by ceylon.
the class IssuesTests_1500_1999 method benchmarkParse.
private void benchmarkParse(String file) throws Exception {
String readSource = readFile(new File(getPackagePath(), file));
String source = readSource.toString();
char[] chars = source.toCharArray();
LineMap map = Position.makeLineMap(chars, chars.length, false);
System.err.println(map.hashCode());
ANTLRStringStream input = new ANTLRStringStream(source);
CeylonLexer lexer = new CeylonLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
CeylonParser parser = new CeylonParser(tokens);
// CompilationUnit cu = parser.compilationUnit();
// System.err.println(cu.hashCode());
}
use of org.antlr.runtime.ANTLRStringStream in project che by eclipse.
the class ANTLRExpressionParser method parse.
private void parse() throws RecognitionException {
JavaLexer lexer = new JavaLexer(new ANTLRStringStream(getExpression()));
CommonTokenStream tokens = new CommonTokenStream(lexer);
JavaParser parser = new JavaParser(tokens);
nodes = new CommonTreeNodeStream(parser.expression().getTree());
}
use of org.antlr.runtime.ANTLRStringStream in project cassandra by apache.
the class CqlParserTest method testAddErrorListener.
@Test
public void testAddErrorListener() throws Exception {
SyntaxErrorCounter firstCounter = new SyntaxErrorCounter();
SyntaxErrorCounter secondCounter = new SyntaxErrorCounter();
CharStream stream = new ANTLRStringStream("SELECT * FORM FROM test");
CqlLexer lexer = new CqlLexer(stream);
TokenStream tokenStream = new CommonTokenStream(lexer);
CqlParser parser = new CqlParser(tokenStream);
parser.addErrorListener(firstCounter);
parser.addErrorListener(secondCounter);
// By default CqlParser should recover from the syntax error by removing FORM
// but as recoverFromMismatchedToken and recover have been overloaded, it will not
// and the returned ParsedStatement will be null.
assertNull(parser.query());
// Only one error must be reported (mismatched: FORM).
assertEquals(1, firstCounter.count);
assertEquals(1, secondCounter.count);
}
Aggregations