RuleParser.g4 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. | debugAttribute
  55. | activationGroupAttribute
  56. | agendaGroupAttribute
  57. | autoFocusAttribute
  58. | ruleflowGroupAttribute
  59. ;
  60. loopAttribute : ('loop' | '\u5141\u8bb8\u5faa\u73af\u89e6\u53d1') '=' Boolean ','?;
  61. salienceAttribute : ('salience' | '\u4f18\u5148\u7ea7') '=' NUMBER ','?;
  62. effectiveDateAttribute : ('effective-date' | '\u751f\u6548\u65f6\u95f4' | '\u751f\u6548\u65e5\u671f') '=' STRING ','?;
  63. expiresDateAttribute : ('expires-date' | '\u5931\u6548\u65f6\u95f4' | '\u5931\u6548\u65e5\u671f') '=' STRING ','?;
  64. enabledAttribute : ('enabled' | '\u6fc0\u6d3b' | '\u542f\u7528') '=' Boolean ','?;
  65. debugAttribute : ('debug' | '\u8c03\u8bd5' | '\u5141\u8bb8\u8c03\u8bd5') '=' Boolean ','?;
  66. activationGroupAttribute : ('activation-group' | '\u6fc0\u6d3b\u7ec4') '=' STRING ','? ;
  67. agendaGroupAttribute : ('agenda-group' | '\u8bae\u7a0b\u7ec4') '=' STRING ','? ;
  68. autoFocusAttribute : ('auto-focus' | '\u81ea\u52a8\u83b7\u53d6\u7126\u70b9') '=' Boolean ','?;
  69. ruleflowGroupAttribute : ('ruleflow-group' | '\u89c4\u5219\u6d41\u7ec4') '=' STRING ','?;
  70. left :
  71. ('if'|'\u5982\u679c')
  72. condition?
  73. ;
  74. condition : leftParen condition rightParen #parenConditions
  75. | condition (join condition)+ #multiConditions
  76. | conditionLeft op (complexValue|nullValue) #singleCondition
  77. | namedConditionSet #singleNamedConditionSet
  78. ;
  79. namedConditionSet : (refName colon)? refObject leftParen namedCondition rightParen;
  80. namedCondition : leftParen namedCondition rightParen #parenNamedConditions
  81. | namedCondition (join namedCondition)+ #multiNamedConditions
  82. | property op (complexValue|nullValue) #singleNamedConditions
  83. ;
  84. decisionTableCellCondition : op (complexValue|nullValue) #singleCellCondition
  85. | decisionTableCellCondition (join decisionTableCellCondition)+ #multiCellConditions
  86. | leftParen decisionTableCellCondition rightParen #parenCellConditions
  87. ;
  88. refName : Identifier ;
  89. refObject : variableCategory | parameterName ;
  90. nullValue : 'null';
  91. conditionLeft : (variable|parameter|functionInvoke|methodInvoke|expEval|expAll|expExists|expCollect|commonFunction) (ARITH value)* ;
  92. expEval : 'eval'leftParen expressionBody rightParen;
  93. expAll : 'all'leftParen
  94. (variable|parameter)
  95. ',' exprCondition
  96. (',' (NUMBER|percent))?
  97. rightParen;
  98. expExists : 'exist'leftParen
  99. (variable|parameter)
  100. ',' exprCondition
  101. (',' (NUMBER|percent))?
  102. rightParen;
  103. expCollect : 'collect'leftParen
  104. (variable|parameter)
  105. (',' exprCondition)?
  106. rightParen
  107. '.'
  108. ( COUNT | property'.'(SUM|AVG|MAX|MIN))
  109. ;
  110. commonFunction : Identifier leftParen complexValue(','property)? rightParen ;
  111. exprCondition : property op (complexValue|nullValue)
  112. | exprCondition (join exprCondition)+
  113. ;
  114. expressionBody : .*? ;
  115. percent : NUMBER'%';
  116. leftParen : '(';
  117. rightParen : ')';
  118. colon : ':';
  119. join :
  120. AND
  121. | OR
  122. ;
  123. right : ('then'|'\u90a3\u4e48')
  124. action*
  125. ;
  126. other : ('else'|'\u5426\u5219')
  127. action*
  128. ;
  129. actions : action*;
  130. action : assignAction ';'?
  131. | outAction ';'?
  132. | methodInvoke ';'?
  133. | functionInvoke ';'?
  134. | commonFunction ';'?
  135. ;
  136. assignAction : (variable|namedVariable|parameter) '=' complexValue;
  137. outAction : 'out''(' complexValue ')';
  138. methodInvoke : beanMethod'('actionParameters?')';
  139. functionInvoke : '@'Identifier'(' actionParameters? ')';
  140. actionParameters : complexValue (',' complexValue)* ;
  141. beanMethod : Identifier'.'Identifier ;
  142. complexValue : value
  143. | variable
  144. | namedVariable
  145. | constant
  146. | variableCategory
  147. | parameter
  148. | methodInvoke
  149. | functionInvoke
  150. | commonFunction
  151. | leftParen complexValue rightParen
  152. | complexValue (ARITH complexValue)+
  153. ;
  154. parameter : parameterName'.'Identifier;
  155. parameterName : 'parameter'|'\u53c2\u6570' ;
  156. constant : constantCategory'.'property;
  157. variable : variableCategory'.'property;
  158. namedVariable : namedVariableCategory'.'property;
  159. property : Identifier('.'Identifier)*;
  160. variableCategory : Identifier;
  161. namedVariableCategory : '!'Identifier;
  162. constantCategory : '$'Identifier;
  163. value :
  164. STRING
  165. | NUMBER
  166. | Boolean
  167. ;
  168. op
  169. :
  170. GreaterThen
  171. | GreaterThenOrEquals
  172. | LessThen
  173. | LessThenOrEquals
  174. | Equals
  175. | NotEquals
  176. | EndWith
  177. | NotEndWith
  178. | StartWith
  179. | NotStartWith
  180. | In
  181. | NotIn
  182. | Match
  183. | NotMatch
  184. | EqualsIgnoreCase
  185. | NotEqualsIgnoreCase
  186. | Contain
  187. | NotContain
  188. ;