use of org.drools.compiler.lang.dsl.DSLTokenizedMappingFile in project drools by kiegroup.
the class DSLMappingFileTest method testParseFile.
@Test
public void testParseFile() {
try {
final Reader reader = new InputStreamReader(this.getClass().getResourceAsStream(this.filename));
this.file = new DSLTokenizedMappingFile();
final boolean parsingResult = this.file.parseAndLoad(reader);
reader.close();
assertTrue(this.file.getErrors().toString(), parsingResult);
assertTrue(this.file.getErrors().isEmpty());
assertEquals(31, this.file.getMapping().getEntries().size());
} catch (final IOException e) {
e.printStackTrace();
fail("Should not raise exception ");
}
}
use of org.drools.compiler.lang.dsl.DSLTokenizedMappingFile in project drools by kiegroup.
the class DSLMappingFileTest method testParseFileWithEscapes.
@Test
public void testParseFileWithEscapes() {
String file = "[then]TEST=System.out.println(\"DO_SOMETHING\");" + NL + "" + "[when]code {code1} occurs and sum of all digit not equal \\( {code2} \\+ {code3} \\)=AAAA( cd1 == {code1}, cd2 != ( {code2} + {code3} ))" + NL + "" + "[when]code {code1} occurs=BBBB" + NL + "";
try {
final Reader reader = new StringReader(file);
this.file = new DSLTokenizedMappingFile();
final boolean parsingResult = this.file.parseAndLoad(reader);
reader.close();
assertTrue(this.file.getErrors().toString(), parsingResult);
assertTrue(this.file.getErrors().isEmpty());
final String LHS = "code 1041 occurs and sum of all digit not equal ( 1034 + 1035 )";
final String rule = "rule \"x\"" + NL + "when" + NL + "" + LHS + "" + NL + "then" + NL + "TEST" + NL + "end";
DefaultExpander de = new DefaultExpander();
de.addDSLMapping(this.file.getMapping());
final String ruleAfterExpansion = de.expand(rule);
final String expected = "rule \"x\"" + NL + "when" + NL + "AAAA( cd1 == 1041, cd2 != ( 1034 + 1035 ))" + NL + "then" + NL + "System.out.println(\"DO_SOMETHING\");" + NL + "end";
assertEquals(expected, ruleAfterExpansion);
} catch (final IOException e) {
e.printStackTrace();
fail("Should not raise exception ");
}
}
use of org.drools.compiler.lang.dsl.DSLTokenizedMappingFile in project drools-wb by kiegroup.
the class GuidedRuleDslrFileIndexer method getDSLMappingFiles.
private List<DSLMappingFile> getDSLMappingFiles(final Path path) {
final List<DSLMappingFile> dsls = new ArrayList<DSLMappingFile>();
final org.uberfire.backend.vfs.Path vfsPath = Paths.convert(path);
final org.uberfire.backend.vfs.Path packagePath = moduleService.resolvePackage(vfsPath).getPackageMainResourcesPath();
final Path nioPackagePath = Paths.convert(packagePath);
final Collection<Path> dslPaths = fileDiscoveryService.discoverFiles(nioPackagePath, FILTER_DSLS);
for (final Path dslPath : dslPaths) {
final String dslDefinition = ioService.readAllString(dslPath);
final DSLTokenizedMappingFile dslFile = new DSLTokenizedMappingFile();
try {
if (dslFile.parseAndLoad(new StringReader(dslDefinition))) {
dsls.add(dslFile);
} else {
logger.error("Unable to parse DSL definition: " + dslDefinition);
}
} catch (IOException ioe) {
logger.error(ioe.getMessage());
}
}
return dsls;
}
use of org.drools.compiler.lang.dsl.DSLTokenizedMappingFile in project drools-wb by kiegroup.
the class DslrFileIndexer method getDSLMappingFiles.
private List<DSLMappingFile> getDSLMappingFiles(final Path path) {
final List<DSLMappingFile> dsls = new ArrayList<DSLMappingFile>();
final org.uberfire.backend.vfs.Path vfsPath = Paths.convert(path);
final org.uberfire.backend.vfs.Path packagePath = moduleService.resolvePackage(vfsPath).getPackageMainResourcesPath();
final org.uberfire.java.nio.file.Path nioPackagePath = Paths.convert(packagePath);
final Collection<Path> dslPaths = fileDiscoveryService.discoverFiles(nioPackagePath, FILTER_DSLS);
for (final org.uberfire.java.nio.file.Path dslPath : dslPaths) {
final String dslDefinition = ioService.readAllString(dslPath);
final DSLTokenizedMappingFile dslFile = new DSLTokenizedMappingFile();
try {
if (dslFile.parseAndLoad(new StringReader(dslDefinition))) {
dsls.add(dslFile);
} else {
logger.error("Unable to parse DSL definition: " + dslDefinition);
}
} catch (IOException ioe) {
logger.error(ioe.getMessage());
}
}
return dsls;
}
use of org.drools.compiler.lang.dsl.DSLTokenizedMappingFile in project drools-wb by kiegroup.
the class DslFileIndexer method fillIndexBuilder.
@Override
public DefaultIndexBuilder fillIndexBuilder(final Path path) throws Exception {
final List<String> lhs = new ArrayList<String>();
final List<String> rhs = new ArrayList<String>();
final String dsl = ioService.readAllString(path);
// Construct a dummy DRL file to parse index elements
final DSLTokenizedMappingFile dslLoader = new DSLTokenizedMappingFile();
if (dslLoader.parseAndLoad(new StringReader(dsl))) {
DSLMapping dslMapping = dslLoader.getMapping();
for (DSLMappingEntry e : dslMapping.getEntries()) {
switch(e.getSection()) {
case CONDITION:
lhs.add(e.getValuePattern());
break;
case CONSEQUENCE:
rhs.add(e.getValuePattern());
break;
default:
}
}
final String drl = makeDrl(path, lhs, rhs);
return fillDrlIndexBuilder(path, drl);
}
return null;
}
Aggregations