Search in sources :

Example 41 with DrlParser

use of org.drools.compiler.compiler.DrlParser in project drools by kiegroup.

the class DRLIncompleteCodeTest method testIncompleteCode7.

@Test
public void testIncompleteCode7() throws DroolsParserException, RecognitionException {
    String input = "package a.b.c imrt a.b.c.*" + " rule MyRule when Class ( property memberOf collection ) then end " + " query MyQuery Class ( property memberOf collection ) end ";
    DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
    PackageDescr descr = parser.parse(true, input);
    assertNotNull(descr);
}
Also used : DrlParser(org.drools.compiler.compiler.DrlParser) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) Test(org.junit.Test)

Example 42 with DrlParser

use of org.drools.compiler.compiler.DrlParser in project drools by kiegroup.

the class DRLIncompleteCodeTest method testIncompleteCode10.

@Test
@Ignore
public void testIncompleteCode10() throws DroolsParserException, RecognitionException {
    String input = "package a.b.c import a.b.c.*" + " rule MyRule xxxxx Class ( property memberOf " + " query MyQuery Class ( property memberOf collection ) end ";
    DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
    PackageDescr descr = parser.parse(true, input);
    assertEquals("a.b.c", descr.getNamespace());
    assertEquals("a.b.c.*", descr.getImports().get(0).getTarget());
    assertEquals(0, descr.getRules().size());
}
Also used : DrlParser(org.drools.compiler.compiler.DrlParser) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 43 with DrlParser

use of org.drools.compiler.compiler.DrlParser in project drools by kiegroup.

the class RuleParserTest method testExpanderLineSpread.

@Test
public void testExpanderLineSpread() throws Exception {
    final DrlParser parser = new DrlParser(LanguageLevelOption.DRL6);
    final PackageDescr pkg = parser.parse(this.getReader("expander_spread_lines.dslr"), this.getReader("complex.dsl"));
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
    assertEquals(1, rule.getLhs().getDescrs().size());
    final OrDescr or = (OrDescr) rule.getLhs().getDescrs().get(0);
    assertEquals(2, or.getDescrs().size());
    assertNotNull((String) rule.getConsequence());
}
Also used : RuleDescr(org.drools.compiler.lang.descr.RuleDescr) DrlParser(org.drools.compiler.compiler.DrlParser) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) OrDescr(org.drools.compiler.lang.descr.OrDescr) Test(org.junit.Test)

Example 44 with DrlParser

use of org.drools.compiler.compiler.DrlParser in project drools by kiegroup.

the class RuleParserTest method testPackageWithError.

@Test
public void testPackageWithError() throws Exception {
    final String source = "package 12 foo.bar.baz";
    final DrlParser parser = new DrlParser(LanguageLevelOption.DRL6);
    final PackageDescr pkg = parser.parse(true, new StringReader(source));
    assertTrue(parser.hasErrors());
    assertEquals("foo.bar.baz", pkg.getName());
}
Also used : StringReader(java.io.StringReader) DrlParser(org.drools.compiler.compiler.DrlParser) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) Test(org.junit.Test)

Aggregations

DrlParser (org.drools.compiler.compiler.DrlParser)44 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)43 Test (org.junit.Test)32 InputStreamReader (java.io.InputStreamReader)10 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)9 StringReader (java.io.StringReader)8 CompositePackageDescr (org.drools.compiler.lang.descr.CompositePackageDescr)6 ArrayList (java.util.ArrayList)5 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)5 ParserError (org.drools.compiler.compiler.ParserError)5 DrlDumper (org.drools.compiler.lang.DrlDumper)4 Reader (java.io.Reader)3 List (java.util.List)3 DroolsParserException (org.drools.compiler.compiler.DroolsParserException)3 PatternDescr (org.drools.compiler.lang.descr.PatternDescr)3 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)3 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)3 Ignore (org.junit.Ignore)3 AttributeDescr (org.drools.compiler.lang.descr.AttributeDescr)2 MVELConsequence (org.drools.core.base.mvel.MVELConsequence)2