Search in sources :

Example 1 with HOGMParser

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;
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) Expression(com.sri.ai.expresso.api.Expression) HOGMLexer(com.sri.ai.praise.model.v1.hogm.antlr.HOGMLexer) HOGMParser(com.sri.ai.praise.model.v1.hogm.antlr.HOGMParser) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 2 with HOGMParser

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;
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) Expression(com.sri.ai.expresso.api.Expression) HOGMLexer(com.sri.ai.praise.model.v1.hogm.antlr.HOGMLexer) HOGMParser(com.sri.ai.praise.model.v1.hogm.antlr.HOGMParser) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Aggregations

Expression (com.sri.ai.expresso.api.Expression)2 HOGMLexer (com.sri.ai.praise.model.v1.hogm.antlr.HOGMLexer)2 HOGMParser (com.sri.ai.praise.model.v1.hogm.antlr.HOGMParser)2 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)2 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)2 ParseTree (org.antlr.v4.runtime.tree.ParseTree)2