Search in sources :

Example 1 with DRLLexer

use of org.drools.drl.parser.lang.DRLLexer 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;
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) DRLExpressions(org.drools.drl.parser.lang.DRLExpressions) DRLLexer(org.drools.drl.parser.lang.DRLLexer) ParserHelper(org.drools.drl.parser.lang.ParserHelper) RecognizerSharedState(org.antlr.runtime.RecognizerSharedState) BaseDescr(org.drools.drl.ast.descr.BaseDescr) ConstraintConnectiveDescr(org.drools.drl.ast.descr.ConstraintConnectiveDescr) RecognitionException(org.antlr.runtime.RecognitionException)

Aggregations

ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)1 CommonTokenStream (org.antlr.runtime.CommonTokenStream)1 RecognitionException (org.antlr.runtime.RecognitionException)1 RecognizerSharedState (org.antlr.runtime.RecognizerSharedState)1 BaseDescr (org.drools.drl.ast.descr.BaseDescr)1 ConstraintConnectiveDescr (org.drools.drl.ast.descr.ConstraintConnectiveDescr)1 DRLExpressions (org.drools.drl.parser.lang.DRLExpressions)1 DRLLexer (org.drools.drl.parser.lang.DRLLexer)1 ParserHelper (org.drools.drl.parser.lang.ParserHelper)1