Search in sources :

Example 96 with DRLParser

use of org.drools.drl.parser.lang.DRLParser in project drools by kiegroup.

the class DrlParser method parse.

public PackageDescr parse(final boolean isEditor, final Reader reader) throws DroolsParserException {
    lexer = DRLFactory.buildLexer(reader, languageLevel);
    DRLParser parser = DRLFactory.buildParser(lexer, languageLevel);
    return compile(isEditor, parser);
}
Also used : DRLParser(org.drools.drl.parser.lang.DRLParser)

Example 97 with DRLParser

use of org.drools.drl.parser.lang.DRLParser in project drools by kiegroup.

the class DrlParser method parse.

public PackageDescr parse(final boolean isEditor, final Resource resource, final InputStream is) throws DroolsParserException, IOException {
    this.resource = resource;
    String encoding = resource instanceof InternalResource ? ((InternalResource) resource).getEncoding() : null;
    lexer = DRLFactory.buildLexer(is, encoding, languageLevel);
    DRLParser parser = DRLFactory.buildParser(lexer, languageLevel);
    return compile(isEditor, parser);
}
Also used : InternalResource(org.drools.core.io.internal.InternalResource) DRLParser(org.drools.drl.parser.lang.DRLParser)

Example 98 with DRLParser

use of org.drools.drl.parser.lang.DRLParser in project drools by kiegroup.

the class DRLContextTest method testCheckLHSLocationDetermination_INSIDE_CONDITION_ARGUMENT.

@Test(timeout = 10 * 1000)
public void testCheckLHSLocationDetermination_INSIDE_CONDITION_ARGUMENT() {
    String input = "rule MyRule \n" + "	when \n" + "		Class ( property > 0 ) from accumulate( \n" + "			$cheese : Cheese( type == ";
    DRLParser parser = getParser(input);
    parser.enableEditorInterface();
    try {
        parser.compilationUnit();
    } catch (Exception ex) {
    }
    assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, 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 99 with DRLParser

use of org.drools.drl.parser.lang.DRLParser in project drools by kiegroup.

the class DRLContextTest method testCheckRuleHeaderLocationDetermination2.

@Test(timeout = 10 * 1000)
public void testCheckRuleHeaderLocationDetermination2() {
    String input = "rule MyRule \n" + "	salience 12 activation-group \"my";
    DRLParser parser = getParser(input);
    parser.enableEditorInterface();
    try {
        parser.compilationUnit();
    } catch (Exception ex) {
    }
    DroolsToken token = getLastTokenOnList(parser.getEditorInterface().get(0).getContent());
    assertEquals("group", token.getText().toLowerCase());
    assertEquals(DroolsEditorType.KEYWORD, token.getEditorType());
    assertEquals(Location.LOCATION_RULE_HEADER_KEYWORD, getLastIntegerValue(parser.getEditorInterface().get(0).getContent()));
}
Also used : DroolsToken(org.drools.drl.parser.lang.DroolsToken) DRLParser(org.drools.drl.parser.lang.DRLParser) DroolsParserException(org.drools.drl.parser.DroolsParserException) RecognitionException(org.antlr.runtime.RecognitionException) Test(org.junit.Test)

Example 100 with DRLParser

use of org.drools.drl.parser.lang.DRLParser in project drools by kiegroup.

the class DRLContextTest method testCheckLHSLocationDetermination_FROM6.

@Test(timeout = 10 * 1000)
public void testCheckLHSLocationDetermination_FROM6() {
    String input = "rule MyRule \n" + "	when \n" + "		ArrayList(size > 50) from accumulate( Person( disabled == \"yes\", income > 100000 ) from ";
    DRLParser parser = getParser(input);
    parser.enableEditorInterface();
    try {
        parser.compilationUnit();
    } catch (Exception ex) {
    }
    assertEquals(Location.LOCATION_LHS_FROM, 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)

Aggregations

DRLParser (org.drools.drl.parser.lang.DRLParser)200 Test (org.junit.Test)197 DroolsParserException (org.drools.drl.parser.DroolsParserException)187 RecognitionException (org.antlr.runtime.RecognitionException)186 DroolsToken (org.drools.drl.parser.lang.DroolsToken)6 Ignore (org.junit.Ignore)2 LinkedList (java.util.LinkedList)1 Token (org.antlr.runtime.Token)1 InternalResource (org.drools.core.io.internal.InternalResource)1 Expander (org.drools.drl.parser.lang.Expander)1 DefaultExpander (org.drools.drl.parser.lang.dsl.DefaultExpander)1