ReportParser.g4 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. grammar ReportParser;
  2. import ReportLexer;
  3. entry : expression+ EOF;
  4. expression : exprComposite
  5. | ifExpr
  6. | caseExpr
  7. | returnExpr
  8. | variableAssign
  9. ;
  10. exprComposite : expr #singleExprComposite
  11. | ternaryExpr #ternaryExprComposite
  12. | LeftParen exprComposite RightParen #parenExprComposite
  13. | exprComposite Operator exprComposite #complexExprComposite
  14. ;
  15. ternaryExpr : ifCondition (join ifCondition)* '?' block ':' block ;
  16. caseExpr : 'case' '{' casePart (',' casePart)* '}' ;
  17. casePart : ifCondition (join ifCondition)* ':'? block ;
  18. ifExpr: ifPart elseIfPart* elsePart? ;
  19. ifPart : 'if' '(' ifCondition (join ifCondition)* ')' '{' block '}';
  20. elseIfPart : 'else' 'if' '(' ifCondition (join ifCondition)* ')' '{' block '}' ;
  21. elsePart : 'else' '{' block '}' ;
  22. block : exprBlock* returnExpr? ;
  23. exprBlock : variableAssign
  24. | ifExpr
  25. | caseExpr
  26. ;
  27. returnExpr : 'return'? expr ';'?;
  28. expr : item (Operator item)* ;
  29. ifCondition : expr OP expr ;
  30. variableAssign : 'var'? variable '=' item ';'?;
  31. item : unit (Operator unit)* #simpleJoin
  32. | LeftParen item RightParen #singleParenJoin
  33. | LeftParen item (Operator item)+ RightParen #parenJoin
  34. ;
  35. unit : dataset
  36. | function
  37. | set
  38. | cellPosition
  39. | relativeCell
  40. | currentCellValue
  41. | currentCellData
  42. | cell
  43. | variable
  44. | INTEGER
  45. | BOOLEAN
  46. | STRING
  47. | NUMBER
  48. | NULL
  49. ;
  50. variable : Identifier ;
  51. cellPosition : '&'Cell ;//表示单元格位置
  52. relativeCell : '$'Cell ; //表示当前引用对应的单元格的值
  53. currentCellValue : '#' ;//表示当前单元格值
  54. currentCellData : '#''.'property ;//表示取当前单元绑定对象的某个属性值
  55. cell : 'cell' ('.'property)? ;
  56. dataset : Identifier '.' aggregate '(' property? (',' conditions )? (',' ORDER)? ')';
  57. function : Identifier '(' functionParameter? ')' ;
  58. functionParameter : item (','? item)* ;
  59. set : simpleValue #simpleData
  60. | Cell #singleCell
  61. | Cell '['']'('{' conditions '}')? #wholeCell
  62. | Cell ':' Cell #cellPair
  63. | Cell '{' conditions '}' #singleCellCondition
  64. | Cell '[' cellCoordinate ']' #singleCellCoordinate
  65. | Cell '[' cellCoordinate ']' '{' conditions '}' #cellCoordinateCondition
  66. | set 'to' set #range
  67. ;
  68. cellCoordinate : coordinate (';' coordinate)? ;
  69. coordinate : cellIndicator (',' cellIndicator)* ;
  70. cellIndicator : Cell #relative
  71. | Cell ':' EXCLAMATION? INTEGER #absolute
  72. ;
  73. conditions : condition (join condition)* ;
  74. condition : Cell OP expr #cellNameExprCondition
  75. | property OP expr #propertyCondition
  76. | currentValue OP expr #currentValueCondition
  77. | expr OP expr #exprCondition
  78. ;
  79. property : Identifier
  80. | property '.' property
  81. ;
  82. currentValue : '@' ;
  83. simpleValue : INTEGER|NUMBER|STRING|BOOLEAN|NULL;
  84. join : AND | OR ;
  85. aggregate : Identifier;