Search in sources :

Example 1 with DroolsParserException

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()));
}
Also used : DRLParser(org.drools.drl.parser.lang.DRLParser) DroolsParserException(org.drools.drl.parser.DroolsParserException) RecognitionException(org.antlr.runtime.RecognitionException) Test(org.junit.Test)

Example 2 with DroolsParserException

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;
}
Also used : DescrBuildError(org.drools.compiler.compiler.DescrBuildError) ConstraintConnectiveDescr(org.drools.drl.ast.descr.ConstraintConnectiveDescr) DrlExprParser(org.drools.drl.parser.DrlExprParser) DroolsParserException(org.drools.drl.parser.DroolsParserException)

Example 3 with DroolsParserException

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);
}
Also used : StringWriter(java.io.StringWriter) DroolsParserException(org.drools.drl.parser.DroolsParserException) PrintWriter(java.io.PrintWriter)

Example 4 with DroolsParserException

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();
}
Also used : XmlPackageReader(org.drools.compiler.compiler.xml.XmlPackageReader) Reader(java.io.Reader) XmlChangeSetReader(org.drools.core.xml.XmlChangeSetReader) StringReader(java.io.StringReader) DroolsParserException(org.drools.drl.parser.DroolsParserException) XmlPackageReader(org.drools.compiler.compiler.xml.XmlPackageReader) SAXException(org.xml.sax.SAXException)

Example 5 with DroolsParserException

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;
}
Also used : ReaderResource(org.drools.core.io.impl.ReaderResource) DroolsParserException(org.drools.drl.parser.DroolsParserException) XmlPackageReader(org.drools.compiler.compiler.xml.XmlPackageReader) SAXException(org.xml.sax.SAXException)

Aggregations

DroolsParserException (org.drools.drl.parser.DroolsParserException)12 Test (org.junit.Test)6 DRLParser (org.drools.drl.parser.lang.DRLParser)5 RecognitionException (org.antlr.runtime.RecognitionException)4 ConstraintConnectiveDescr (org.drools.drl.ast.descr.ConstraintConnectiveDescr)3 DrlExprParser (org.drools.drl.parser.DrlExprParser)3 DescrBuildError (org.drools.compiler.compiler.DescrBuildError)2 XmlPackageReader (org.drools.compiler.compiler.xml.XmlPackageReader)2 SAXException (org.xml.sax.SAXException)2 PrintWriter (java.io.PrintWriter)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 ReaderResource (org.drools.core.io.impl.ReaderResource)1 Declaration (org.drools.core.rule.Declaration)1 QueryArgument (org.drools.core.rule.QueryArgument)1 XmlChangeSetReader (org.drools.core.xml.XmlChangeSetReader)1 PackageDescr (org.drools.drl.ast.descr.PackageDescr)1 PatternDescr (org.drools.drl.ast.descr.PatternDescr)1 RuleDescr (org.drools.drl.ast.descr.RuleDescr)1