Search in sources :

Example 6 with DroolsParserException

use of org.drools.drl.parser.DroolsParserException in project drools by kiegroup.

the class Misc2Test method testEvalConstraintWithMvelOperator.

@Test
public void testEvalConstraintWithMvelOperator() {
    String drl = "rule \"yeah\" " + "\tdialect \"mvel\"\n when " + "Foo( eval( field soundslike \"water\" ) )" + " then " + "end";
    DrlParser drlParser = new DrlParser();
    PackageDescr packageDescr;
    try {
        packageDescr = drlParser.parse(true, drl);
    } catch (DroolsParserException e) {
        throw new RuntimeException(e);
    }
    RuleDescr r = packageDescr.getRules().get(0);
    PatternDescr pd = (PatternDescr) r.getLhs().getDescrs().get(0);
    assertEquals(1, pd.getConstraint().getDescrs().size());
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) RuleDescr(org.drools.drl.ast.descr.RuleDescr) DrlParser(org.drools.drl.parser.DrlParser) FactWithString(org.drools.mvel.integrationtests.facts.FactWithString) PackageDescr(org.drools.drl.ast.descr.PackageDescr) DroolsParserException(org.drools.drl.parser.DroolsParserException) Test(org.junit.Test)

Example 7 with DroolsParserException

use of org.drools.drl.parser.DroolsParserException in project drools by kiegroup.

the class ErrorsParserTest method testExpanderErrorsAfterExpansion.

@Test
public void testExpanderErrorsAfterExpansion() throws Exception {
    String name = "expander_post_errors.dslr";
    Expander expander = new DefaultExpander();
    String expanded = expander.expand(this.getReader(name));
    DRLParser parser = parse(name, expanded);
    parser.compilationUnit();
    assertTrue(parser.hasErrors());
    assertEquals(1, parser.getErrors().size());
    DroolsParserException err = (DroolsParserException) parser.getErrors().get(0);
    assertEquals(6, err.getLineNumber());
}
Also used : DefaultExpander(org.drools.drl.parser.lang.dsl.DefaultExpander) Expander(org.drools.drl.parser.lang.Expander) DRLParser(org.drools.drl.parser.lang.DRLParser) DroolsParserException(org.drools.drl.parser.DroolsParserException) DefaultExpander(org.drools.drl.parser.lang.dsl.DefaultExpander) Test(org.junit.Test)

Example 8 with DroolsParserException

use of org.drools.drl.parser.DroolsParserException in project drools by kiegroup.

the class DRLContextTest method testCheckLHSLocationDetermination_OPERATORS_AND_COMPLEMENT2.

@Test(timeout = 10 * 1000)
public void testCheckLHSLocationDetermination_OPERATORS_AND_COMPLEMENT2() throws DroolsParserException, RecognitionException {
    String input = "rule MyRule when Class ( property not memberOf collection";
    DRLParser parser = getParser(input);
    parser.enableEditorInterface();
    try {
        parser.compilationUnit();
    } catch (Exception ex) {
    }
    assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, getLastIntegerValue(parser.getEditorInterface().get(0).getContent()));
}
Also used : DRLParser(org.drools.drl.parser.lang.DRLParser) DroolsParserException(org.drools.drl.parser.DroolsParserException) RecognitionException(org.antlr.runtime.RecognitionException) Test(org.junit.Test)

Example 9 with DroolsParserException

use of org.drools.drl.parser.DroolsParserException in project drools by kiegroup.

the class DRLContextTest method testCheckLHSLocationDetermination_OPERATORS_AND_COMPLEMENT1.

@Test(timeout = 10 * 1000)
public void testCheckLHSLocationDetermination_OPERATORS_AND_COMPLEMENT1() throws DroolsParserException, RecognitionException {
    String input = "rule MyRule when Class ( property memberOf collection ";
    DRLParser parser = getParser(input);
    parser.enableEditorInterface();
    try {
        parser.compilationUnit();
    } catch (Exception ex) {
    }
    assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, getLastIntegerValue(parser.getEditorInterface().get(0).getContent()));
}
Also used : DRLParser(org.drools.drl.parser.lang.DRLParser) DroolsParserException(org.drools.drl.parser.DroolsParserException) RecognitionException(org.antlr.runtime.RecognitionException) Test(org.junit.Test)

Example 10 with DroolsParserException

use of org.drools.drl.parser.DroolsParserException in project drools by kiegroup.

the class DRLContextTest method testCheckLHSLocationDetermination_COMPOSITE_OPERATOR1.

@Test(timeout = 10 * 1000)
public void testCheckLHSLocationDetermination_COMPOSITE_OPERATOR1() throws DroolsParserException, RecognitionException {
    String input = "rule MyRule when Class ( property in ( ";
    DRLParser parser = getParser(input);
    parser.enableEditorInterface();
    try {
        parser.compilationUnit();
    } catch (Exception ex) {
    }
    assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, getLastIntegerValue(parser.getEditorInterface().get(0).getContent()));
}
Also used : DRLParser(org.drools.drl.parser.lang.DRLParser) DroolsParserException(org.drools.drl.parser.DroolsParserException) RecognitionException(org.antlr.runtime.RecognitionException) Test(org.junit.Test)

Aggregations

DroolsParserException (org.drools.drl.parser.DroolsParserException)12 Test (org.junit.Test)6 DRLParser (org.drools.drl.parser.lang.DRLParser)5 RecognitionException (org.antlr.runtime.RecognitionException)4 ConstraintConnectiveDescr (org.drools.drl.ast.descr.ConstraintConnectiveDescr)3 DrlExprParser (org.drools.drl.parser.DrlExprParser)3 DescrBuildError (org.drools.compiler.compiler.DescrBuildError)2 XmlPackageReader (org.drools.compiler.compiler.xml.XmlPackageReader)2 SAXException (org.xml.sax.SAXException)2 PrintWriter (java.io.PrintWriter)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 ReaderResource (org.drools.core.io.impl.ReaderResource)1 Declaration (org.drools.core.rule.Declaration)1 QueryArgument (org.drools.core.rule.QueryArgument)1 XmlChangeSetReader (org.drools.core.xml.XmlChangeSetReader)1 PackageDescr (org.drools.drl.ast.descr.PackageDescr)1 PatternDescr (org.drools.drl.ast.descr.PatternDescr)1 RuleDescr (org.drools.drl.ast.descr.RuleDescr)1