Package org.drools.compiler.lang.dsl

Examples of org.drools.compiler.lang.dsl.DefaultExpander


    /**
     * Returns an expander for DSLs (only if there is a DSL configured for this package).
     */
    public Expander getDSLExpander( final Path path ) {
        final Expander expander = new DefaultExpander();
        final List<DSLMappingFile> dsls = getDSLMappingFiles( path );
        for ( DSLMappingFile dsl : dsls ) {
            expander.addDSLMapping( dsl.getMapping() );
        }
        return expander;
    }
View Full Code Here


    @Test
    public void testExpandWithDots() throws IOException {
        DSLMappingEntry entry1 = this.createEntry( "- {prop} is not {val} ", "{prop} != {val}" );
        DSLMappingEntry entry2 = this.createEntry( "- {prop} is {val} ",     "{prop} == {val}" );
        DSLMappingEntry entry3 = this.createEntry( "- {prop} is_not {val} ", "{prop} != {val}" );
        DefaultExpander ex = makeExpander( entry1, entry2, entry3 );
        StringBuilder sb = new StringBuilder( "rule x\n" ).append( "when\n" );
        sb.append( "> Foo()").append( NL );
        sb.append( "- type1 is ClientServiceType.TypeGOLD" ).append( NL );
        sb.append( "- type2 is_not ClientServiceType.TypeGOLD" ).append( NL );
        sb.append( "- type3 is not ClientServiceType.TypeGOLD" ).append( NL );
        sb.append( "then\n" ).append( "end\n" );
        String dslr = sb.toString();
        String drl = ex.expand( dslr );
        System.out.println( dslr );
        System.out.println( drl );
        assertTrue( "failure type1", drl.contains( "type1 == ClientServiceType.TypeGOLD" ) );
        assertTrue( "failure type2", drl.contains( "type2 != ClientServiceType.TypeGOLD" ) );
        assertTrue( "failure type3", drl.contains( "type3 != ClientServiceType.TypeGOLD" ) );
View Full Code Here

        assertEquals( lookbehind  + "Bedingung-#19-MKM4(?=\\W|$)",
                      entry7.getKeyPattern().toString() );
        assertEquals( "eval ( $p.getTempVal(\"#UML-ATZ-1\") < $p.getZvUmlStfr() )",
                       entry7.getValuePattern());
 
        DefaultExpander ex = makeExpander( entry1, entry2, entry3, entry4,
                                           entry5, entry6, entry7 );
        StringBuilder sb = new StringBuilder( "rule x\n" ).append( "when\n" );
       
        sb.append( "attr name is in [ 'Edson', 'Bob' ]" ).append( NL );
        sb.append( "he (is) a $xx handsome man" ).append( NL );
        sb.append( "DSL sentence with mykey myvalue" ).append( NL );
        sb.append( "When the credit rating is AA" ).append( NL );
        sb.append( "When the credit rating is 555" ).append( NL );
        sb.append( "This is a sentence with line breaks" ).append( NL );
        sb.append( "Bedingung-#19-MKM4" ).append( NL );
        sb.append( "then\n" + "end\n" );
        String dslr = sb.toString();
        String drl = ex.expand( dslr );

        for( String exp: new String[]{
                "name in ( 'Edson', 'Bob' )",
                "Person( attribute == \"handsome\" )",
                "Sentence( mykey == myvalue )",
View Full Code Here

            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 );
           
View Full Code Here

                          entry.getMappingValue() );
           
            String input = "rule x" + NL + "when" + NL + "then" + NL + "Add surcharge 300 to Policy" + NL + "end" + NL + "";
            String expected = "rule x" + NL + "when" + NL + "then" + NL + "modify(policy) {price = 300}" + NL + "end" + NL + "";
           
            DefaultExpander de = new DefaultExpander();
            de.addDSLMapping( this.file.getMapping() );

            final String result = de.expand( input );
           
//            String result = entry.getKeyPattern().matcher( input ).replaceAll( entry.getValuePattern() );
           
            assertEquals( expected,
                          result );
View Full Code Here

            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 + "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 + "end";

            assertEquals( expected,
                          ruleAfterExpansion );
View Full Code Here

            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 );
View Full Code Here

        return createEntry( inputKey,
                            inputValue );
    }
       
    private DefaultExpander makeExpander( DSLMappingEntry... entries ){
        DefaultExpander expander = new DefaultExpander();
        DefaultDSLMapping mapping = new DefaultDSLMapping();
        for( DSLMappingEntry entry: entries ){
            mapping.addEntry( entry );
        }
        List<String> options = new ArrayList<String>();
        options.add("result");
        options.add("when");
        options.add("steps");
        mapping.setOptions(options);
        expander.addDSLMapping(mapping);
        return expander;
    }
View Full Code Here

   

    @Test
    public void testExpandSpaces() throws IOException {
        DSLMappingEntry entry = this.setupEntry();
        DefaultExpander ex = makeExpander( entry );
        String[] strs = new String[]{ "0_sp", " 1_sp", "   3_sp", "0_sp_1 ",
                                      "0_sp_3   ", "0_sp 1_sp 2_sp", "   3_sp   3_sp 1_sp 1_sp_2  " };
        StringBuilder sb = new StringBuilder( "rule x\n" + "when\n" );
        for( String str: strs ){
            sb.append( "String is \"" + str + "\"" + NL );
        }
        sb.append( "then\n" + "end\n" );
        String dslr = sb.toString();
        String drl = ex.expand( dslr );
       
        for( String str: strs ){
            assertTrue( drl.contains( '"' + str + '"' ) );
        }
    }
View Full Code Here

        DefaultExpanderResolver resolver = new DefaultExpanderResolver(new StringReader(dsl));
       
       
        final DSLMappingFile file = new DSLTokenizedMappingFile();
        if ( file.parseAndLoad( new StringReader(dsl) ) ) {
            final Expander expander = new DefaultExpander();
            expander.addDSLMapping( file.getMapping() );
            resolver.addExpander("*", expander);
        } else {
            throw new RuntimeException( "Error parsing and loading DSL file." + file.getErrors() );
        }

View Full Code Here

TOP

Related Classes of org.drools.compiler.lang.dsl.DefaultExpander

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.