use of org.antlr.v4.runtime.tree in project oxTrust by GluuFederation.
the class ScimFilterParser method criteria.
public final CriteriaContext criteria() throws RecognitionException {
CriteriaContext _localctx = new CriteriaContext(_ctx, getState());
enterRule(_localctx, 4, RULE_criteria);
try {
int _alt;
enterOuterAlt(_localctx, 1);
{
setState(139);
match(T__0);
setState(141);
_errHandler.sync(this);
_alt = 1 + 1;
do {
switch(_alt) {
case 1 + 1:
{
{
setState(140);
matchWildcard();
}
}
break;
default:
throw new NoViableAltException(this);
}
setState(143);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input, 20, _ctx);
} while (_alt != 1 && _alt != org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER);
setState(145);
match(T__0);
}
} catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
} finally {
exitRule();
}
return _localctx;
}
use of org.antlr.v4.runtime.tree in project incubator-systemml by apache.
the class PyDMLParserWrapper method doParse.
/**
* This function is supposed to be called directly only from PydmlSyntacticValidator when it encounters 'import'
* @param fileName script file name
* @param dmlScript script file contents
* @param sourceNamespace namespace from source statement
* @param argVals script arguments
* @return dml program, or null if at least one error
*/
public DMLProgram doParse(String fileName, String dmlScript, String sourceNamespace, Map<String, String> argVals) {
DMLProgram dmlPgm = null;
ANTLRInputStream in;
try {
if (dmlScript == null) {
dmlScript = readDMLScript(fileName, LOG);
}
InputStream stream = new ByteArrayInputStream(dmlScript.getBytes());
in = new org.antlr.v4.runtime.ANTLRInputStream(stream);
} catch (FileNotFoundException e) {
throw new ParseException("Cannot find file/resource: " + fileName, e);
} catch (IOException e) {
throw new ParseException("Cannot open file: " + fileName, e);
} catch (LanguageException e) {
throw new ParseException(e.getMessage(), e);
}
ProgramrootContext ast = null;
CustomErrorListener errorListener = new CustomErrorListener();
try {
PydmlLexer lexer = new PydmlLexer(in);
CommonTokenStream tokens = new CommonTokenStream(lexer);
PydmlParser antlr4Parser = new PydmlParser(tokens);
// For now no optimization, since it is not able to parse integer value.
boolean tryOptimizedParsing = false;
if (tryOptimizedParsing) {
// Try faster and simpler SLL
antlr4Parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
antlr4Parser.removeErrorListeners();
antlr4Parser.setErrorHandler(new BailErrorStrategy());
try {
ast = antlr4Parser.programroot();
// If successful, no need to try out full LL(*) ... SLL was enough
} catch (ParseCancellationException ex) {
// Error occurred, so now try full LL(*) for better error messages
tokens.reset();
antlr4Parser.reset();
if (fileName != null) {
errorListener.setCurrentFileName(fileName);
} else {
errorListener.setCurrentFileName("MAIN_SCRIPT");
}
// Set our custom error listener
antlr4Parser.addErrorListener(errorListener);
antlr4Parser.setErrorHandler(new DefaultErrorStrategy());
antlr4Parser.getInterpreter().setPredictionMode(PredictionMode.LL);
ast = antlr4Parser.programroot();
}
} else {
// Set our custom error listener
antlr4Parser.removeErrorListeners();
antlr4Parser.addErrorListener(errorListener);
errorListener.setCurrentFileName(fileName);
// Now do the parsing
ast = antlr4Parser.programroot();
}
} catch (Exception e) {
throw new ParseException("ERROR: Cannot parse the program:" + fileName, e);
}
// Now convert the parse tree into DMLProgram
// Do syntactic validation while converting
ParseTree tree = ast;
// And also do syntactic validation
ParseTreeWalker walker = new ParseTreeWalker();
// Get list of function definitions which take precedence over built-in functions if same name
PydmlPreprocessor prep = new PydmlPreprocessor(errorListener);
walker.walk(prep, tree);
// Syntactic validation
PydmlSyntacticValidator validator = new PydmlSyntacticValidator(errorListener, argVals, sourceNamespace, prep.getFunctionDefs());
walker.walk(validator, tree);
errorListener.unsetCurrentFileName();
this.parseIssues = errorListener.getParseIssues();
this.atLeastOneWarning = errorListener.isAtLeastOneWarning();
this.atLeastOneError = errorListener.isAtLeastOneError();
if (atLeastOneError) {
throw new ParseException(parseIssues, dmlScript);
}
if (atLeastOneWarning) {
LOG.warn(CustomErrorListener.generateParseIssuesMessage(dmlScript, parseIssues));
}
dmlPgm = createDMLProgram(ast, sourceNamespace);
return dmlPgm;
}
use of org.antlr.v4.runtime.tree in project components by Talend.
the class SoqlParser method anyword.
public final AnywordContext anyword() throws RecognitionException {
AnywordContext _localctx = new AnywordContext(_ctx, getState());
enterRule(_localctx, 22, RULE_anyword);
try {
int _alt;
enterOuterAlt(_localctx, 1);
{
setState(86);
_errHandler.sync(this);
_alt = 1;
do {
switch(_alt) {
case 1:
{
{
setState(85);
match(ANYCHAR);
}
}
break;
default:
throw new NoViableAltException(this);
}
setState(88);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input, 8, _ctx);
} while (_alt != 2 && _alt != org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER);
}
} catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
} finally {
exitRule();
}
return _localctx;
}
use of org.antlr.v4.runtime.tree in project components by Talend.
the class SoqlParser method objectPrefix.
public final ObjectPrefixContext objectPrefix() throws RecognitionException {
ObjectPrefixContext _localctx = new ObjectPrefixContext(_ctx, getState());
enterRule(_localctx, 16, RULE_objectPrefix);
try {
int _alt;
enterOuterAlt(_localctx, 1);
{
setState(73);
_errHandler.sync(this);
_alt = 1;
do {
switch(_alt) {
case 1:
{
{
setState(71);
match(NAME);
setState(72);
match(DOT);
}
}
break;
default:
throw new NoViableAltException(this);
}
setState(75);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input, 7, _ctx);
} while (_alt != 2 && _alt != org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER);
}
} catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
} finally {
exitRule();
}
return _localctx;
}
use of org.antlr.v4.runtime.tree in project antlr4 by tunnelvisionlabs.
the class TimeLexerSpeed method lex_legacy_java_utf8.
public void lex_legacy_java_utf8(int n, boolean clearLexerDFACache) throws Exception {
InputStream is = TimeLexerSpeed.class.getClassLoader().getResourceAsStream(Parser_java_file);
try {
InputStreamReader isr = new InputStreamReader(is, Charset.forName("UTF-8"));
try {
BufferedReader br = new BufferedReader(isr);
try {
@SuppressWarnings("deprecation") CharStream input = new org.antlr.v4.runtime.ANTLRInputStream(br);
JavaLexer lexer = new JavaLexer(input);
double avg = tokenize(lexer, n, clearLexerDFACache);
String currentMethodName = new Exception().getStackTrace()[0].getMethodName();
if (output)
System.out.printf("%27s average time %5dus over %4d runs of %5d symbols%s\n", currentMethodName, (int) avg, n, input.size(), clearLexerDFACache ? " DFA cleared" : "");
} finally {
br.close();
}
} finally {
isr.close();
}
} finally {
is.close();
}
}
Aggregations