Drools Syntax Diagrams

Wolfgang Laun
February 10, 2011

All rights reserved. . 2010.II c Wolfgang Laun.

package QualifiedName package com. The diagrams follow the usual conventions. A nonterminal.uni-freiburg. Some language constructs were omitted because they are deprecated or just alternative forms. Starting point is the first diagram. available from http://www. Compilation Unit CompilationUnit PackageHeader Definition PackageHeader .order. You can follow possible paths between these two points by following the arrows through the boxes. . for which there is another diagram. CompilationUnit.de/~thiemann/haskell/ebnf2ps/. is represented by a square box with yellow background while a terminal is represented by a round box and green background.1 Preface This is a comprehensive set of syntax diagrams for Drools 5. They were produced from an EBNF representation of the grammar using Peter Thiemann’s program Ebnf2ps. Each diagram has an entry point and an end point. There are no diagrams for several nonterminals. which may become deprecated as well.informatik.1. which operates on tokens assembled by the lexer. these follow the syntax as defined by the Java Language Specification: • StringLiteral • Identifier • Statement • Expression The DRL Parser Diagrams The diagrams in this section describe the syntactic units of the DRL parser.acme.

acme.order.println( "Hello!" ).calculate. function com.util.Math.out. com.order.2 Definition RuleAttribute ImportDefinition GlobalDefinition FunctionDefinition TypeDefinition RuleDefinition QueryDefinition Import and Global ImportDefinition function static * QualifiedName import import import import import . global DataType Identifier global Map ident2product.lang. static java. Parameters Block . Function Definition FunctionDefinition DataType function Identifier function sayHello(){ System.*.Position.PI.acme. GlobalDefinition . com.acme. .

String[] strings ){ /* . */ } Type Definition TypeDefinition Metadata declare Field Identifier end declare Message from : Address.3 } function int sqr( int a ){ return a*a. text : String. ] DataType [ Identifier ( ) function f( int i. end Metadata @ ( Tokens ( Expression ) Identifier @author( John Doe ) @validated Field = Identifier Metadata ) : DataType .. } Parameters .. state : MsgState.

INITIAL ) : State @modifyBy( "rules" ) Query Definition QueryDefinition Arguments Identifier ConditionalOr query . Argument ( ) Argument DataType ] [ Identifier query ’any Item’ $item : Item end query ’Triangles with side a’ ( Integer pa ) $t : Triangle( a == pa ) end Rule Definition RuleDefinition WhenPart Identifier Options rule StringLiteral ThenPart . end StringLiteral Arguments .4 name : String state = ( State.

end Rule Attributes RuleAttributes . attributes : RuleAttribute RuleAttributes . $goal1 : goal ) Path( start == $goal1. $goal2 ) ).5 Options Identifier extends StringLiteral Metadata WhenPart ConditionalOr : when ThenPart RhsStatement then . $goal2 : goal ) then insert( new Path( $start1. end rule "concatenate paths" when Path( $start1 : start.

handler == null ) $h : Handler( skills contains $skill. calendars StringLiteral rule "assign Handler to Task" agenda_group( "assignHandler" ) salience ( $prio ) when $t : Task( $prio : priority. $skill : skill. available == true ) then modify( $t ){ setHandler( $h ) } modify( $h ){ setAvailable( false ) } end Conditional Elements ConditionalOr or ConditionalAnd .6 RuleAttribute IntLiteral salience Expression ( ) BooleanLiteral enabled Expression ( auto–focus ) BooleanLiteral no–loop lock–on–active agenda–group activation–group date–effective StringLiteral date–expires dialect ruleflow–group timer ( Tokens ) .

end SourcePattern Expression collect ( SourcePattern from entry–point OverClause AccumulateClause Pattern OverClause . $data : data ) eval( $data.out.println( "Match!" ).7 ConditionalAnd and ConditionalElement ConditionalElement exists Pattern not ( eval ( Expression ( forall ConditionalOr ( ) . SourcePattern ConditionalOr ) ) ) SourcePattern rule "CE demo" when exists Fact( id == 1 ) not ( Other( key == "foo" ) or Other( key == "bar" ) ) Fact( id == 42.size() > 10 ) then System. over Identifier : Identifier ( Expression ) Identifier ) .

accumulate ( AccumulateSteps ConditionalOr ) AccumulateFunction AccumulateFunction . ) . and collectList. count() ) then System. ) AccumulateAction Statement action ( . maximum (or max). mininum (or min). Expression Identifier ( ) Predifined accumulate functions are sum.8 AccumulateClause . rule "Check item count" when $batch : Batch( $id : id ) $total : Number( intValue > 100 ) from accumulate( Item( batch == $batch ). ) AccumulateReverse Statement reverse ( .out. average (or avg). count. end AccumulateSteps AccumulateReverse AccumulateInit AccumulateAction AccumulateResult AccumulateInit Statement init ( .println( "too many Items in Batch " + $id ). collectSet.

println( "Names: " + $set.remove( $name ). end Pattern. ) reverse( nameSet.out. init( Set<String> nameSet = new TreeSet<String>( Collator. Identifier ConstraintOr : DataType ( $emp : Employee( trainings contains "Java" ) ConstraintOr || ConstraintAnd ConstraintAnd && ConstraintTerm Resort( rate <= 100 || seaside == true && rate <= 110 ) ConstraintTerm eval ( Expression FieldConstraint ( ConstraintOr ) ) ) . ) action( nameSet. ) result( nameSet ) ) then System.add( $name ). Constraint and Restrictions Pattern .getInstance() ).9 AccumulateResult result Expression ( ) rule "print sorted Element names" when $set: Set() from accumulate ( Element( $name: name ).toString() ).

and the .10 eval( $p1. soundslike. $maker : maker ) RestrictionOr || RestrictionAnd RestrictionAnd && RestrictionTerm RestrictionTerm SingleValueRestriction MultiValueRestriction ( RestrictionOr ) SingleValueRestriction == > >= < RestrictionExpression <= != not [ Expression ] Identifier Predefined operators are: contains. excludes.getY() == $p2.getX() == $p2.getX() || $p2. memberOf. matches.getY() ) FieldConstraint RestrictionOr Identifier AccessorPath : AccessorPath RestrictionOr Wine( grape == "Merlot".

11 Medication( dose <= 100 || >= 200 ) MultiValueRestriction .a. not in Expression ( ) Duck( name in ( "Huey". "Dewey". Identifier DataType ] QualifiedName [ . c < (2*a + b) ) RestrictionLiteral StringLiteral IntLiteral RealLiteral BooleanLiteral null Miscellaneous QualifiedName . "Louie" ) ) RestrictionExpression AccessorPath RestrictionLiteral Expression ( ) $t1 : Triangle() $t2 : Triangle( this != $t1. a == $t1. b < 10.

) from each other. . This means that its terminals may not be separated by any white space (space. tab.’F’ . newline. which assembles its nonterminals from individual characters. . IntLiteral + Digit – Digit 0x ’a’.... AccessorStep AccessorStep ] Expression [ Identifier Block Statement { } BracketedExpression Expression [ ] BooleanLiteral true false The DRL Lexer Diagrams The diagrams in this section describe the syntactic units of the lexer.12 AccessorPath .’f’ ’A’.

125 1e10 100f 2E-6D Template Files The syntax of Template files is line-oriente.. . . Digit Exponent + – e Digit E RealTypeSuffix f F d D 3.’9’ RealLiteral Exponent + Fraction – RealTypeSuffix Digit Exponent Digit RealTypeSuffix Fraction Digit Digit .14159 .13 Digit ’0’. nl is used to indicate where a newline is required.

14 TemplateFile nl Identifier HeaderText nl template header Template HeaderText PackageHeader nl nl TextLine Template nl Identifier nl template TextLine end template StringLiteral template header type test template match rule "match @{row. end end template nl .rowNumber}" when f: @{type}( @{test} ) then System.out.println( "Match for " + f.toString() ).

4 definition. 13 FunctionDefinition. 5 OverClause. 6–12 Field. 8 definition. 9 AccumulateReverse. 13 definition. 2 HeaderText. 3 Pattern. 13 Exponent. 2. 5 definition. 9 definition. 3 definition. 3. 7 definition. 10 definition. 8 AccumulateClause. 1 Parameters. 9 DataType. 3 MultiValueRestriction. 9 definition. 2 definition. 13 Expression.Index AccessorPath. 1 ConditionalAnd. 11 definition. 10. 8 AccumulateFunction. 8 definition. 8 definition. 7 ConditionalOr. 10 nl. 12 Block. 2 GlobalDefinition. 2 IntLiteral. 12 Definition. 8 AccumulateInit. 14 definition. 9 definition. 11 definition. 13 definition. 5. 14 Identifier. 4. 7 PackageHeader. 10 definition. 14 Options. 2 definition. 9 ConstraintTerm. 1. 2 definition. 2–4. 2–5. 10 definition. 1. 14 ImportDefinition. 8 AccumulateSteps. 7–12. 12 Metadata. 12. 7 definition. 10 Fraction. 7 definition. 3. 14 definition. 11 15 . 12 definition. 12 AccessorStep. 8 AccumulateResult. 3 FieldConstraint. 11 definition. 8 definition. 7 ConditionalElement. 5 definition. 8 definition. 4 definition. 12 BooleanLiteral. 9 ConstraintOr. 7. 4 Arguments. 11 CompilationUnit definition. 12 AccumulateAction. 2 definition. 12 definition. 8 definition. 1 QualifiedName. 9. 2 definition. 8 Argument. 6. 2 Digit. 4 definition. 6. 7 definition. 12 BracketedExpression definition. 13 definition. 7 definition. 8 definition. 7 ConstraintAnd.

7 definition. 11 RestrictionOr. 11 definition. 13 definition. 6 RuleAttributes. 6 TypeDefinition. 6 definition. 4 RealLiteral. 14 definition. 10 definition. 11 RestrictionLiteral. 10 definition. 5 SingleValueRestriction. 2 definition. 4–6. 10 definition. 3 WhenPart. 5 definition. 5 Tokens. 10 definition. 12 StringLiteral. 5 INDEX . 5 definition. 11 definition. 2 definition. 10 RestrictionExpression. 13 RealTypeSuffix. 5 RuleAttribute. 2. 2 definition. 11. 6 RuleDefinition. 7 Statement.16 QueryDefinition. 10 RestrictionTerm. 14 ThenPart. 10 definition. 14 Template. 14 TextLine. 10 RhsStatement. 13 RestrictionAnd. 5 definition. 3. 10 SourcePattern. 8. 14 TemplateFile definition.