use of org.drools.drl.parser.DroolsParserException in project drools by kiegroup.
the class DRLContextTest method testCheckLHSLocationDetermination_BEGIN_OF_CONDITION1.
@Test(timeout = 10 * 1000)
public void testCheckLHSLocationDetermination_BEGIN_OF_CONDITION1() throws DroolsParserException, RecognitionException {
String input = "rule MyRule \n" + " when \n" + " ";
DRLParser parser = getParser(input);
parser.enableEditorInterface();
try {
parser.compilationUnit();
} catch (Exception ex) {
}
assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, getLastIntegerValue(parser.getEditorInterface().get(0).getContent()));
}
use of org.drools.drl.parser.DroolsParserException in project drools by kiegroup.
the class QueryElementBuilder method parseExpression.
private ConstraintConnectiveDescr parseExpression(final RuleBuildContext context, final PatternDescr patternDescr, final String expression) {
DrlExprParser parser = new DrlExprParser(context.getConfiguration().getLanguageLevel());
ConstraintConnectiveDescr result = parser.parse(expression);
if (result == null || parser.hasErrors()) {
for (DroolsParserException error : parser.getErrors()) {
context.addError(new DescrBuildError(context.getParentDescr(), patternDescr, null, "Unable to parser pattern expression:\n" + error.getMessage()));
}
return null;
}
return result;
}
use of org.drools.drl.parser.DroolsParserException in project drools by kiegroup.
the class DroolsParserExceptionFactory method createDroolsException.
public DroolsParserException createDroolsException(Exception e, Token token) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
return new DroolsParserException(String.format(DroolsParserExceptionFactory.UNEXPECTED_EXCEPTION, token.getLine(), token.getCharPositionInLine(), getBetterToken(token), e.toString(), sw.toString()), e);
}
use of org.drools.drl.parser.DroolsParserException in project drools by kiegroup.
the class KnowledgeBuilderImpl method xmlToPackageDescr.
PackageDescr xmlToPackageDescr(Resource resource) throws DroolsParserException, IOException {
final XmlPackageReader xmlReader = new XmlPackageReader(this.configuration.getSemanticModules());
xmlReader.getParser().setClassLoader(this.rootClassLoader);
try (Reader reader = resource.getReader()) {
xmlReader.read(reader);
} catch (final SAXException e) {
throw new DroolsParserException(e.toString(), e.getCause());
}
return xmlReader.getPackageDescr();
}
use of org.drools.drl.parser.DroolsParserException in project drools by kiegroup.
the class KnowledgeBuilderImpl method addPackageFromXml.
/**
* Load a rule package from XML source.
*
* @param reader
* @throws DroolsParserException
* @throws IOException
*/
public void addPackageFromXml(final Reader reader) throws DroolsParserException, IOException {
this.resource = new ReaderResource(reader, ResourceType.XDRL);
final XmlPackageReader xmlReader = new XmlPackageReader(this.configuration.getSemanticModules());
xmlReader.getParser().setClassLoader(this.rootClassLoader);
try {
xmlReader.read(reader);
} catch (final SAXException e) {
throw new DroolsParserException(e.toString(), e.getCause());
}
addPackage(xmlReader.getPackageDescr());
this.resource = null;
}
Aggregations