[jboss-jira] [JBoss JIRA] (DROOLS-889) Ambiguity with 'end' keyword and end() method in drl file

Mario Fusco (JIRA) issues at jboss.org
Wed Aug 19 14:00:28 EDT 2015


Mario Fusco created DROOLS-889:
----------------------------------

             Summary: Ambiguity with 'end' keyword and end() method in drl file
                 Key: DROOLS-889
                 URL: https://issues.jboss.org/browse/DROOLS-889
             Project: Drools
          Issue Type: Bug
            Reporter: Mario Fusco
            Assignee: Mario Fusco


Trying to invoke a method called end() in the RHS of a rule, as in the test case pasted below, causes a compilation failure because drools interprets it as the 'end' soft keyword that terminates the rule. 

{code}
    @Test
    public void testEndMethod() throws Exception {
        // DROOLS-889
        String drl =
                "import " + Pattern.class.getCanonicalName() + "\n" +
                "import " + Matcher.class.getCanonicalName() + "\n" +
                "global java.util.List list\n" +
                "rule \"Variable matches field\" when\n" +
                "    $emailAddress :String(this matches \"^.*[_A-Za-z0-9-\\\\+]+(\\\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\\\.[A-Za-z0-9]+)*(\\\\.[A-Za-z]{2,}).*$\")\n" +
                "then\n" +
                "    Pattern pattern=Pattern.compile(\"[_A-Za-z0-9-\\\\+]+(\\\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\\\.[A-Za-z0-9]+)*(\\\\.[A-Za-z]{2,})\");\n" +
                "    Matcher matcher=pattern.matcher($emailAddress);\n" +
                "    while(matcher.find()){\n" +
                "        list.add($emailAddress.substring(matcher.start(),matcher.end()));\n" +
                "    }\n" +
                "end\n";

        KieSession ksession = new KieHelper().addContent(drl, ResourceType.DRL)
                                             .build()
                                             .newKieSession();

        List<String> list = new ArrayList<String>();
        ksession.setGlobal( "list", list );

        ksession.insert( "mario.fusco at test.org" );
        ksession.fireAllRules();

        assertEquals( 1, list.size() );
        assertEquals( "mario.fusco at test.org", list.get(0) );
    }
{code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)


More information about the jboss-jira mailing list