use of org.drools.drl.parser.DrlParser in project drools by kiegroup.
the class DRLIncompleteCodeTest method testIncompleteCode6.
@Test
public void testIncompleteCode6() throws DroolsParserException, RecognitionException {
String input = "packe 1111.111 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);
}
use of org.drools.drl.parser.DrlParser in project drools by kiegroup.
the class DRLIncompleteCodeTest method testIncompleteCode1.
@Test
@Ignore
public void testIncompleteCode1() throws DroolsParserException, RecognitionException {
String input = "package a.b.c import a.b.c.* rule MyRule when Class ( property memberOf collexction ";
DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
PackageDescr descr = parser.parse(true, input);
System.out.println(parser.getErrors());
assertNotNull(descr);
assertEquals("a.b.c", descr.getNamespace());
assertEquals("a.b.c.*", descr.getImports().get(0).getTarget());
assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, getLastIntegerValue(parser.getEditorSentences().get(2).getContent()));
}
use of org.drools.drl.parser.DrlParser in project drools by kiegroup.
the class TestBaseOld method getTestData.
@SuppressWarnings("unchecked")
public Collection<? extends Object> getTestData(InputStream stream, VerifierData data) throws Exception {
Reader drlReader = new InputStreamReader(stream);
PackageDescr descr = new DrlParser(LanguageLevelOption.DRL5).parse(drlReader);
PackageDescrVisitor packageDescrVisitor = new PackageDescrVisitor(data, Collections.EMPTY_LIST);
packageDescrVisitor.visitPackageDescr(descr);
// Rules with relations
return data.getAll();
}
use of org.drools.drl.parser.DrlParser in project drools by kiegroup.
the class KnowledgeBuilderImpl method dslrReaderToPackageDescr.
private PackageDescr dslrReaderToPackageDescr(Resource resource, Reader dslrReader) throws DroolsParserException {
boolean hasErrors;
PackageDescr pkg;
DrlParser parser = new DrlParser(configuration.getLanguageLevel());
DefaultExpander expander = getDslExpander();
try {
try {
if (expander == null) {
expander = new DefaultExpander();
}
String str = expander.expand(dslrReader);
if (expander.hasErrors()) {
for (ExpanderException error : expander.getErrors()) {
error.setResource(resource);
addBuilderResult(error);
}
}
pkg = parser.parse(resource, str);
this.results.addAll(parser.getErrors());
hasErrors = parser.hasErrors();
} finally {
if (dslrReader != null) {
dslrReader.close();
}
}
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
return hasErrors ? null : pkg;
}
use of org.drools.drl.parser.DrlParser in project drools by kiegroup.
the class KnowledgeBuilderImpl method addPackageFromDrl.
/**
* Load a rule package from DRL source and associate all loaded artifacts
* with the given resource.
*
* @param reader
* @param sourceResource the source resource for the read artifacts
* @throws DroolsParserException
*/
public void addPackageFromDrl(final Reader reader, final Resource sourceResource) throws DroolsParserException, IOException {
this.resource = sourceResource;
final DrlParser parser = new DrlParser(configuration.getLanguageLevel());
final PackageDescr pkg = parser.parse(sourceResource, reader);
this.results.addAll(parser.getErrors());
if (pkg == null) {
addBuilderResult(new ParserError(sourceResource, "Parser returned a null Package", 0, 0));
}
if (!parser.hasErrors()) {
addPackage(pkg);
}
this.resource = null;
}
Aggregations