RuleParser.g4 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. grammar RuleParser;
  2. import RuleLexer;
  3. ruleSet : ruleSetHeader
  4. ruleSetBody
  5. ;
  6. ruleSetHeader : resource*
  7. | functionImport*
  8. | resource* functionImport*
  9. | functionImport* resource*
  10. ;
  11. ruleSetBody : rules* ;
  12. rules : ruleDef | loopRuleDef ;
  13. functionImport : 'import' packageDef';'?;
  14. packageDef : Identifier
  15. | Identifier('.'Identifier)+
  16. | packageDef'.*';
  17. resource : importVariableLibrary
  18. | importActionLibrary
  19. | importConstantLibrary
  20. | importParameterLibrary
  21. ;
  22. importParameterLibrary : 'importParameterLibrary' STRING ';'?;
  23. importVariableLibrary : 'importVariableLibrary' STRING ';'?;
  24. importConstantLibrary : 'importConstantLibrary' STRING ';'?;
  25. importActionLibrary : 'importActionLibrary' STRING ';'?;
  26. functionDef : 'function' Identifier '(' functionParameters? ')' '{' expressionBody '}'';'?;
  27. functionParameters : functionParameter (','functionParameter)* ;
  28. functionParameter : Datatype Identifier ;
  29. ruleDef : ('rule'|'\u89c4\u5219') STRING
  30. attribute*
  31. left
  32. right
  33. other?
  34. ('end'|'\u7ed3\u675f') ';'?
  35. ;
  36. loopRuleDef : ('loopRule' | '\u5faa\u73af\u89c4\u5219') STRING
  37. attribute*
  38. loopTarget
  39. loopStart?
  40. left
  41. right
  42. other?
  43. loopEnd?
  44. ('end'|'\u7ed3\u675f') ';'?
  45. ;
  46. loopTarget : ('loopTarget' | '\u5faa\u73af\u5bf9\u8c61') complexValue ;
  47. loopStart : ('loopStart' | '\u5f00\u59cb\u524d\u52a8\u4f5c') action* ;
  48. loopEnd : ('loopEnd' | '\u7ed3\u675f\u540e\u52a8\u4f5c') action*;
  49. attribute :loopAttribute
  50. | salienceAttribute
  51. | effectiveDateAttribute
  52. | expiresDateAttribute
  53. | enabledAttribute
  54. | activationGroupAttribute
  55. | agendaGroupAttribute
  56. | autoFocusAttribute
  57. | ruleflowGroupAttribute
  58. ;
  59. loopAttribute : ('loop' | '\u5141\u8bb8\u5faa\u73af\u89e6\u53d1') '=' Boolean ','?;
  60. salienceAttribute : ('salience' | '\u4f18\u5148\u7ea7') '=' NUMBER ','?;
  61. effectiveDateAttribute : ('effective-date' | '\u751f\u6548\u65f6\u95f4' | '\u751f\u6548\u65e5\u671f') '=' STRING ','?;
  62. expiresDateAttribute : ('expires-date' | '\u5931\u6548\u65f6\u95f4' | '\u5931\u6548\u65e5\u671f') '=' STRING ','?;
  63. enabledAttribute : ('enabled' | '\u6fc0\u6d3b' | '\u542f\u7528') '=' Boolean ','?;
  64. activationGroupAttribute : ('activation-group' | '\u6fc0\u6d3b\u7ec4') '=' STRING ','? ;
  65. agendaGroupAttribute : ('agenda-group' | '\u8bae\u7a0b\u7ec4') '=' STRING ','? ;
  66. autoFocusAttribute : ('auto-focus' | '\u81ea\u52a8\u83b7\u53d6\u7126\u70b9') '=' Boolean ','?;
  67. ruleflowGroupAttribute : ('ruleflow-group' | '\u89c4\u5219\u6d41\u7ec4') '=' STRING ','?;
  68. left :
  69. ('if'|'\u5982\u679c')
  70. condition?
  71. ;
  72. condition : leftParen condition rightParen #parenConditions
  73. | condition (join condition)+ #multiConditions
  74. | conditionLeft op (complexValue|nullValue) #singleCondition
  75. | namedConditionSet #singleNamedConditionSet
  76. ;
  77. namedConditionSet : (refName colon)? refObject leftParen namedCondition rightParen;
  78. namedCondition : leftParen namedCondition rightParen #parenNamedConditions
  79. | namedCondition (join namedCondition)+ #multiNamedConditions
  80. | property op (complexValue|nullValue) #singleNamedConditions
  81. ;
  82. decisionTableCellCondition : op (complexValue|nullValue) #singleCellCondition
  83. | decisionTableCellCondition (join decisionTableCellCondition)+ #multiCellConditions
  84. | leftParen decisionTableCellCondition rightParen #parenCellConditions
  85. ;
  86. refName : Identifier ;
  87. refObject : variableCategory | parameterName ;
  88. nullValue : 'null';
  89. conditionLeft : (variable|parameter|functionInvoke|methodInvoke|expEval|expAll|expExists|expCollect|commonFunction) (ARITH value)* ;
  90. expEval : 'eval'leftParen expressionBody rightParen;
  91. expAll : 'all'leftParen
  92. (variable|parameter)
  93. ',' exprCondition
  94. (',' (NUMBER|percent))?
  95. rightParen;
  96. expExists : 'exist'leftParen
  97. (variable|parameter)
  98. ',' exprCondition
  99. (',' (NUMBER|percent))?
  100. rightParen;
  101. expCollect : 'collect'leftParen
  102. (variable|parameter)
  103. (',' exprCondition)?
  104. rightParen
  105. '.'
  106. ( COUNT | property'.'(SUM|AVG|MAX|MIN))
  107. ;
  108. commonFunction : Identifier leftParen complexValue(','property)? rightParen ;
  109. exprCondition : property op (complexValue|nullValue)
  110. | exprCondition (join exprCondition)+
  111. ;
  112. expressionBody : .*? ;
  113. percent : NUMBER'%';
  114. leftParen : '(';
  115. rightParen : ')';
  116. colon : ':';
  117. join :
  118. AND
  119. | OR
  120. ;
  121. right : ('then'|'\u90a3\u4e48')
  122. action*
  123. ;
  124. other : ('else'|'\u5426\u5219')
  125. action*
  126. ;
  127. actions : action*;
  128. action : assignAction ';'?
  129. | outAction ';'?
  130. | methodInvoke ';'?
  131. | functionInvoke ';'?
  132. | commonFunction ';'?
  133. ;
  134. assignAction : (variable|namedVariable|parameter) '=' complexValue;
  135. outAction : 'out''(' complexValue ')';
  136. methodInvoke : beanMethod'('actionParameters?')';
  137. functionInvoke : '@'Identifier'(' actionParameters? ')';
  138. actionParameters : complexValue (',' complexValue)* ;
  139. beanMethod : Identifier'.'Identifier ;
  140. complexValue : value
  141. | variable
  142. | namedVariable
  143. | constant
  144. | variableCategory
  145. | parameter
  146. | methodInvoke
  147. | functionInvoke
  148. | commonFunction
  149. | leftParen complexValue rightParen
  150. | complexValue (ARITH complexValue)+
  151. ;
  152. parameter : parameterName'.'Identifier;
  153. parameterName : 'parameter'|'\u53c2\u6570' ;
  154. constant : constantCategory'.'property;
  155. variable : variableCategory'.'property;
  156. namedVariable : namedVariableCategory'.'property;
  157. property : Identifier('.'Identifier)*;
  158. variableCategory : Identifier;
  159. namedVariableCategory : '!'Identifier;
  160. constantCategory : '$'Identifier;
  161. value :
  162. STRING
  163. | NUMBER
  164. | Boolean
  165. ;
  166. op
  167. :
  168. GreaterThen
  169. | GreaterThenOrEquals
  170. | LessThen
  171. | LessThenOrEquals
  172. | Equals
  173. | NotEquals
  174. | EndWith
  175. | NotEndWith
  176. | StartWith
  177. | NotStartWith
  178. | In
  179. | NotIn
  180. | Match
  181. | NotMatch
  182. | EqualsIgnoreCase
  183. | NotEqualsIgnoreCase
  184. ;