Search in sources :

Example 1 with MvelParser

use of org.drools.mvel.parser.MvelParser in project drools by kiegroup.

the class DrlxCompilerTest method testWhitespace.

@Test
public void testWhitespace() {
    ParseStart<Expression> context = ParseStart.EXPRESSION;
    MvelParser mvelParser = new MvelParser(new ParserConfiguration(), false);
    ParseResult<Expression> result = mvelParser.parse(context, provider("1\n+1"));
    assertEquals("1 + 1", result.getResult().get().toString());
}
Also used : Expression(com.github.javaparser.ast.expr.Expression) MvelParser(org.drools.mvel.parser.MvelParser) ParserConfiguration(com.github.javaparser.ParserConfiguration) Test(org.junit.Test)

Example 2 with MvelParser

use of org.drools.mvel.parser.MvelParser in project drools by kiegroup.

the class DrlxCompiler method toPackageDescr.

public PackageDescr toPackageDescr(Resource resource) throws IOException {
    ParseStart<CompilationUnit> context = ParseStart.DRLX_COMPILATION_UNIT;
    MvelParser mvelParser = new MvelParser(new ParserConfiguration(), false);
    ParseResult<CompilationUnit> result = mvelParser.parse(context, provider(resource.getReader()));
    if (result.isSuccessful()) {
        DrlxVisitor drlxCompiler = new DrlxVisitor();
        drlxCompiler.visit(result.getResult().get(), null);
        PackageDescr pkg = drlxCompiler.getPackageDescr();
        if (pkg == null) {
            this.results.add(new ParserError(resource, "Parser returned a null Package", 0, 0));
            return null;
        } else {
            pkg.setResource(resource);
            return pkg;
        }
    } else {
        for (Problem problem : result.getProblems()) {
            TokenRange tokenRange = problem.getLocation().get();
            Range range = tokenRange.getBegin().getRange().get();
            int lineCount = range.getLineCount();
            this.results.add(new ParserError(problem.getMessage(), lineCount, -1));
        }
        return null;
    }
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) MvelParser(org.drools.mvel.parser.MvelParser) ParserError(org.drools.drl.parser.ParserError) Problem(com.github.javaparser.Problem) TokenRange(com.github.javaparser.TokenRange) PackageDescr(org.drools.drl.ast.descr.PackageDescr) Range(com.github.javaparser.Range) TokenRange(com.github.javaparser.TokenRange) ParserConfiguration(com.github.javaparser.ParserConfiguration)

Aggregations

ParserConfiguration (com.github.javaparser.ParserConfiguration)2 MvelParser (org.drools.mvel.parser.MvelParser)2 Problem (com.github.javaparser.Problem)1 Range (com.github.javaparser.Range)1 TokenRange (com.github.javaparser.TokenRange)1 CompilationUnit (com.github.javaparser.ast.CompilationUnit)1 Expression (com.github.javaparser.ast.expr.Expression)1 PackageDescr (org.drools.drl.ast.descr.PackageDescr)1 ParserError (org.drools.drl.parser.ParserError)1 Test (org.junit.Test)1