use of com.sri.ai.praise.model.v1.hogm.antlr.HOGMParser in project aic-praise by aic-sri-international.
the class HOGMParserWrapper method parse.
//
// PRIVATE
//
private Expression parse(String string, Parser.ErrorListener errorListener, ParseTreeRetriever parseTreeRetriever) throws RecognitionException, UnableToParseAllTheInputError, HOGModelException {
Expression result = null;
AntlrErrorListener antlrErrorListener = new AntlrErrorListener(errorListener);
ANTLRInputStream input = new ANTLRInputStream(string);
HOGMLexer lexer = new HOGMLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
HOGMParser parser = new HOGMParser(tokens);
lexer.removeErrorListeners();
parser.removeErrorListeners();
lexer.addErrorListener(antlrErrorListener);
parser.addErrorListener(antlrErrorListener);
ParseTree tree = parseTreeRetriever.retrieve(parser);
boolean eofReached = parser.getInputStream().LA(1) == Recognizer.EOF;
if (!antlrErrorListener.errorsDetected) {
if (!eofReached) {
throw new UnableToParseAllTheInputError();
} else {
lexer.removeErrorListeners();
parser.removeErrorListeners();
HOGModelVisitor hogmModelVisitor = new HOGModelVisitor();
result = hogmModelVisitor.visit(tree);
}
}
return result;
}
use of com.sri.ai.praise.model.v1.hogm.antlr.HOGMParser in project aic-praise by aic-sri-international.
the class HOGMParserWrapper method parse.
//
// PRIVATE
//
private Expression parse(String string, Parser.ErrorListener errorListener, ParseTreeRetriever parseTreeRetriever) throws RecognitionException, UnableToParseAllTheInputError, HOGModelException {
Expression result = null;
AntlrErrorListener antlrErrorListener = new AntlrErrorListener(errorListener);
ANTLRInputStream input = new ANTLRInputStream(string);
HOGMLexer lexer = new HOGMLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
HOGMParser parser = new HOGMParser(tokens);
lexer.removeErrorListeners();
parser.removeErrorListeners();
lexer.addErrorListener(antlrErrorListener);
parser.addErrorListener(antlrErrorListener);
ParseTree tree = parseTreeRetriever.retrieve(parser);
boolean eofReached = parser.getInputStream().LA(1) == Recognizer.EOF;
if (!antlrErrorListener.errorsDetected) {
if (!eofReached) {
throw new UnableToParseAllTheInputError();
} else {
lexer.removeErrorListeners();
parser.removeErrorListeners();
HOGModelVisitor hogmModelVisitor = new HOGModelVisitor();
result = hogmModelVisitor.visit(tree);
}
}
return result;
}
Aggregations