Search in sources :

Example 1 with PackageDescr

use of org.drools.compiler.lang.descr.PackageDescr in project drools by kiegroup.

the class DRLIncompleteCodeTest method testIncompleteCode5.

@Test
public void testIncompleteCode5() throws DroolsParserException, RecognitionException {
    String input = "package a.b.c import 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 2 with PackageDescr

use of org.drools.compiler.lang.descr.PackageDescr in project drools by kiegroup.

the class DRLIncompleteCodeTest method testIncompleteCode13.

@Test
public void testIncompleteCode13() throws DroolsParserException, RecognitionException {
    String input = "package com.sample " + "import com.sample.DroolsTest.Message; " + "rule \"Hello World\"" + "  when " + "  then" + "     \\\" " + "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 3 with PackageDescr

use of org.drools.compiler.lang.descr.PackageDescr in project drools by kiegroup.

the class DRLIncompleteCodeTest method testIncompleteCode2.

@Test
public void testIncompleteCode2() throws DroolsParserException, RecognitionException {
    String input = "rule MyRule when Class ( property memberOf collection ";
    DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
    PackageDescr descr = parser.parse(true, input);
    assertNotNull(descr);
    assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, getLastIntegerValue(parser.getEditorSentences().get(0).getContent()));
}
Also used : DrlParser(org.drools.compiler.compiler.DrlParser) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) Test(org.junit.Test)

Example 4 with PackageDescr

use of org.drools.compiler.lang.descr.PackageDescr in project drools by kiegroup.

the class DRLIncompleteCodeTest method testIncompleteCode8.

@Test
public void testIncompleteCode8() throws DroolsParserException, RecognitionException {
    String input = "package a.b.c import a.1111.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);
    System.out.println(parser.getErrors());
    assertEquals("a.b.c", descr.getNamespace());
    // FIXME: assertEquals(2, descr.getRules().size());
    assertEquals(true, parser.hasErrors());
}
Also used : DrlParser(org.drools.compiler.compiler.DrlParser) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) Test(org.junit.Test)

Example 5 with PackageDescr

use of org.drools.compiler.lang.descr.PackageDescr in project drools by kiegroup.

the class KnowledgeBuilderImpl method generatedResourcesToPackageDescr.

private List<PackageDescr> generatedResourcesToPackageDescr(Resource resource, List<PMMLResource> resources) throws DroolsParserException {
    List<PackageDescr> pkgDescrs = new ArrayList<>();
    DrlParser parser = new DrlParser(configuration.getLanguageLevel());
    for (PMMLResource res : resources) {
        for (String key : res.getRules().keySet()) {
            String src = res.getRules().get(key);
            PackageDescr descr = null;
            descr = parser.parse(false, src);
            if (descr != null) {
                descr.setResource(resource);
                pkgDescrs.add(descr);
                dumpGeneratedRule(descr, key, src);
            } else {
                addBuilderResult(new ParserError(resource, "Parser returned a null Package", 0, 0));
            }
        }
    }
    return pkgDescrs;
}
Also used : PMMLResource(org.drools.compiler.compiler.PMMLResource) ParserError(org.drools.compiler.compiler.ParserError) ArrayList(java.util.ArrayList) DrlParser(org.drools.compiler.compiler.DrlParser) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) CompositePackageDescr(org.drools.compiler.lang.descr.CompositePackageDescr)

Aggregations

PackageDescr (org.drools.compiler.lang.descr.PackageDescr)199 Test (org.junit.Test)178 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)100 PatternDescr (org.drools.compiler.lang.descr.PatternDescr)83 DrlParser (org.drools.compiler.compiler.DrlParser)36 AndDescr (org.drools.compiler.lang.descr.AndDescr)36 CompositeObjectSinkAdapterTest (org.drools.core.reteoo.CompositeObjectSinkAdapterTest)27 ExprConstraintDescr (org.drools.compiler.lang.descr.ExprConstraintDescr)23 InputStreamReader (java.io.InputStreamReader)22 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)21 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)17 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)17 Cheese (org.drools.compiler.Cheese)16 XmlPackageReader (org.drools.compiler.compiler.xml.XmlPackageReader)16 KiePackage (org.kie.api.definition.KiePackage)16 AccumulateDescr (org.drools.compiler.lang.descr.AccumulateDescr)15 DrlDumper (org.drools.compiler.lang.DrlDumper)14 KieSession (org.kie.api.runtime.KieSession)14 GlobalDescr (org.drools.compiler.lang.descr.GlobalDescr)13 List (java.util.List)12