expressir 0.2.1 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (560) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/rake.yml +46 -0
  3. data/.github/workflows/release.yml +75 -0
  4. data/.gitignore +15 -15
  5. data/.gitmodules +3 -0
  6. data/.rspec +2 -2
  7. data/.rubocop.yml +508 -508
  8. data/Gemfile +6 -4
  9. data/README.adoc +147 -147
  10. data/Rakefile +25 -6
  11. data/bin/console +12 -12
  12. data/bin/rspec +29 -29
  13. data/bin/setup +8 -8
  14. data/demo.rb +18 -18
  15. data/docs/development.md +90 -90
  16. data/exe/expressir +20 -20
  17. data/exe/generate-parser +48 -0
  18. data/expressir.gemspec +42 -36
  19. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/CMakeLists.txt +118 -0
  20. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2013.vcxproj +637 -0
  21. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2013.vcxproj.filters +984 -0
  22. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2015.vcxproj +652 -0
  23. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2015.vcxproj.filters +990 -0
  24. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2017.vcxproj +652 -0
  25. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2017.vcxproj.filters +990 -0
  26. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2019.vcxproj +652 -0
  27. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2019.vcxproj.filters +990 -0
  28. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlrcpp-ios/Info.plist +26 -0
  29. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlrcpp-ios/antlrcpp_ios.h +17 -0
  30. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlrcpp.xcodeproj/project.pbxproj +3024 -0
  31. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlrcpp.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  32. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlrcpp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  33. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlrcpp.xcodeproj/xcshareddata/xcschemes/antlr4.xcscheme +76 -0
  34. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlrcpp.xcodeproj/xcshareddata/xcschemes/antlr4_ios.xcscheme +80 -0
  35. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlrcpp.xcodeproj/xcshareddata/xcschemes/antlr4_static.xcscheme +80 -0
  36. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRErrorListener.cpp +10 -0
  37. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRErrorListener.h +167 -0
  38. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRErrorStrategy.cpp +10 -0
  39. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRErrorStrategy.h +121 -0
  40. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRFileStream.cpp +34 -0
  41. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRFileStream.h +27 -0
  42. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRInputStream.cpp +155 -0
  43. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRInputStream.h +69 -0
  44. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/BailErrorStrategy.cpp +61 -0
  45. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/BailErrorStrategy.h +59 -0
  46. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/BaseErrorListener.cpp +25 -0
  47. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/BaseErrorListener.h +36 -0
  48. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/BufferedTokenStream.cpp +414 -0
  49. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/BufferedTokenStream.h +200 -0
  50. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/CharStream.cpp +11 -0
  51. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/CharStream.h +37 -0
  52. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonToken.cpp +195 -0
  53. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonToken.h +158 -0
  54. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonTokenFactory.cpp +39 -0
  55. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonTokenFactory.h +74 -0
  56. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonTokenStream.cpp +78 -0
  57. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonTokenStream.h +79 -0
  58. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ConsoleErrorListener.cpp +15 -0
  59. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ConsoleErrorListener.h +35 -0
  60. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/DefaultErrorStrategy.cpp +333 -0
  61. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/DefaultErrorStrategy.h +466 -0
  62. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/DiagnosticErrorListener.cpp +84 -0
  63. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/DiagnosticErrorListener.h +80 -0
  64. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Exceptions.cpp +64 -0
  65. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Exceptions.h +99 -0
  66. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/FailedPredicateException.cpp +51 -0
  67. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/FailedPredicateException.h +32 -0
  68. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/InputMismatchException.cpp +18 -0
  69. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/InputMismatchException.h +24 -0
  70. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/IntStream.cpp +12 -0
  71. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/IntStream.h +218 -0
  72. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/InterpreterRuleContext.cpp +19 -0
  73. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/InterpreterRuleContext.h +45 -0
  74. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Lexer.cpp +295 -0
  75. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Lexer.h +196 -0
  76. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerInterpreter.cpp +75 -0
  77. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerInterpreter.h +52 -0
  78. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerNoViableAltException.cpp +36 -0
  79. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerNoViableAltException.h +31 -0
  80. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ListTokenSource.cpp +92 -0
  81. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ListTokenSource.h +88 -0
  82. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/NoViableAltException.cpp +46 -0
  83. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/NoViableAltException.h +42 -0
  84. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Parser.cpp +648 -0
  85. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Parser.h +467 -0
  86. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserInterpreter.cpp +306 -0
  87. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserInterpreter.h +179 -0
  88. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserRuleContext.cpp +141 -0
  89. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserRuleContext.h +147 -0
  90. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ProxyErrorListener.cpp +53 -0
  91. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ProxyErrorListener.h +38 -0
  92. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RecognitionException.cpp +66 -0
  93. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RecognitionException.h +98 -0
  94. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Recognizer.cpp +167 -0
  95. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Recognizer.h +164 -0
  96. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContext.cpp +143 -0
  97. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContext.h +137 -0
  98. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContextWithAltNum.cpp +27 -0
  99. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContextWithAltNum.h +32 -0
  100. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuntimeMetaData.cpp +53 -0
  101. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuntimeMetaData.h +155 -0
  102. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Token.cpp +9 -0
  103. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Token.h +92 -0
  104. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenFactory.h +30 -0
  105. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenSource.cpp +9 -0
  106. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenSource.h +85 -0
  107. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStream.cpp +11 -0
  108. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStream.h +137 -0
  109. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStreamRewriter.cpp +425 -0
  110. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStreamRewriter.h +293 -0
  111. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedCharStream.cpp +211 -0
  112. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedCharStream.h +123 -0
  113. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedTokenStream.cpp +270 -0
  114. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedTokenStream.h +115 -0
  115. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Vocabulary.cpp +104 -0
  116. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Vocabulary.h +193 -0
  117. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/WritableToken.cpp +9 -0
  118. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/WritableToken.h +23 -0
  119. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/antlr4-common.h +137 -0
  120. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/antlr4-runtime.h +167 -0
  121. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATN.cpp +209 -0
  122. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATN.h +112 -0
  123. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfig.cpp +113 -0
  124. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfig.h +148 -0
  125. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfigSet.cpp +228 -0
  126. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfigSet.h +110 -0
  127. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.cpp +64 -0
  128. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.h +50 -0
  129. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializer.cpp +758 -0
  130. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializer.h +85 -0
  131. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSerializer.cpp +621 -0
  132. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSerializer.h +61 -0
  133. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSimulator.cpp +63 -0
  134. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSimulator.h +87 -0
  135. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNState.cpp +72 -0
  136. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNState.h +133 -0
  137. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNType.h +20 -0
  138. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AbstractPredicateTransition.cpp +14 -0
  139. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AbstractPredicateTransition.h +24 -0
  140. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ActionTransition.cpp +33 -0
  141. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ActionTransition.h +33 -0
  142. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AmbiguityInfo.cpp +16 -0
  143. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AmbiguityInfo.h +68 -0
  144. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.cpp +82 -0
  145. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.h +43 -0
  146. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AtomTransition.cpp +31 -0
  147. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AtomTransition.h +30 -0
  148. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicBlockStartState.cpp +12 -0
  149. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicBlockStartState.h +22 -0
  150. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicState.cpp +12 -0
  151. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicState.h +21 -0
  152. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockEndState.cpp +15 -0
  153. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockEndState.h +24 -0
  154. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockStartState.cpp +9 -0
  155. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockStartState.h +21 -0
  156. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ContextSensitivityInfo.cpp +14 -0
  157. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ContextSensitivityInfo.h +47 -0
  158. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionEventInfo.cpp +14 -0
  159. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionEventInfo.h +70 -0
  160. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionInfo.cpp +25 -0
  161. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionInfo.h +227 -0
  162. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionState.cpp +17 -0
  163. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionState.h +30 -0
  164. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EmptyPredictionContext.cpp +35 -0
  165. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EmptyPredictionContext.h +27 -0
  166. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EpsilonTransition.cpp +35 -0
  167. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EpsilonTransition.h +39 -0
  168. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ErrorInfo.cpp +15 -0
  169. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ErrorInfo.h +43 -0
  170. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LL1Analyzer.cpp +158 -0
  171. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LL1Analyzer.h +109 -0
  172. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNConfig.cpp +84 -0
  173. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNConfig.h +44 -0
  174. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNSimulator.cpp +628 -0
  175. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNSimulator.h +210 -0
  176. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerAction.cpp +9 -0
  177. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerAction.h +66 -0
  178. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerActionExecutor.cpp +107 -0
  179. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerActionExecutor.h +115 -0
  180. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerActionType.h +55 -0
  181. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerChannelAction.cpp +55 -0
  182. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerChannelAction.h +63 -0
  183. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerCustomAction.cpp +62 -0
  184. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerCustomAction.h +87 -0
  185. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.cpp +63 -0
  186. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.h +82 -0
  187. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerModeAction.cpp +56 -0
  188. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerModeAction.h +61 -0
  189. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerMoreAction.cpp +47 -0
  190. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerMoreAction.h +57 -0
  191. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPopModeAction.cpp +47 -0
  192. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPopModeAction.h +57 -0
  193. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPushModeAction.cpp +56 -0
  194. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPushModeAction.h +61 -0
  195. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerSkipAction.cpp +47 -0
  196. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerSkipAction.h +55 -0
  197. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerTypeAction.cpp +56 -0
  198. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerTypeAction.h +55 -0
  199. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LookaheadEventInfo.cpp +16 -0
  200. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LookaheadEventInfo.h +42 -0
  201. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LoopEndState.cpp +12 -0
  202. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LoopEndState.h +22 -0
  203. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/Makefile +67 -0
  204. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/NotSetTransition.cpp +27 -0
  205. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/NotSetTransition.h +25 -0
  206. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.cpp +12 -0
  207. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.h +20 -0
  208. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParseInfo.cpp +102 -0
  209. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParseInfo.h +102 -0
  210. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParserATNSimulator.cpp +1366 -0
  211. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParserATNSimulator.h +904 -0
  212. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusBlockStartState.cpp +12 -0
  213. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusBlockStartState.h +25 -0
  214. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusLoopbackState.cpp +12 -0
  215. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusLoopbackState.h +22 -0
  216. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PrecedencePredicateTransition.cpp +32 -0
  217. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PrecedencePredicateTransition.h +29 -0
  218. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.cpp +17 -0
  219. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.h +62 -0
  220. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateTransition.cpp +34 -0
  221. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateTransition.h +39 -0
  222. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContext.cpp +662 -0
  223. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContext.h +254 -0
  224. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionMode.cpp +201 -0
  225. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionMode.h +436 -0
  226. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ProfilingATNSimulator.cpp +179 -0
  227. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ProfilingATNSimulator.h +60 -0
  228. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RangeTransition.cpp +30 -0
  229. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RangeTransition.h +29 -0
  230. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStartState.cpp +16 -0
  231. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStartState.h +25 -0
  232. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStopState.cpp +12 -0
  233. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStopState.h +25 -0
  234. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleTransition.cpp +37 -0
  235. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleTransition.h +40 -0
  236. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SemanticContext.cpp +377 -0
  237. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SemanticContext.h +222 -0
  238. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SetTransition.cpp +32 -0
  239. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SetTransition.h +30 -0
  240. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.cpp +81 -0
  241. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.h +36 -0
  242. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarBlockStartState.cpp +12 -0
  243. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarBlockStartState.h +21 -0
  244. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopEntryState.cpp +15 -0
  245. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopEntryState.h +35 -0
  246. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopbackState.cpp +19 -0
  247. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopbackState.h +21 -0
  248. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TokensStartState.cpp +12 -0
  249. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TokensStartState.h +21 -0
  250. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/Transition.cpp +44 -0
  251. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/Transition.h +76 -0
  252. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/WildcardTransition.cpp +25 -0
  253. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/WildcardTransition.h +25 -0
  254. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFA.cpp +127 -0
  255. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFA.h +91 -0
  256. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFASerializer.cpp +67 -0
  257. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFASerializer.h +32 -0
  258. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFAState.cpp +100 -0
  259. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFAState.h +144 -0
  260. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/LexerDFASerializer.cpp +20 -0
  261. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/LexerDFASerializer.h +23 -0
  262. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/InterpreterDataReader.cpp +124 -0
  263. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/InterpreterDataReader.h +31 -0
  264. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.cpp +89 -0
  265. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.h +84 -0
  266. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/IntervalSet.cpp +521 -0
  267. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/IntervalSet.h +198 -0
  268. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/MurmurHash.cpp +134 -0
  269. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/MurmurHash.h +76 -0
  270. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Predicate.cpp +4 -0
  271. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Predicate.h +21 -0
  272. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Any.cpp +13 -0
  273. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Any.h +170 -0
  274. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Arrays.cpp +43 -0
  275. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Arrays.h +110 -0
  276. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h +76 -0
  277. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/CPPUtils.cpp +248 -0
  278. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/CPPUtils.h +78 -0
  279. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Declarations.h +163 -0
  280. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/StringUtils.cpp +36 -0
  281. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/StringUtils.h +54 -0
  282. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/guid.cpp +303 -0
  283. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/guid.h +112 -0
  284. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/AbstractParseTreeVisitor.h +128 -0
  285. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNode.cpp +9 -0
  286. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNode.h +19 -0
  287. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNodeImpl.cpp +23 -0
  288. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNodeImpl.h +33 -0
  289. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/IterativeParseTreeWalker.cpp +71 -0
  290. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/IterativeParseTreeWalker.h +53 -0
  291. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTree.cpp +15 -0
  292. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTree.h +102 -0
  293. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeListener.cpp +9 -0
  294. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeListener.h +39 -0
  295. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeProperty.h +50 -0
  296. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeVisitor.cpp +9 -0
  297. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeVisitor.h +57 -0
  298. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeWalker.cpp +49 -0
  299. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeWalker.h +31 -0
  300. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNode.cpp +9 -0
  301. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNode.h +32 -0
  302. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNodeImpl.cpp +57 -0
  303. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNodeImpl.h +33 -0
  304. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/Trees.cpp +241 -0
  305. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/Trees.h +78 -0
  306. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/Chunk.cpp +9 -0
  307. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/Chunk.h +44 -0
  308. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreeMatch.cpp +69 -0
  309. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreeMatch.h +132 -0
  310. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreePattern.cpp +64 -0
  311. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreePattern.h +105 -0
  312. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreePatternMatcher.cpp +371 -0
  313. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreePatternMatcher.h +185 -0
  314. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/RuleTagToken.cpp +77 -0
  315. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/RuleTagToken.h +117 -0
  316. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TagChunk.cpp +39 -0
  317. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TagChunk.h +86 -0
  318. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TextChunk.cpp +28 -0
  319. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TextChunk.h +51 -0
  320. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TokenTagToken.cpp +36 -0
  321. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TokenTagToken.h +80 -0
  322. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPath.cpp +154 -0
  323. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPath.h +86 -0
  324. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathElement.cpp +31 -0
  325. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathElement.h +40 -0
  326. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexer.cpp +173 -0
  327. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexer.g4 +64 -0
  328. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexer.h +56 -0
  329. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexer.tokens +12 -0
  330. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexerErrorListener.cpp +13 -0
  331. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexerErrorListener.h +22 -0
  332. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathRuleAnywhereElement.cpp +20 -0
  333. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathRuleAnywhereElement.h +27 -0
  334. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathRuleElement.cpp +30 -0
  335. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathRuleElement.h +26 -0
  336. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathTokenAnywhereElement.cpp +20 -0
  337. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathTokenAnywhereElement.h +25 -0
  338. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathTokenElement.cpp +33 -0
  339. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathTokenElement.h +26 -0
  340. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathWildcardAnywhereElement.cpp +23 -0
  341. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathWildcardAnywhereElement.h +23 -0
  342. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathWildcardElement.cpp +24 -0
  343. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathWildcardElement.h +23 -0
  344. data/ext/express-parser/antlrgen/Express.interp +532 -0
  345. data/ext/express-parser/antlrgen/Express.tokens +190 -0
  346. data/ext/express-parser/antlrgen/ExpressBaseListener.cpp +7 -0
  347. data/ext/express-parser/antlrgen/ExpressBaseListener.h +623 -0
  348. data/ext/express-parser/antlrgen/ExpressBaseVisitor.cpp +7 -0
  349. data/ext/express-parser/antlrgen/ExpressBaseVisitor.h +816 -0
  350. data/ext/express-parser/antlrgen/ExpressLexer.cpp +1169 -0
  351. data/ext/express-parser/antlrgen/ExpressLexer.h +85 -0
  352. data/ext/express-parser/antlrgen/ExpressLexer.interp +534 -0
  353. data/ext/express-parser/antlrgen/ExpressLexer.tokens +190 -0
  354. data/ext/express-parser/antlrgen/ExpressListener.cpp +7 -0
  355. data/ext/express-parser/antlrgen/ExpressListener.h +616 -0
  356. data/ext/express-parser/antlrgen/ExpressParser.cpp +17284 -0
  357. data/ext/express-parser/antlrgen/ExpressParser.h +3696 -0
  358. data/ext/express-parser/antlrgen/ExpressVisitor.cpp +7 -0
  359. data/ext/express-parser/antlrgen/ExpressVisitor.h +422 -0
  360. data/ext/express-parser/express_parser.cpp +17931 -0
  361. data/ext/express-parser/extconf.rb +35 -0
  362. data/lib/expressir.rb +21 -21
  363. data/lib/expressir/cli.rb +27 -27
  364. data/lib/expressir/cli/ui.rb +36 -36
  365. data/lib/expressir/config.rb +23 -23
  366. data/lib/expressir/express.rb +11 -11
  367. data/lib/expressir/express/aggregate_dimension.rb +38 -38
  368. data/lib/expressir/express/attribute.rb +15 -15
  369. data/lib/expressir/express/comment.rb +7 -7
  370. data/lib/expressir/express/defined_type.rb +36 -36
  371. data/lib/expressir/express/derived.rb +65 -65
  372. data/lib/expressir/express/derived_aggregate.rb +43 -43
  373. data/lib/expressir/express/entity.rb +137 -137
  374. data/lib/expressir/express/explicit.rb +70 -70
  375. data/lib/expressir/express/explicit_aggregate.rb +46 -46
  376. data/lib/expressir/express/explicit_or_derived.rb +16 -16
  377. data/lib/expressir/express/global_rule.rb +44 -44
  378. data/lib/expressir/express/interface_specification.rb +51 -51
  379. data/lib/expressir/express/interfaced_item.rb +38 -38
  380. data/lib/expressir/express/inverse.rb +46 -46
  381. data/lib/expressir/express/inverse_aggregate.rb +37 -37
  382. data/lib/expressir/express/model_element.rb +7 -7
  383. data/lib/expressir/express/named_type.rb +19 -19
  384. data/lib/expressir/express/remark.rb +8 -8
  385. data/lib/expressir/express/repository.rb +306 -306
  386. data/lib/expressir/express/schema_definition.rb +96 -96
  387. data/lib/expressir/express/subtype_constraint.rb +14 -14
  388. data/lib/expressir/express/type.rb +26 -26
  389. data/lib/expressir/express/type_aggregate.rb +42 -42
  390. data/lib/expressir/express/type_enum.rb +29 -29
  391. data/lib/expressir/express/type_parser.rb +45 -45
  392. data/lib/expressir/express/type_select.rb +82 -82
  393. data/lib/expressir/express/unique_rule.rb +35 -35
  394. data/lib/expressir/express/where_rule.rb +32 -32
  395. data/lib/expressir/express_exp/formatter.rb +1450 -0
  396. data/lib/expressir/express_exp/parser.rb +35 -29
  397. data/lib/expressir/express_exp/visitor.rb +2450 -2133
  398. data/lib/expressir/express_parser.rb +30 -30
  399. data/lib/expressir/model.rb +64 -90
  400. data/lib/expressir/model/{derived.rb → attribute.rb} +26 -18
  401. data/lib/expressir/model/constant.rb +16 -16
  402. data/lib/expressir/model/entity.rb +45 -40
  403. data/lib/expressir/model/enumeration_item.rb +10 -12
  404. data/lib/expressir/model/expressions/aggregate_initializer.rb +13 -13
  405. data/lib/expressir/model/expressions/aggregate_item.rb +15 -0
  406. data/lib/expressir/model/expressions/{attribute_qualifier.rb → attribute_reference.rb} +14 -12
  407. data/lib/expressir/model/expressions/binary_expression.rb +40 -0
  408. data/lib/expressir/model/expressions/{function_call.rb → call.rb} +14 -14
  409. data/lib/expressir/model/expressions/entity_constructor.rb +15 -15
  410. data/lib/expressir/model/expressions/{group_qualifier.rb → group_reference.rb} +14 -12
  411. data/lib/expressir/model/expressions/{index_qualifier.rb → index_reference.rb} +16 -14
  412. data/lib/expressir/model/expressions/interval.rb +21 -21
  413. data/lib/expressir/model/expressions/query_expression.rb +26 -0
  414. data/lib/expressir/model/expressions/simple_reference.rb +13 -0
  415. data/lib/expressir/model/expressions/{expression.rb → unary_expression.rb} +18 -14
  416. data/lib/expressir/model/function.rb +61 -53
  417. data/lib/expressir/model/identifier.rb +9 -0
  418. data/lib/expressir/model/{reference.rb → interface.rb} +17 -12
  419. data/lib/expressir/model/literals/binary.rb +12 -12
  420. data/lib/expressir/model/literals/integer.rb +12 -12
  421. data/lib/expressir/model/literals/logical.rb +16 -12
  422. data/lib/expressir/model/literals/real.rb +12 -12
  423. data/lib/expressir/model/literals/string.rb +14 -14
  424. data/lib/expressir/model/parameter.rb +16 -16
  425. data/lib/expressir/model/procedure.rb +59 -51
  426. data/lib/expressir/model/renamed_ref.rb +12 -12
  427. data/lib/expressir/model/repository.rb +18 -16
  428. data/lib/expressir/model/rule.rb +61 -53
  429. data/lib/expressir/model/schema.rb +66 -50
  430. data/lib/expressir/model/scope.rb +17 -0
  431. data/lib/expressir/model/statements/alias.rb +25 -24
  432. data/lib/expressir/model/statements/assignment.rb +14 -14
  433. data/lib/expressir/model/statements/{procedure_call.rb → call.rb} +14 -14
  434. data/lib/expressir/model/statements/case.rb +16 -16
  435. data/lib/expressir/model/statements/case_action.rb +14 -14
  436. data/lib/expressir/model/statements/compound.rb +12 -12
  437. data/lib/expressir/model/statements/escape.rb +7 -7
  438. data/lib/expressir/model/statements/if.rb +16 -16
  439. data/lib/expressir/model/statements/null.rb +7 -7
  440. data/lib/expressir/model/statements/repeat.rb +33 -32
  441. data/lib/expressir/model/statements/return.rb +12 -12
  442. data/lib/expressir/model/statements/skip.rb +7 -7
  443. data/lib/expressir/model/subtype_constraint.rb +26 -20
  444. data/lib/expressir/model/type.rb +23 -22
  445. data/lib/expressir/model/types/aggregate.rb +16 -16
  446. data/lib/expressir/model/types/array.rb +20 -20
  447. data/lib/expressir/model/types/bag.rb +16 -16
  448. data/lib/expressir/model/types/binary.rb +14 -14
  449. data/lib/expressir/model/types/boolean.rb +7 -7
  450. data/lib/expressir/model/types/enumeration.rb +18 -18
  451. data/lib/expressir/model/types/generic.rb +12 -14
  452. data/lib/expressir/model/types/generic_entity.rb +12 -14
  453. data/lib/expressir/model/types/integer.rb +7 -7
  454. data/lib/expressir/model/types/list.rb +18 -18
  455. data/lib/expressir/model/types/logical.rb +7 -7
  456. data/lib/expressir/model/types/number.rb +7 -7
  457. data/lib/expressir/model/types/real.rb +12 -12
  458. data/lib/expressir/model/types/select.rb +20 -20
  459. data/lib/expressir/model/types/set.rb +16 -16
  460. data/lib/expressir/model/types/string.rb +14 -14
  461. data/lib/expressir/model/unique.rb +14 -14
  462. data/lib/expressir/model/{local.rb → variable.rb} +16 -16
  463. data/lib/expressir/model/where.rb +14 -14
  464. data/lib/expressir/parser.rb +6 -6
  465. data/lib/expressir/parser/owl_parser.rb +8 -8
  466. data/lib/expressir/version.rb +3 -3
  467. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.exp +9589 -9589
  468. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.owl +36619 -36619
  469. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.xml +13293 -13293
  470. data/original/examples/employment/eclipse/.project +17 -17
  471. data/original/examples/employment/eclipse/Express/employment_schema.exp +33 -33
  472. data/original/examples/employment/eclipse/Express/employment_schema.xmi +77 -77
  473. data/original/examples/employment/eclipse/Express/employment_schema.xml +92 -92
  474. data/original/examples/employment/eclipse/Models/Employment.uml +4 -4
  475. data/original/examples/employment/eclipse/Models/Employment.umldi +240 -240
  476. data/original/examples/employment/eclipse/readme.txt +6 -6
  477. data/original/examples/employment/employment_schema.exp +33 -33
  478. data/original/examples/employment/employment_schema.rb +232 -232
  479. data/original/examples/employment/employment_schema.xml +92 -92
  480. data/original/examples/employment/employment_schema___module.rb +46 -46
  481. data/original/examples/employment/employment_schema___p28attr.rb +126 -126
  482. data/original/examples/employment/employment_schema___p28inst.rb +26 -26
  483. data/original/examples/employment/example_employment_data.xml +1 -1
  484. data/original/examples/employment/example_employment_data_copy.xml +1 -1
  485. data/original/examples/employment/example_employment_reader.rb +30 -30
  486. data/original/examples/employment/example_employment_writer.rb +51 -51
  487. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.exp +3710 -3710
  488. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.owl +35880 -35880
  489. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.xmi +15357 -15357
  490. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.xml +9467 -9467
  491. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.exp +8404 -8404
  492. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.owl +43147 -43147
  493. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.xmi +18341 -18341
  494. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.xml +11631 -11631
  495. data/original/examples/syntax/remark.exp +145 -127
  496. data/original/examples/syntax/remark_formatted.exp +174 -0
  497. data/original/examples/syntax/syntax.exp +310 -300
  498. data/original/examples/syntax/syntax_formatted.exp +1187 -0
  499. data/original/exp2ruby.rb +525 -525
  500. data/original/expsm.rb +34 -34
  501. data/original/mapping_owl.rb +1018 -1018
  502. data/original/mapping_sysml.rb +2281 -2281
  503. data/original/mapping_uml2.rb +598 -598
  504. data/original/mapping_uml2_eclipse.rb +433 -433
  505. data/original/reeper.rb +134 -134
  506. data/spec/acceptance/express_to_owl_spec.rb +18 -18
  507. data/spec/acceptance/version_spec.rb +12 -12
  508. data/spec/expressir/express/repository_spec.rb +25 -25
  509. data/spec/expressir/express_exp/ap233_spec.rb +22 -22
  510. data/spec/expressir/express_exp/format_remark_spec.rb +28 -0
  511. data/spec/expressir/express_exp/format_syntax_spec.rb +28 -0
  512. data/spec/expressir/express_exp/{remark_spec.rb → parse_remark_spec.rb} +345 -301
  513. data/spec/expressir/express_exp/parse_syntax_spec.rb +2998 -0
  514. data/spec/expressir/model/find_spec.rb +110 -0
  515. data/spec/expressr_spec.rb +5 -5
  516. data/spec/spec_helper.rb +17 -17
  517. data/spec/support/console_helper.rb +29 -29
  518. metadata +401 -67
  519. data/.github/workflows/macos.yml +0 -38
  520. data/.github/workflows/ubuntu.yml +0 -56
  521. data/.github/workflows/windows.yml +0 -40
  522. data/generate-parser.sh +0 -29
  523. data/lib/expressir/express_exp/generated/ExpressBaseVisitor.rb +0 -779
  524. data/lib/expressir/express_exp/generated/ExpressLexer.rb +0 -844
  525. data/lib/expressir/express_exp/generated/ExpressParser.rb +0 -12162
  526. data/lib/expressir/express_exp/generated/ExpressVisitor.rb +0 -394
  527. data/lib/expressir/model/explicit.rb +0 -19
  528. data/lib/expressir/model/expressions/aggregate_element.rb +0 -15
  529. data/lib/expressir/model/expressions/qualified_ref.rb +0 -15
  530. data/lib/expressir/model/expressions/query.rb +0 -25
  531. data/lib/expressir/model/inverse.rb +0 -19
  532. data/lib/expressir/model/operators/addition.rb +0 -8
  533. data/lib/expressir/model/operators/and.rb +0 -8
  534. data/lib/expressir/model/operators/andor.rb +0 -8
  535. data/lib/expressir/model/operators/combine.rb +0 -8
  536. data/lib/expressir/model/operators/equal.rb +0 -8
  537. data/lib/expressir/model/operators/exponentiation.rb +0 -8
  538. data/lib/expressir/model/operators/greater_than.rb +0 -8
  539. data/lib/expressir/model/operators/greater_than_or_equal.rb +0 -8
  540. data/lib/expressir/model/operators/in.rb +0 -8
  541. data/lib/expressir/model/operators/instance_equal.rb +0 -8
  542. data/lib/expressir/model/operators/instance_not_equal.rb +0 -8
  543. data/lib/expressir/model/operators/integer_division.rb +0 -8
  544. data/lib/expressir/model/operators/less_than.rb +0 -8
  545. data/lib/expressir/model/operators/less_than_or_equal.rb +0 -8
  546. data/lib/expressir/model/operators/like.rb +0 -8
  547. data/lib/expressir/model/operators/modulo.rb +0 -8
  548. data/lib/expressir/model/operators/multiplication.rb +0 -8
  549. data/lib/expressir/model/operators/not.rb +0 -8
  550. data/lib/expressir/model/operators/not_equal.rb +0 -8
  551. data/lib/expressir/model/operators/oneof.rb +0 -8
  552. data/lib/expressir/model/operators/or.rb +0 -8
  553. data/lib/expressir/model/operators/real_division.rb +0 -8
  554. data/lib/expressir/model/operators/subtraction.rb +0 -8
  555. data/lib/expressir/model/operators/unary_minus.rb +0 -8
  556. data/lib/expressir/model/operators/unary_plus.rb +0 -8
  557. data/lib/expressir/model/operators/xor.rb +0 -8
  558. data/lib/expressir/model/ref.rb +0 -11
  559. data/lib/expressir/model/use.rb +0 -13
  560. data/spec/expressir/express_exp/syntax_spec.rb +0 -2992
@@ -1,30 +1,36 @@
1
- require 'antlr4/runtime'
2
- require 'expressir/express_exp/generated/ExpressVisitor'
3
- require 'expressir/express_exp/generated/ExpressLexer'
4
- require 'expressir/express_exp/generated/ExpressParser'
5
- require 'expressir/express_exp/visitor'
6
-
7
- module Expressir
8
- module ExpressExp
9
- class Parser
10
- def self.from_exp(file)
11
- input = File.read(file)
12
-
13
- char_stream = Antlr4::Runtime::CharStreams.from_string(input, 'String')
14
- lexer = Generated::ExpressLexer.new(char_stream)
15
- token_stream = Antlr4::Runtime::CommonTokenStream.new(lexer)
16
- parser = Generated::ExpressParser.new(token_stream)
17
-
18
- # don't attempt to recover from any parsing error
19
- parser.instance_variable_set(:@_err_handler, Antlr4::Runtime::BailErrorStrategy.new)
20
-
21
- parse_tree = parser.syntax()
22
-
23
- visitor = Visitor.new(token_stream)
24
- repo = visitor.visit(parse_tree)
25
-
26
- repo
27
- end
28
- end
29
- end
1
+ require 'express_parser'
2
+ require 'expressir/express_exp/visitor'
3
+
4
+ module Expressir
5
+ module ExpressExp
6
+ class Parser
7
+ def self.from_exp(file)
8
+ input = File.read(file)
9
+
10
+ =begin
11
+ char_stream = Antlr4::Runtime::CharStreams.from_string(input, 'String')
12
+ lexer = ::ExpressParser::Lexer.new(char_stream)
13
+ token_stream = Antlr4::Runtime::CommonTokenStream.new(lexer)
14
+ parser = ::ExpressParser::Parser.new(token_stream)
15
+
16
+ # don't attempt to recover from any parsing error
17
+ parser.instance_variable_set(:@_err_handler, Antlr4::Runtime::BailErrorStrategy.new)
18
+
19
+ parse_tree = parser.syntax()
20
+
21
+ visitor = Visitor.new(token_stream)
22
+ repo = visitor.visit(parse_tree)
23
+ =end
24
+
25
+ parser = ::ExpressParser::Parser.parse(input)
26
+
27
+ parse_tree = parser.syntax()
28
+
29
+ visitor = Visitor.new(parser.tokens)
30
+ repo = visitor.visit(parse_tree)
31
+
32
+ repo
33
+ end
34
+ end
35
+ end
30
36
  end
@@ -1,2134 +1,2451 @@
1
- require 'expressir/express_exp/generated/ExpressBaseVisitor'
2
- require 'expressir/model'
3
-
4
- # issues:
5
- #
6
- # reference type is not recognized
7
- # see note in A.1.5 Interpreted identifiers
8
- # > It is expected that identifiers matching these syntax rules are known to an implementation.
9
- # > How the implementation obtains this information is of no concern to the definition of the language. One
10
- # > method of gaining this information is multi-pass parsing: the first pass collects the identifiers from their
11
- # > declarations, so that subsequent passes are then able to distinguish a veriable_ref from a function_ref,
12
- # > for example.
13
- #
14
- # - xxxRef - merged to Ref
15
- # - entityConstructor, functionCall, procedureCall
16
- #
17
- # difference between generalized and instantiable types is not recognized
18
- # see note in 8.6.2 Parameter data types
19
- # > A syntactic construct such as ARRAY[1:3] OF REAL satisfies two syntactic productions —
20
- # > aggregation_type and general_aggregation_type. It is considered to be instantiable no matter which
21
- # > production it is required to satisfy in the syntax.
22
-
23
- module Expressir
24
- module ExpressExp
25
- class Visitor < Generated::ExpressBaseVisitor
26
- REMARK_CHANNEL = 2
27
-
28
- def initialize(tokens)
29
- @tokens = tokens
30
- @attached_remarks = Set.new
31
- end
32
-
33
- def visit(ctx)
34
- result = super(ctx)
35
- attach_remarks(ctx, result)
36
- result
37
- end
38
-
39
- def attach_remarks(ctx, item)
40
- # get remark tokens
41
- start_index, stop_index = if ctx.instance_of? Generated::ExpressParser::SyntaxContext
42
- [0, @tokens.size - 1]
43
- else
44
- [ctx.start.token_index, ctx.stop.token_index]
45
- end
46
- # puts [start_index, stop_index, ctx.class].inspect
47
-
48
- remark_tokens = @tokens.filter_for_channel(start_index, stop_index, REMARK_CHANNEL)
49
- if remark_tokens
50
- remark_tokens.each do |remark_token|
51
- remark_text = remark_token.text
52
-
53
- # check if it is tagged remark
54
- match = if remark_text.start_with?('--')
55
- remark_text[2..-1].match(/^"([^"]*)"(.*)$/)
56
- elsif remark_text.start_with?('(*') and remark_text.end_with?('*)')
57
- remark_text[2..-3].match(/^"([^"]*)"(.*)$/m)
58
- end
59
- if !match
60
- next
61
- end
62
-
63
- # don't attach already attached tagged remark
64
- if @attached_remarks.include? remark_token
65
- next
66
- end
67
-
68
- # attach tagged remark
69
- remark_tag = match[1]
70
- remark_content = match[2].strip
71
-
72
- current_item = item
73
- remark_tag.split('.').each do |id|
74
- if current_item
75
- if current_item.class.method_defined? :scope_items
76
- current_item = current_item.scope_items.find{|x| x.id == id}
77
- else
78
- current_item = nil
79
- break
80
- end
81
- else
82
- break
83
- end
84
- end
85
-
86
- if current_item
87
- current_item.remarks ||= []
88
- current_item.remarks << remark_content
89
-
90
- # mark remark as attached, so that it is not attached again at higher nesting level
91
- @attached_remarks << remark_token
92
- end
93
- end
94
- end
95
- end
96
-
97
- def visitAttributeRef(ctx)
98
- id = visit(ctx.attributeId())
99
-
100
- Model::Ref.new({
101
- id: id
102
- })
103
- end
104
-
105
- def visitConstantRef(ctx)
106
- id = visit(ctx.constantId())
107
-
108
- Model::Ref.new({
109
- id: id
110
- })
111
- end
112
-
113
- def visitEntityRef(ctx)
114
- id = visit(ctx.entityId())
115
-
116
- Model::Ref.new({
117
- id: id
118
- })
119
- end
120
-
121
- def visitEnumerationRef(ctx)
122
- id = visit(ctx.enumerationId())
123
-
124
- Model::Ref.new({
125
- id: id
126
- })
127
- end
128
-
129
- def visitFunctionRef(ctx)
130
- id = visit(ctx.functionId())
131
-
132
- Model::Ref.new({
133
- id: id
134
- })
135
- end
136
-
137
- def visitParameterRef(ctx)
138
- id = visit(ctx.parameterId())
139
-
140
- Model::Ref.new({
141
- id: id
142
- })
143
- end
144
-
145
- def visitProcedureRef(ctx)
146
- id = visit(ctx.procedureId())
147
-
148
- Model::Ref.new({
149
- id: id
150
- })
151
- end
152
-
153
- def visitRuleLabelRef(ctx)
154
- id = visit(ctx.ruleLabelId())
155
-
156
- Model::Ref.new({
157
- id: id
158
- })
159
- end
160
-
161
- def visitRuleRef(ctx)
162
- id = visit(ctx.ruleId())
163
-
164
- Model::Ref.new({
165
- id: id
166
- })
167
- end
168
-
169
- def visitSchemaRef(ctx)
170
- id = visit(ctx.schemaId())
171
-
172
- Model::Ref.new({
173
- id: id
174
- })
175
- end
176
-
177
- def visitSubtypeConstraintRef(ctx)
178
- id = visit(ctx.subtypeConstraintId())
179
-
180
- Model::Ref.new({
181
- id: id
182
- })
183
- end
184
-
185
- def visitTypeLabelRef(ctx)
186
- id = visit(ctx.typeLabelId())
187
-
188
- Model::Ref.new({
189
- id: id
190
- })
191
- end
192
-
193
- def visitTypeRef(ctx)
194
- id = visit(ctx.typeId())
195
-
196
- Model::Ref.new({
197
- id: id
198
- })
199
- end
200
-
201
- def visitVariableRef(ctx)
202
- id = visit(ctx.variableId())
203
-
204
- Model::Ref.new({
205
- id: id
206
- })
207
- end
208
-
209
- def visitAbstractEntityDeclaration(ctx)
210
- raise 'Invalid state'
211
- end
212
-
213
- def visitAbstractSupertype(ctx)
214
- raise 'Invalid state'
215
- end
216
-
217
- def visitAbstractSupertypeDeclaration(ctx)
218
- raise 'Invalid state'
219
- end
220
-
221
- def visitActualParameterList(ctx)
222
- raise 'Invalid state'
223
- end
224
-
225
- def visitAddLikeOp(ctx)
226
- if ctx.text == '+'
227
- Model::Operators::Addition.new()
228
- elsif ctx.text == '-'
229
- Model::Operators::Subtraction.new()
230
- elsif ctx.OR()
231
- Model::Operators::Or.new()
232
- elsif ctx.XOR()
233
- Model::Operators::Xor.new()
234
- else
235
- raise 'Invalid state'
236
- end
237
- end
238
-
239
- def visitAggregateInitializer(ctx)
240
- items = ctx.element().map{|ctx| visit(ctx)}
241
-
242
- Model::Expressions::AggregateInitializer.new({
243
- items: items
244
- })
245
- end
246
-
247
- def visitAggregateSource(ctx)
248
- raise 'Invalid state'
249
- end
250
-
251
- def visitAggregateType(ctx)
252
- label = if ctx.typeLabel()
253
- visit(ctx.typeLabel())
254
- end
255
- base_type = visit(ctx.parameterType())
256
-
257
- Model::Types::Aggregate.new({
258
- label: label,
259
- base_type: base_type
260
- })
261
- end
262
-
263
- def visitAggregationTypes(ctx)
264
- if ctx.arrayType()
265
- visit(ctx.arrayType())
266
- elsif ctx.bagType()
267
- visit(ctx.bagType())
268
- elsif ctx.listType()
269
- visit(ctx.listType())
270
- elsif ctx.setType()
271
- visit(ctx.setType())
272
- else
273
- raise 'Invalid state'
274
- end
275
- end
276
-
277
- def visitAlgorithmHead(ctx)
278
- raise 'Invalid state'
279
- end
280
-
281
- def visitAliasStmt(ctx)
282
- id = visit(ctx.variableId())
283
- expression = if ctx.qualifier().length > 0
284
- ref = visit(ctx.generalRef())
285
- qualifiers = ctx.qualifier().map{|ctx| visit(ctx)}
286
-
287
- Model::Expressions::QualifiedRef.new({
288
- ref: ref,
289
- qualifiers: qualifiers
290
- })
291
- else
292
- visit(ctx.generalRef())
293
- end
294
- statements = ctx.stmt().map{|ctx| visit(ctx)}
295
-
296
- Model::Statements::Alias.new({
297
- id: id,
298
- expression: expression,
299
- statements: statements
300
- })
301
- end
302
-
303
- def visitArrayType(ctx)
304
- bound1 = visit(ctx.boundSpec().bound1().numericExpression().simpleExpression())
305
- bound2 = visit(ctx.boundSpec().bound2().numericExpression().simpleExpression())
306
- optional = !!ctx.OPTIONAL()
307
- unique = !!ctx.UNIQUE()
308
- base_type = visit(ctx.instantiableType())
309
-
310
- Model::Types::Array.new({
311
- bound1: bound1,
312
- bound2: bound2,
313
- optional: optional,
314
- unique: unique,
315
- base_type: base_type
316
- })
317
- end
318
-
319
- def visitAssignmentStmt(ctx)
320
- expression = visit(ctx.expression())
321
-
322
- ref = if ctx.qualifier().length > 0
323
- ref = visit(ctx.generalRef())
324
- qualifiers = ctx.qualifier().map{|ctx| visit(ctx)}
325
-
326
- Model::Expressions::QualifiedRef.new({
327
- ref: ref,
328
- qualifiers: qualifiers
329
- })
330
- else
331
- visit(ctx.generalRef())
332
- end
333
-
334
- Model::Statements::Assignment.new({
335
- ref: ref,
336
- expression: expression
337
- })
338
- end
339
-
340
- def visitAttributeDecl(ctx)
341
- raise 'Invalid state'
342
- end
343
-
344
- def visitAttributeId(ctx)
345
- handleSimpleId(ctx.SimpleId())
346
- end
347
-
348
- def visitAttributeQualifier(ctx)
349
- attribute = visit(ctx.attributeRef())
350
-
351
- Model::Expressions::AttributeQualifier.new({
352
- attribute: attribute
353
- })
354
- end
355
-
356
- def visitBagType(ctx)
357
- bound1, bound2 = if ctx.boundSpec()
358
- [
359
- visit(ctx.boundSpec().bound1().numericExpression().simpleExpression()),
360
- visit(ctx.boundSpec().bound2().numericExpression().simpleExpression())
361
- ]
362
- end
363
- base_type = visit(ctx.instantiableType())
364
-
365
- Model::Types::Bag.new({
366
- bound1: bound1,
367
- bound2: bound2,
368
- base_type: base_type
369
- })
370
- end
371
-
372
- def visitBinaryType(ctx)
373
- width = if ctx.widthSpec()
374
- visit(ctx.widthSpec().width().numericExpression().simpleExpression())
375
- end
376
- fixed = if ctx.widthSpec()
377
- !!ctx.widthSpec().FIXED()
378
- end
379
-
380
- Model::Types::Binary.new({
381
- width: width,
382
- fixed: fixed
383
- })
384
- end
385
-
386
- def visitBooleanType(ctx)
387
- Model::Types::Boolean.new()
388
- end
389
-
390
- def visitBound1(ctx)
391
- raise 'Invalid state'
392
- end
393
-
394
- def visitBound2(ctx)
395
- raise 'Invalid state'
396
- end
397
-
398
- def visitBoundSpec(ctx)
399
- raise 'Invalid state'
400
- end
401
-
402
- def visitBuiltInConstant(ctx)
403
- id = ctx.text
404
-
405
- Model::Ref.new({
406
- id: id
407
- })
408
- end
409
-
410
- def visitBuiltInFunction(ctx)
411
- id = ctx.text
412
-
413
- Model::Ref.new({
414
- id: id
415
- })
416
- end
417
-
418
- def visitBuiltInProcedure(ctx)
419
- id = ctx.text
420
-
421
- Model::Ref.new({
422
- id: id
423
- })
424
- end
425
-
426
- def visitCaseAction(ctx)
427
- expressions = ctx.caseLabel().map{|ctx| visit(ctx.expression())}
428
- statement = visit(ctx.stmt())
429
-
430
- expressions.map do |expression|
431
- Model::Statements::CaseAction.new({
432
- expression: expression,
433
- statement: statement
434
- })
435
- end
436
- end
437
-
438
- def visitCaseLabel(ctx)
439
- raise 'Invalid state'
440
- end
441
-
442
- def visitCaseStmt(ctx)
443
- selector = visit(ctx.selector().expression())
444
- actions = ctx.caseAction().map{|ctx| visit(ctx)}.flatten
445
- otherwise_statement = if ctx.stmt()
446
- visit(ctx.stmt())
447
- end
448
-
449
- Model::Statements::Case.new({
450
- selector: selector,
451
- actions: actions,
452
- otherwise_statement: otherwise_statement
453
- })
454
- end
455
-
456
- def visitCompoundStmt(ctx)
457
- statements = ctx.stmt().map{|ctx| visit(ctx)}
458
-
459
- Model::Statements::Compound.new({
460
- statements: statements
461
- })
462
- end
463
-
464
- def visitConcreteTypes(ctx)
465
- if ctx.aggregationTypes()
466
- visit(ctx.aggregationTypes())
467
- elsif ctx.simpleTypes()
468
- visit(ctx.simpleTypes())
469
- elsif ctx.typeRef()
470
- visit(ctx.typeRef())
471
- else
472
- raise 'Invalid state'
473
- end
474
- end
475
-
476
- def visitConstantBody(ctx)
477
- id = visit(ctx.constantId())
478
- type = visit(ctx.instantiableType())
479
- expression = visit(ctx.expression())
480
-
481
- Model::Constant.new({
482
- id: id,
483
- type: type,
484
- expression: expression
485
- })
486
- end
487
-
488
- def visitConstantDecl(ctx)
489
- raise 'Invalid state'
490
- end
491
-
492
- def visitConstantFactor(ctx)
493
- if ctx.builtInConstant()
494
- visit(ctx.builtInConstant())
495
- elsif ctx.constantRef()
496
- visit(ctx.constantRef())
497
- else
498
- raise 'Invalid state'
499
- end
500
- end
501
-
502
- def visitConstantId(ctx)
503
- handleSimpleId(ctx.SimpleId())
504
- end
505
-
506
- def visitConstructedTypes(ctx)
507
- if ctx.enumerationType()
508
- visit(ctx.enumerationType())
509
- elsif ctx.selectType()
510
- visit(ctx.selectType())
511
- else
512
- raise 'Invalid state'
513
- end
514
- end
515
-
516
- def visitDeclaration(ctx)
517
- if ctx.entityDecl()
518
- visit(ctx.entityDecl())
519
- elsif ctx.functionDecl()
520
- visit(ctx.functionDecl())
521
- elsif ctx.procedureDecl()
522
- visit(ctx.procedureDecl())
523
- elsif ctx.subtypeConstraintDecl()
524
- visit(ctx.subtypeConstraintDecl())
525
- elsif ctx.typeDecl()
526
- visit(ctx.typeDecl())
527
- else
528
- raise 'Invalid state'
529
- end
530
- end
531
-
532
- def visitDerivedAttr(ctx)
533
- id = if ctx.attributeDecl().attributeId()
534
- visit(ctx.attributeDecl().attributeId())
535
- elsif ctx.attributeDecl().redeclaredAttribute() && ctx.attributeDecl().redeclaredAttribute().attributeId()
536
- visit(ctx.attributeDecl().redeclaredAttribute().attributeId())
537
- end
538
- supertype_attribute = if ctx.attributeDecl().redeclaredAttribute() && ctx.attributeDecl().redeclaredAttribute().qualifiedAttribute()
539
- visit(ctx.attributeDecl().redeclaredAttribute().qualifiedAttribute())
540
- end
541
- type = visit(ctx.parameterType())
542
- expression = visit(ctx.expression())
543
-
544
- Model::Derived.new({
545
- id: id,
546
- supertype_attribute: supertype_attribute,
547
- type: type,
548
- expression: expression
549
- })
550
- end
551
-
552
- def visitDeriveClause(ctx)
553
- raise 'Invalid state'
554
- end
555
-
556
- def visitDomainRule(ctx)
557
- id = if ctx.ruleLabelId()
558
- visit(ctx.ruleLabelId())
559
- end
560
- expression = visit(ctx.expression())
561
-
562
- Model::Where.new({
563
- id: id,
564
- expression: expression
565
- })
566
- end
567
-
568
- def visitElement(ctx)
569
- if ctx.repetition()
570
- expression = visit(ctx.expression())
571
- repetition = visit(ctx.repetition().numericExpression().simpleExpression())
572
-
573
- Model::Expressions::AggregateElement.new({
574
- expression: expression,
575
- repetition: repetition
576
- })
577
- else
578
- visit(ctx.expression())
579
- end
580
- end
581
-
582
- def visitEntityBody(ctx)
583
- raise 'Invalid state'
584
- end
585
-
586
- def visitEntityConstructor(ctx)
587
- entity = visit(ctx.entityRef())
588
- parameters = ctx.expression().map{|ctx| visit(ctx)}
589
-
590
- Model::Expressions::EntityConstructor.new({
591
- entity: entity,
592
- parameters: parameters
593
- })
594
- end
595
-
596
- def visitEntityDecl(ctx)
597
- id = visit(ctx.entityHead().entityId())
598
- abstract = if ctx.entityHead().subsuper().supertypeConstraint()
599
- !!ctx.entityHead().subsuper().supertypeConstraint().abstractEntityDeclaration()
600
- end
601
- abstract_supertype = if ctx.entityHead().subsuper().supertypeConstraint()
602
- !!ctx.entityHead().subsuper().supertypeConstraint().abstractSupertypeDeclaration()
603
- end
604
- supertypes = if ctx.entityHead().subsuper().subtypeDeclaration()
605
- ctx.entityHead().subsuper().subtypeDeclaration().entityRef().map{|ctx| visit(ctx)}
606
- end
607
- subtype_expression = if ctx.entityHead().subsuper().supertypeConstraint() && ctx.entityHead().subsuper().supertypeConstraint().abstractSupertypeDeclaration() && ctx.entityHead().subsuper().supertypeConstraint().abstractSupertypeDeclaration().subtypeConstraint()
608
- visit(ctx.entityHead().subsuper().supertypeConstraint().abstractSupertypeDeclaration().subtypeConstraint().supertypeExpression())
609
- elsif ctx.entityHead().subsuper().supertypeConstraint() && ctx.entityHead().subsuper().supertypeConstraint().supertypeRule()
610
- visit(ctx.entityHead().subsuper().supertypeConstraint().supertypeRule().subtypeConstraint().supertypeExpression())
611
- end
612
- explicit = ctx.entityBody().explicitAttr().map{|ctx| visit(ctx)}.flatten
613
- derived = if ctx.entityBody().deriveClause()
614
- ctx.entityBody().deriveClause().derivedAttr().map{|ctx| visit(ctx)}
615
- end
616
- inverse = if ctx.entityBody().inverseClause()
617
- ctx.entityBody().inverseClause().inverseAttr().map{|ctx| visit(ctx)}
618
- end
619
- unique = if ctx.entityBody().uniqueClause()
620
- ctx.entityBody().uniqueClause().uniqueRule().map{|ctx| visit(ctx)}
621
- end
622
- where = if ctx.entityBody().whereClause()
623
- ctx.entityBody().whereClause().domainRule().map{|ctx| visit(ctx)}
624
- end
625
-
626
- Model::Entity.new({
627
- id: id,
628
- abstract: abstract,
629
- abstract_supertype: abstract_supertype,
630
- supertypes: supertypes,
631
- subtype_expression: subtype_expression,
632
- explicit: explicit,
633
- derived: derived,
634
- inverse: inverse,
635
- unique: unique,
636
- where: where
637
- })
638
- end
639
-
640
- def visitEntityHead(ctx)
641
- raise 'Invalid state'
642
- end
643
-
644
- def visitEntityId(ctx)
645
- handleSimpleId(ctx.SimpleId())
646
- end
647
-
648
- def visitEnumerationExtension(ctx)
649
- raise 'Invalid state'
650
- end
651
-
652
- def visitEnumerationId(ctx)
653
- handleSimpleId(ctx.SimpleId())
654
- end
655
-
656
- def visitEnumerationItems(ctx)
657
- raise 'Invalid state'
658
- end
659
-
660
- def visitEnumerationReference(ctx)
661
- if ctx.typeRef()
662
- ref = visit(ctx.typeRef())
663
- attribute = visit(ctx.enumerationRef())
664
- attribute_qualifier = Model::Expressions::AttributeQualifier.new({
665
- attribute: attribute
666
- })
667
- qualifiers = [attribute_qualifier]
668
-
669
- Model::Expressions::QualifiedRef.new({
670
- ref: ref,
671
- qualifiers: qualifiers
672
- })
673
- else
674
- visit(ctx.enumerationRef())
675
- end
676
- end
677
-
678
- def visitEnumerationType(ctx)
679
- extensible = !!ctx.EXTENSIBLE()
680
- items = if ctx.enumerationItems()
681
- ctx.enumerationItems().enumerationId().map{|ctx| handleEnumerationItem(ctx)}
682
- end
683
- extension_type = if ctx.enumerationExtension()
684
- visit(ctx.enumerationExtension().typeRef())
685
- end
686
- extension_items = if ctx.enumerationExtension() && ctx.enumerationExtension().enumerationItems()
687
- ctx.enumerationExtension().enumerationItems().enumerationId().map{|ctx| handleEnumerationItem(ctx)}
688
- end
689
-
690
- Model::Types::Enumeration.new({
691
- extensible: extensible,
692
- items: items,
693
- extension_type: extension_type,
694
- extension_items: extension_items
695
- })
696
- end
697
-
698
- def visitEscapeStmt(ctx)
699
- Model::Statements::Escape.new()
700
- end
701
-
702
- def visitExplicitAttr(ctx)
703
- decls = ctx.attributeDecl()
704
- optional = !!ctx.OPTIONAL()
705
- type = visit(ctx.parameterType())
706
-
707
- decls.map do |decl|
708
- id = if decl.attributeId()
709
- visit(decl.attributeId())
710
- elsif decl.redeclaredAttribute() && decl.redeclaredAttribute().attributeId()
711
- visit(decl.redeclaredAttribute().attributeId())
712
- end
713
- supertype_attribute = if decl.redeclaredAttribute() && decl.redeclaredAttribute().qualifiedAttribute()
714
- visit(decl.redeclaredAttribute().qualifiedAttribute())
715
- end
716
- Model::Explicit.new({
717
- id: id,
718
- supertype_attribute: supertype_attribute,
719
- optional: optional,
720
- type: type
721
- })
722
- end
723
- end
724
-
725
- def visitExpression(ctx)
726
- if ctx.relOpExtended()
727
- operator = visit(ctx.relOpExtended())
728
- operands = ctx.simpleExpression().map{|ctx| visit(ctx)}
729
-
730
- Model::Expressions::Expression.new({
731
- operator: operator,
732
- operands: operands
733
- })
734
- else
735
- visit(ctx.simpleExpression()[0])
736
- end
737
- end
738
-
739
- def visitFactor(ctx)
740
- if ctx.child_at(1) && ctx.child_at(1).text == '**'
741
- operator = Model::Operators::Exponentiation.new()
742
- operands = ctx.simpleFactor().map{|ctx| visit(ctx)}
743
-
744
- Model::Expressions::Expression.new({
745
- operator: operator,
746
- operands: operands
747
- })
748
- else
749
- visit(ctx.simpleFactor()[0])
750
- end
751
- end
752
-
753
- def visitFormalParameter(ctx)
754
- ids = ctx.parameterId().map{|ctx| visit(ctx)}
755
- type = visit(ctx.parameterType())
756
-
757
- ids.map do |id|
758
- Model::Parameter.new({
759
- id: id,
760
- type: type
761
- })
762
- end
763
- end
764
-
765
- def visitFunctionCall(ctx)
766
- function = if ctx.builtInFunction()
767
- visit(ctx.builtInFunction())
768
- elsif ctx.functionRef()
769
- visit(ctx.functionRef())
770
- else
771
- raise 'Invalid state'
772
- end
773
- parameters = if ctx.actualParameterList()
774
- ctx.actualParameterList().parameter().map{|ctx| visit(ctx.expression)}
775
- end
776
-
777
- Model::Expressions::FunctionCall.new({
778
- function: function,
779
- parameters: parameters
780
- })
781
- end
782
-
783
- def visitFunctionDecl(ctx)
784
- id = visit(ctx.functionHead().functionId())
785
- parameters = ctx.functionHead().formalParameter().map{|ctx| visit(ctx)}.flatten
786
- return_type = visit(ctx.functionHead().parameterType())
787
- declarations = ctx.algorithmHead().declaration().map{|ctx| visit(ctx)}
788
- constants = if ctx.algorithmHead().constantDecl()
789
- ctx.algorithmHead().constantDecl().constantBody().map{|ctx| visit(ctx)}
790
- end
791
- locals = if ctx.algorithmHead().localDecl()
792
- ctx.algorithmHead().localDecl().localVariable().map{|ctx| visit(ctx)}.flatten
793
- end
794
- declarations = ctx.algorithmHead().declaration().map{|ctx| visit(ctx)}
795
- statements = ctx.stmt().map{|ctx| visit(ctx)}
796
-
797
- Model::Function.new({
798
- id: id,
799
- parameters: parameters,
800
- return_type: return_type,
801
- declarations: declarations,
802
- constants: constants,
803
- locals: locals,
804
- statements: statements
805
- })
806
- end
807
-
808
- def visitFunctionHead(ctx)
809
- raise 'Invalid state'
810
- end
811
-
812
- def visitFunctionId(ctx)
813
- handleSimpleId(ctx.SimpleId())
814
- end
815
-
816
- def visitGeneralizedTypes(ctx)
817
- if ctx.aggregateType()
818
- visit(ctx.aggregateType())
819
- elsif ctx.generalAggregationTypes()
820
- visit(ctx.generalAggregationTypes())
821
- elsif ctx.genericEntityType()
822
- visit(ctx.genericEntityType())
823
- elsif ctx.genericType()
824
- visit(ctx.genericType())
825
- else
826
- raise 'Invalid state'
827
- end
828
- end
829
-
830
- def visitGeneralAggregationTypes(ctx)
831
- if ctx.generalArrayType()
832
- visit(ctx.generalArrayType())
833
- elsif ctx.generalBagType()
834
- visit(ctx.generalBagType())
835
- elsif ctx.generalListType()
836
- visit(ctx.generalListType())
837
- elsif ctx.generalSetType()
838
- visit(ctx.generalSetType())
839
- else
840
- raise 'Invalid state'
841
- end
842
- end
843
-
844
- def visitGeneralArrayType(ctx)
845
- bound1, bound2 = if ctx.boundSpec()
846
- [
847
- visit(ctx.boundSpec().bound1().numericExpression().simpleExpression()),
848
- visit(ctx.boundSpec().bound2().numericExpression().simpleExpression())
849
- ]
850
- end
851
- optional = !!ctx.OPTIONAL()
852
- unique = !!ctx.UNIQUE()
853
- base_type = visit(ctx.parameterType())
854
-
855
- Model::Types::Array.new({
856
- bound1: bound1,
857
- bound2: bound2,
858
- optional: optional,
859
- unique: unique,
860
- base_type: base_type
861
- })
862
- end
863
-
864
- def visitGeneralBagType(ctx)
865
- bound1, bound2 = if ctx.boundSpec()
866
- [
867
- visit(ctx.boundSpec().bound1().numericExpression().simpleExpression()),
868
- visit(ctx.boundSpec().bound2().numericExpression().simpleExpression())
869
- ]
870
- end
871
- base_type = visit(ctx.parameterType())
872
-
873
- Model::Types::Bag.new({
874
- bound1: bound1,
875
- bound2: bound2,
876
- base_type: base_type
877
- })
878
- end
879
-
880
- def visitGeneralListType(ctx)
881
- bound1, bound2 = if ctx.boundSpec()
882
- [
883
- visit(ctx.boundSpec().bound1().numericExpression().simpleExpression()),
884
- visit(ctx.boundSpec().bound2().numericExpression().simpleExpression())
885
- ]
886
- end
887
- unique = !!ctx.UNIQUE()
888
- base_type = visit(ctx.parameterType())
889
-
890
- Model::Types::List.new({
891
- bound1: bound1,
892
- bound2: bound2,
893
- unique: unique,
894
- base_type: base_type
895
- })
896
- end
897
-
898
- def visitGeneralRef(ctx)
899
- if ctx.parameterRef()
900
- visit(ctx.parameterRef())
901
- elsif ctx.variableId()
902
- visit(ctx.variableId())
903
- else
904
- raise 'Invalid state'
905
- end
906
- end
907
-
908
- def visitGeneralSetType(ctx)
909
- bound1, bound2 = if ctx.boundSpec()
910
- [
911
- visit(ctx.boundSpec().bound1().numericExpression().simpleExpression()),
912
- visit(ctx.boundSpec().bound2().numericExpression().simpleExpression())
913
- ]
914
- end
915
- base_type = visit(ctx.parameterType())
916
-
917
- Model::Types::Set.new({
918
- bound1: bound1,
919
- bound2: bound2,
920
- base_type: base_type
921
- })
922
- end
923
-
924
- def visitGenericEntityType(ctx)
925
- label = if ctx.typeLabel()
926
- visit(ctx.typeLabel())
927
- end
928
-
929
- Model::Types::GenericEntity.new({
930
- label: label
931
- })
932
- end
933
-
934
- def visitGenericType(ctx)
935
- label = if ctx.typeLabel()
936
- visit(ctx.typeLabel())
937
- end
938
-
939
- Model::Types::Generic.new({
940
- label: label
941
- })
942
- end
943
-
944
- def visitGroupQualifier(ctx)
945
- entity = visit(ctx.entityRef())
946
-
947
- Model::Expressions::GroupQualifier.new({
948
- entity: entity
949
- })
950
- end
951
-
952
- def visitIfStmt(ctx)
953
- expression = visit(ctx.logicalExpression().expression())
954
- else_index = if ctx.ELSE()
955
- ctx.children.find_index{|x| x == ctx.ELSE()}
956
- end
957
- else_statement_index = if else_index
958
- else_index - ctx.children.find_index{|x| x == ctx.stmt()[0]}
959
- end
960
- statements = if else_statement_index
961
- ctx.stmt()[0..(else_statement_index - 1)].map{|ctx| visit(ctx)}
962
- else
963
- ctx.stmt().map{|ctx| visit(ctx)}
964
- end
965
- else_statements = if else_statement_index
966
- ctx.stmt()[else_statement_index..(ctx.stmt().length - 1)].map{|ctx| visit(ctx)}
967
- end
968
-
969
- Model::Statements::If.new({
970
- expression: expression,
971
- statements: statements,
972
- else_statements: else_statements
973
- })
974
- end
975
-
976
- def visitIncrement(ctx)
977
- raise 'Invalid state'
978
- end
979
-
980
- def visitIncrementControl(ctx)
981
- raise 'Invalid state'
982
- end
983
-
984
- def visitIndex(ctx)
985
- raise 'Invalid state'
986
- end
987
-
988
- def visitIndex1(ctx)
989
- raise 'Invalid state'
990
- end
991
-
992
- def visitIndex2(ctx)
993
- raise 'Invalid state'
994
- end
995
-
996
- def visitIndexQualifier(ctx)
997
- index1 = visit(ctx.index1().index().numericExpression().simpleExpression())
998
- index2 = if ctx.index2()
999
- visit(ctx.index2().index().numericExpression().simpleExpression())
1000
- end
1001
-
1002
- Model::Expressions::IndexQualifier.new({
1003
- index1: index1,
1004
- index2: index2
1005
- })
1006
- end
1007
-
1008
- def visitInstantiableType(ctx)
1009
- if ctx.concreteTypes()
1010
- visit(ctx.concreteTypes())
1011
- elsif ctx.entityRef()
1012
- visit(ctx.entityRef())
1013
- else
1014
- raise 'Invalid state'
1015
- end
1016
- end
1017
-
1018
- def visitIntegerType(ctx)
1019
- Model::Types::Integer.new()
1020
- end
1021
-
1022
- def visitInterfaceSpecification(ctx)
1023
- if ctx.referenceClause()
1024
- visit(ctx.referenceClause())
1025
- elsif ctx.useClause()
1026
- visit(ctx.useClause())
1027
- else
1028
- raise 'Invalid state'
1029
- end
1030
- end
1031
-
1032
- def visitInterval(ctx)
1033
- low = visit(ctx.intervalLow().simpleExpression())
1034
- operator1 = visit(ctx.intervalOp()[0])
1035
- item = visit(ctx.intervalItem().simpleExpression())
1036
- operator2 = visit(ctx.intervalOp()[1])
1037
- high = visit(ctx.intervalHigh().simpleExpression())
1038
-
1039
- Model::Expressions::Interval.new({
1040
- low: low,
1041
- operator1: operator1,
1042
- item: item,
1043
- operator2: operator2,
1044
- high: high
1045
- })
1046
- end
1047
-
1048
- def visitIntervalHigh(ctx)
1049
- raise 'Invalid state'
1050
- end
1051
-
1052
- def visitIntervalItem(ctx)
1053
- raise 'Invalid state'
1054
- end
1055
-
1056
- def visitIntervalLow(ctx)
1057
- raise 'Invalid state'
1058
- end
1059
-
1060
- def visitIntervalOp(ctx)
1061
- if ctx.text == '<'
1062
- Model::Operators::LessThan.new()
1063
- elsif ctx.text == '<='
1064
- Model::Operators::LessThanOrEqual.new()
1065
- else
1066
- raise 'Invalid state'
1067
- end
1068
- end
1069
-
1070
- def visitInverseAttr(ctx)
1071
- id = if ctx.attributeDecl().attributeId()
1072
- visit(ctx.attributeDecl().attributeId())
1073
- elsif ctx.attributeDecl().redeclaredAttribute() && ctx.attributeDecl().redeclaredAttribute().attributeId()
1074
- visit(ctx.attributeDecl().redeclaredAttribute().attributeId())
1075
- end
1076
- supertype_attribute = if ctx.attributeDecl().redeclaredAttribute() && ctx.attributeDecl().redeclaredAttribute().qualifiedAttribute()
1077
- visit(ctx.attributeDecl().redeclaredAttribute().qualifiedAttribute())
1078
- end
1079
- type = if ctx.SET()
1080
- bound1, bound2 = if ctx.boundSpec()
1081
- [
1082
- visit(ctx.boundSpec().bound1().numericExpression().simpleExpression()),
1083
- visit(ctx.boundSpec().bound2().numericExpression().simpleExpression())
1084
- ]
1085
- end
1086
- base_type = visit(ctx.entityRef()[0])
1087
-
1088
- Model::Types::Set.new({
1089
- bound1: bound1,
1090
- bound2: bound2,
1091
- base_type: base_type
1092
- })
1093
- elsif ctx.BAG()
1094
- bound1, bound2 = if ctx.boundSpec()
1095
- [
1096
- visit(ctx.boundSpec().bound1().numericExpression().simpleExpression()),
1097
- visit(ctx.boundSpec().bound2().numericExpression().simpleExpression())
1098
- ]
1099
- end
1100
- base_type = visit(ctx.entityRef()[0])
1101
-
1102
- Model::Types::Bag.new({
1103
- bound1: bound1,
1104
- bound2: bound2,
1105
- base_type: base_type
1106
- })
1107
- else
1108
- visit(ctx.entityRef()[0])
1109
- end
1110
- attribute = if ctx.entityRef()[1]
1111
- ref = visit(ctx.entityRef()[1])
1112
- attribute = visit(ctx.attributeRef())
1113
- attribute_qualifier = Model::Expressions::AttributeQualifier.new({
1114
- attribute: attribute
1115
- })
1116
- qualifiers = [attribute_qualifier]
1117
-
1118
- Model::Expressions::QualifiedRef.new({
1119
- ref: ref,
1120
- qualifiers: qualifiers
1121
- })
1122
- else
1123
- visit(ctx.attributeRef())
1124
- end
1125
-
1126
- Model::Inverse.new({
1127
- id: id,
1128
- supertype_attribute: supertype_attribute,
1129
- type: type,
1130
- attribute: attribute
1131
- })
1132
- end
1133
-
1134
- def visitInverseClause(ctx)
1135
- raise 'Invalid state'
1136
- end
1137
-
1138
- def visitListType(ctx)
1139
- bound1, bound2 = if ctx.boundSpec()
1140
- [
1141
- visit(ctx.boundSpec().bound1().numericExpression().simpleExpression()),
1142
- visit(ctx.boundSpec().bound2().numericExpression().simpleExpression())
1143
- ]
1144
- end
1145
- unique = !!ctx.UNIQUE()
1146
- base_type = visit(ctx.instantiableType())
1147
-
1148
- Model::Types::List.new({
1149
- bound1: bound1,
1150
- bound2: bound2,
1151
- unique: unique,
1152
- base_type: base_type
1153
- })
1154
- end
1155
-
1156
- def visitLiteral(ctx)
1157
- if ctx.BinaryLiteral()
1158
- handleBinaryLiteral(ctx.BinaryLiteral())
1159
- elsif ctx.IntegerLiteral()
1160
- handleIntegerLiteral(ctx.IntegerLiteral())
1161
- elsif ctx.logicalLiteral()
1162
- visit(ctx.logicalLiteral())
1163
- elsif ctx.RealLiteral()
1164
- handleRealLiteral(ctx.RealLiteral())
1165
- elsif ctx.stringLiteral()
1166
- visit(ctx.stringLiteral())
1167
- else
1168
- raise 'Invalid state'
1169
- end
1170
- end
1171
-
1172
- def visitLocalDecl(ctx)
1173
- raise 'Invalid state'
1174
- end
1175
-
1176
- def visitLocalVariable(ctx)
1177
- ids = ctx.variableId().map{|ctx| visit(ctx)}
1178
- type = visit(ctx.parameterType())
1179
- expression = if ctx.expression()
1180
- visit(ctx.expression())
1181
- end
1182
-
1183
- ids.map do |id|
1184
- Model::Local.new({
1185
- id: id,
1186
- type: type,
1187
- expression: expression
1188
- })
1189
- end
1190
- end
1191
-
1192
- def visitLogicalExpression(ctx)
1193
- raise 'Invalid state'
1194
- end
1195
-
1196
- def visitLogicalLiteral(ctx)
1197
- value = if ctx.TRUE()
1198
- true
1199
- elsif ctx.FALSE()
1200
- false
1201
- elsif ctx.UNKNOWN()
1202
- nil
1203
- else
1204
- raise 'Invalid state'
1205
- end
1206
-
1207
- Model::Literals::Logical.new({
1208
- value: value
1209
- })
1210
- end
1211
-
1212
- def visitLogicalType(ctx)
1213
- Model::Types::Logical.new()
1214
- end
1215
-
1216
- def visitMultiplicationLikeOp(ctx)
1217
- if ctx.text == '*'
1218
- Model::Operators::Multiplication.new()
1219
- elsif ctx.text == '/'
1220
- Model::Operators::RealDivision.new()
1221
- elsif ctx.DIV()
1222
- Model::Operators::IntegerDivision.new()
1223
- elsif ctx.MOD()
1224
- Model::Operators::Modulo.new()
1225
- elsif ctx.AND()
1226
- Model::Operators::And.new()
1227
- elsif ctx.text == '||'
1228
- Model::Operators::Combine.new()
1229
- else
1230
- raise 'Invalid state'
1231
- end
1232
- end
1233
-
1234
- def visitNamedTypes(ctx)
1235
- if ctx.entityRef()
1236
- visit(ctx.entityRef())
1237
- elsif ctx.typeRef()
1238
- visit(ctx.typeRef())
1239
- else
1240
- raise 'Invalid state'
1241
- end
1242
- end
1243
-
1244
- def visitNamedTypeOrRename(ctx)
1245
- if ctx.entityId() || ctx.typeId()
1246
- ref = visit(ctx.namedTypes())
1247
- id = if ctx.entityId()
1248
- visit(ctx.entityId())
1249
- elsif ctx.typeId()
1250
- visit(ctx.typeId())
1251
- end
1252
-
1253
- Model::RenamedRef.new({
1254
- ref: ref,
1255
- id: id
1256
- })
1257
- else
1258
- visit(ctx.namedTypes())
1259
- end
1260
- end
1261
-
1262
- def visitNullStmt(ctx)
1263
- Model::Statements::Null.new()
1264
- end
1265
-
1266
- def visitNumberType(ctx)
1267
- Model::Types::Number.new()
1268
- end
1269
-
1270
- def visitNumericExpression(ctx)
1271
- raise 'Invalid state'
1272
- end
1273
-
1274
- def visitOneOf(ctx)
1275
- operator = Model::Operators::Oneof.new()
1276
- operands = ctx.supertypeExpression().map{|ctx| visit(ctx)}
1277
-
1278
- Model::Expressions::Expression.new({
1279
- operator: operator,
1280
- operands: operands
1281
- })
1282
- end
1283
-
1284
- def visitParameter(ctx)
1285
- raise 'Invalid state'
1286
- end
1287
-
1288
- def visitParameterId(ctx)
1289
- handleSimpleId(ctx.SimpleId())
1290
- end
1291
-
1292
- def visitParameterType(ctx)
1293
- if ctx.generalizedTypes()
1294
- visit(ctx.generalizedTypes())
1295
- elsif ctx.namedTypes()
1296
- visit(ctx.namedTypes())
1297
- elsif ctx.simpleTypes()
1298
- visit(ctx.simpleTypes())
1299
- else
1300
- raise 'Invalid state'
1301
- end
1302
- end
1303
-
1304
- def visitPopulation(ctx)
1305
- raise 'Invalid state'
1306
- end
1307
-
1308
- def visitPrecisionSpec(ctx)
1309
- raise 'Invalid state'
1310
- end
1311
-
1312
- def visitPrimary(ctx)
1313
- if ctx.literal()
1314
- visit(ctx.literal())
1315
- elsif ctx.qualifiableFactor()
1316
- visit(ctx.qualifiableFactor())
1317
- else
1318
- raise 'Invalid state'
1319
- end
1320
- end
1321
-
1322
- def visitProcedureCallStmt(ctx)
1323
- procedure = if ctx.builtInProcedure()
1324
- visit(ctx.builtInProcedure())
1325
- elsif ctx.procedureRef()
1326
- visit(ctx.procedureRef())
1327
- else
1328
- raise 'Invalid state'
1329
- end
1330
- parameters = if ctx.actualParameterList()
1331
- ctx.actualParameterList().parameter().map{|ctx| visit(ctx.expression)}
1332
- end
1333
-
1334
- Model::Statements::ProcedureCall.new({
1335
- procedure: procedure,
1336
- parameters: parameters
1337
- })
1338
- end
1339
-
1340
- def visitProcedureDecl(ctx)
1341
- id = visit(ctx.procedureHead().procedureId())
1342
- parameters = ctx.procedureHead().formalParameter().map do |ctx|
1343
- parameters = visit(ctx)
1344
- parameters_index = ctx.parent.children.find_index{|x| x == ctx}
1345
- var = ctx.parent.child_at(parameters_index - 1)
1346
- if var.text == 'VAR'
1347
- parameters.map do |parameter|
1348
- Model::Parameter.new({
1349
- id: parameter.id,
1350
- type: parameter.type,
1351
- var: true
1352
- })
1353
- end
1354
- else
1355
- parameters
1356
- end
1357
- end.flatten
1358
- declarations = ctx.algorithmHead().declaration().map{|ctx| visit(ctx)}
1359
- constants = if ctx.algorithmHead().constantDecl()
1360
- ctx.algorithmHead().constantDecl().constantBody().map{|ctx| visit(ctx)}
1361
- end
1362
- locals = if ctx.algorithmHead().localDecl()
1363
- ctx.algorithmHead().localDecl().localVariable().map{|ctx| visit(ctx)}.flatten
1364
- end
1365
- statements = ctx.stmt().map{|ctx| visit(ctx)}
1366
-
1367
- Model::Procedure.new({
1368
- id: id,
1369
- parameters: parameters,
1370
- declarations: declarations,
1371
- constants: constants,
1372
- locals: locals,
1373
- statements: statements
1374
- })
1375
- end
1376
-
1377
- def visitProcedureHead(ctx)
1378
- raise 'Invalid state'
1379
- end
1380
-
1381
- def visitProcedureId(ctx)
1382
- handleSimpleId(ctx.SimpleId())
1383
- end
1384
-
1385
- def visitQualifiableFactor(ctx)
1386
- if ctx.attributeRef()
1387
- visit(ctx.attributeRef())
1388
- elsif ctx.constantFactor()
1389
- visit(ctx.constantFactor())
1390
- elsif ctx.functionCall()
1391
- visit(ctx.functionCall())
1392
- elsif ctx.generalRef()
1393
- visit(ctx.generalRef())
1394
- elsif ctx.population()
1395
- visit(ctx.population().entityRef())
1396
- else
1397
- raise 'Invalid state'
1398
- end
1399
- end
1400
-
1401
- def visitQualifiedAttribute(ctx)
1402
- id = ctx.SELF().text
1403
-
1404
- ref = Model::Ref.new({
1405
- id: id
1406
- })
1407
-
1408
- group_qualifier = visit(ctx.groupQualifier())
1409
- attribute_qualifier = visit(ctx.attributeQualifier())
1410
- qualifiers = [group_qualifier, attribute_qualifier]
1411
-
1412
- Model::Expressions::QualifiedRef.new({
1413
- ref: ref,
1414
- qualifiers: qualifiers
1415
- })
1416
- end
1417
-
1418
- def visitQualifier(ctx)
1419
- if ctx.attributeQualifier()
1420
- visit(ctx.attributeQualifier())
1421
- elsif ctx.groupQualifier()
1422
- visit(ctx.groupQualifier())
1423
- elsif ctx.indexQualifier()
1424
- visit(ctx.indexQualifier())
1425
- else
1426
- raise 'Invalid state'
1427
- end
1428
- end
1429
-
1430
- def visitQueryExpression(ctx)
1431
- id = visit(ctx.variableId())
1432
- source = visit(ctx.aggregateSource().simpleExpression())
1433
- expression = visit(ctx.logicalExpression().expression())
1434
-
1435
- Model::Expressions::Query.new({
1436
- id: id,
1437
- source: source,
1438
- expression: expression
1439
- })
1440
- end
1441
-
1442
- def visitRealType(ctx)
1443
- precision = if ctx.precisionSpec()
1444
- visit(ctx.precisionSpec().numericExpression().simpleExpression())
1445
- end
1446
-
1447
- Model::Types::Real.new({
1448
- precision: precision
1449
- })
1450
- end
1451
-
1452
- def visitRedeclaredAttribute(ctx)
1453
- raise 'Invalid state'
1454
- end
1455
-
1456
- def visitReferencedAttribute(ctx)
1457
- if ctx.attributeRef()
1458
- visit(ctx.attributeRef())
1459
- elsif ctx.qualifiedAttribute()
1460
- visit(ctx.qualifiedAttribute())
1461
- else
1462
- raise 'Invalid state'
1463
- end
1464
- end
1465
-
1466
- def visitReferenceClause(ctx)
1467
- schema = visit(ctx.schemaRef())
1468
- items = ctx.resourceOrRename().map{|ctx| visit(ctx)}
1469
-
1470
- Model::Reference.new({
1471
- schema: schema,
1472
- items: items
1473
- })
1474
- end
1475
-
1476
- def visitRelOp(ctx)
1477
- if ctx.text == '<'
1478
- Model::Operators::LessThan.new()
1479
- elsif ctx.text == '>'
1480
- Model::Operators::GreaterThan.new()
1481
- elsif ctx.text == '<='
1482
- Model::Operators::LessThanOrEqual.new()
1483
- elsif ctx.text == '>='
1484
- Model::Operators::GreaterThanOrEqual.new()
1485
- elsif ctx.text == '<>'
1486
- Model::Operators::NotEqual.new()
1487
- elsif ctx.text == '='
1488
- Model::Operators::Equal.new()
1489
- elsif ctx.text == ':<>:'
1490
- Model::Operators::InstanceNotEqual.new()
1491
- elsif ctx.text == ':=:'
1492
- Model::Operators::InstanceEqual.new()
1493
- else
1494
- raise 'Invalid state'
1495
- end
1496
- end
1497
-
1498
- def visitRelOpExtended(ctx)
1499
- if ctx.relOp()
1500
- visit(ctx.relOp())
1501
- elsif ctx.IN()
1502
- Model::Operators::In.new()
1503
- elsif ctx.LIKE()
1504
- Model::Operators::Like.new()
1505
- else
1506
- raise 'Invalid state'
1507
- end
1508
- end
1509
-
1510
- def visitRenameId(ctx)
1511
- if ctx.constantId()
1512
- visit(ctx.constantId())
1513
- elsif ctx.entityId()
1514
- visit(ctx.entityId())
1515
- elsif ctx.functionId()
1516
- visit(ctx.functionId())
1517
- elsif ctx.procedureId()
1518
- visit(ctx.procedureId())
1519
- elsif ctx.typeId()
1520
- visit(ctx.typeId())
1521
- else
1522
- raise 'Invalid state'
1523
- end
1524
- end
1525
-
1526
- def visitRepeatControl(ctx)
1527
- raise 'Invalid state'
1528
- end
1529
-
1530
- def visitRepeatStmt(ctx)
1531
- id = if ctx.repeatControl().incrementControl()
1532
- visit(ctx.repeatControl().incrementControl().variableId())
1533
- end
1534
- bound1, bound2 = if ctx.repeatControl().incrementControl()
1535
- [
1536
- visit(ctx.repeatControl().incrementControl().bound1().numericExpression().simpleExpression()),
1537
- visit(ctx.repeatControl().incrementControl().bound2().numericExpression().simpleExpression())
1538
- ]
1539
- end
1540
- increment = if ctx.repeatControl().incrementControl() && ctx.repeatControl().incrementControl().increment()
1541
- visit(ctx.repeatControl().incrementControl().increment().numericExpression().simpleExpression())
1542
- end
1543
- while_expression = if ctx.repeatControl().whileControl()
1544
- visit(ctx.repeatControl().whileControl().logicalExpression().expression())
1545
- end
1546
- until_expression = if ctx.repeatControl().untilControl()
1547
- visit(ctx.repeatControl().untilControl().logicalExpression().expression())
1548
- end
1549
- statements = ctx.stmt().map{|ctx| visit(ctx)}
1550
-
1551
- Model::Statements::Repeat.new({
1552
- id: id,
1553
- bound1: bound1,
1554
- bound2: bound2,
1555
- increment: increment,
1556
- while_expression: while_expression,
1557
- until_expression: until_expression,
1558
- statements: statements
1559
- })
1560
- end
1561
-
1562
- def visitRepetition(ctx)
1563
- raise 'Invalid state'
1564
- end
1565
-
1566
- def visitResourceOrRename(ctx)
1567
- if ctx.renameId()
1568
- ref = visit(ctx.resourceRef())
1569
- id = visit(ctx.renameId())
1570
-
1571
- Model::RenamedRef.new({
1572
- ref: ref,
1573
- id: id
1574
- })
1575
- else
1576
- visit(ctx.resourceRef())
1577
- end
1578
- end
1579
-
1580
- def visitResourceRef(ctx)
1581
- if ctx.constantRef()
1582
- visit(ctx.constantRef())
1583
- elsif ctx.entityRef()
1584
- visit(ctx.entityRef())
1585
- elsif ctx.functionRef()
1586
- visit(ctx.functionRef())
1587
- elsif ctx.procedureRef()
1588
- visit(ctx.procedureRef())
1589
- elsif ctx.typeRef()
1590
- visit(ctx.typeRef())
1591
- else
1592
- raise 'Invalid state'
1593
- end
1594
- end
1595
-
1596
- def visitReturnStmt(ctx)
1597
- expression = visit(ctx.expression())
1598
-
1599
- Model::Statements::Return.new({
1600
- expression: expression
1601
- })
1602
- end
1603
-
1604
- def visitRuleDecl(ctx)
1605
- id = visit(ctx.ruleHead().ruleId())
1606
- applies_to = ctx.ruleHead().entityRef().map{|ctx| visit(ctx)}
1607
- declarations = ctx.algorithmHead().declaration().map{|ctx| visit(ctx)}
1608
- constants = if ctx.algorithmHead().constantDecl()
1609
- ctx.algorithmHead().constantDecl().constantBody().map{|ctx| visit(ctx)}
1610
- end
1611
- locals = if ctx.algorithmHead().localDecl()
1612
- ctx.algorithmHead().localDecl().localVariable().map{|ctx| visit(ctx)}.flatten
1613
- end
1614
- where = ctx.whereClause().domainRule().map{|ctx| visit(ctx)}
1615
- statements = ctx.stmt().map{|ctx| visit(ctx)}
1616
-
1617
- Model::Rule.new({
1618
- id: id,
1619
- applies_to: applies_to,
1620
- declarations: declarations,
1621
- constants: constants,
1622
- locals: locals,
1623
- where: where,
1624
- statements: statements
1625
- })
1626
- end
1627
-
1628
- def visitRuleHead(ctx)
1629
- raise 'Invalid state'
1630
- end
1631
-
1632
- def visitRuleId(ctx)
1633
- handleSimpleId(ctx.SimpleId())
1634
- end
1635
-
1636
- def visitRuleLabelId(ctx)
1637
- handleSimpleId(ctx.SimpleId())
1638
- end
1639
-
1640
- def visitSchemaBody(ctx)
1641
- raise 'Invalid state'
1642
- end
1643
-
1644
- def visitSchemaDecl(ctx)
1645
- id = visit(ctx.schemaId())
1646
- version = if ctx.schemaVersionId()
1647
- visit(ctx.schemaVersionId().stringLiteral())
1648
- end
1649
- interfaces = ctx.schemaBody().interfaceSpecification().map{|ctx| visit(ctx)}
1650
- constants = if ctx.schemaBody().constantDecl()
1651
- ctx.schemaBody().constantDecl().constantBody().map{|ctx| visit(ctx)}
1652
- end
1653
- declarations = ctx.schemaBody().declaration().map{|ctx| visit(ctx)}
1654
- rules = ctx.schemaBody().ruleDecl().map{|ctx| visit(ctx)}
1655
-
1656
- Model::Schema.new({
1657
- id: id,
1658
- version: version,
1659
- interfaces: interfaces,
1660
- constants: constants,
1661
- declarations: declarations,
1662
- rules: rules
1663
- })
1664
- end
1665
-
1666
- def visitSchemaId(ctx)
1667
- handleSimpleId(ctx.SimpleId())
1668
- end
1669
-
1670
- def visitSchemaVersionId(ctx)
1671
- raise 'Invalid state'
1672
- end
1673
-
1674
- def visitSelector(ctx)
1675
- raise 'Invalid state'
1676
- end
1677
-
1678
- def visitSelectExtension(ctx)
1679
- raise 'Invalid state'
1680
- end
1681
-
1682
- def visitSelectList(ctx)
1683
- raise 'Invalid state'
1684
- end
1685
-
1686
- def visitSelectType(ctx)
1687
- extensible = !!ctx.EXTENSIBLE()
1688
- generic_entity = !!ctx.GENERIC_ENTITY()
1689
- items = if ctx.selectList()
1690
- ctx.selectList().namedTypes().map{|ctx| visit(ctx)}
1691
- end
1692
- extension_type = if ctx.selectExtension()
1693
- visit(ctx.selectExtension().typeRef())
1694
- end
1695
- extension_items = if ctx.selectExtension() && ctx.selectExtension().selectList()
1696
- ctx.selectExtension().selectList().namedTypes().map{|ctx| visit(ctx)}
1697
- end
1698
-
1699
- Model::Types::Select.new({
1700
- extensible: extensible,
1701
- generic_entity: generic_entity,
1702
- items: items,
1703
- extension_type: extension_type,
1704
- extension_items: extension_items
1705
- })
1706
- end
1707
-
1708
- def visitSetType(ctx)
1709
- bound1, bound2 = if ctx.boundSpec()
1710
- [
1711
- visit(ctx.boundSpec().bound1().numericExpression().simpleExpression()),
1712
- visit(ctx.boundSpec().bound2().numericExpression().simpleExpression())
1713
- ]
1714
- end
1715
- base_type = visit(ctx.instantiableType())
1716
-
1717
- Model::Types::Set.new({
1718
- bound1: bound1,
1719
- bound2: bound2,
1720
- base_type: base_type
1721
- })
1722
- end
1723
-
1724
- def visitSimpleExpression(ctx)
1725
- if ctx.term().length >= 2
1726
- operands = ctx.term().map{|ctx| visit(ctx)}
1727
- operators = ctx.addLikeOp().map{|ctx| visit(ctx)}
1728
-
1729
- handleBinaryExpression(operands, operators)
1730
- else
1731
- visit(ctx.term()[0])
1732
- end
1733
- end
1734
-
1735
- def visitSimpleFactor(ctx)
1736
- if ctx.aggregateInitializer()
1737
- visit(ctx.aggregateInitializer())
1738
- elsif ctx.entityConstructor()
1739
- visit(ctx.entityConstructor())
1740
- elsif ctx.enumerationReference()
1741
- visit(ctx.enumerationReference())
1742
- elsif ctx.interval()
1743
- visit(ctx.interval())
1744
- elsif ctx.queryExpression()
1745
- visit(ctx.queryExpression())
1746
- elsif !ctx.unaryOp() && ctx.expression()
1747
- visit(ctx.expression())
1748
- elsif !ctx.unaryOp() && ctx.primary()
1749
- visit(ctx.primary())
1750
- elsif ctx.unaryOp() && ctx.expression()
1751
- operator = visit(ctx.unaryOp())
1752
- operand = visit(ctx.expression())
1753
-
1754
- Model::Expressions::Expression.new({
1755
- operator: operator,
1756
- operands: [operand]
1757
- })
1758
- elsif ctx.unaryOp() && ctx.primary()
1759
- operator = visit(ctx.unaryOp())
1760
- operand = visit(ctx.primary())
1761
-
1762
- Model::Expressions::Expression.new({
1763
- operator: operator,
1764
- operands: [operand]
1765
- })
1766
- else
1767
- raise 'Invalid state'
1768
- end
1769
- end
1770
-
1771
- def visitSimpleTypes(ctx)
1772
- if ctx.binaryType()
1773
- visit(ctx.binaryType())
1774
- elsif ctx.booleanType()
1775
- visit(ctx.booleanType())
1776
- elsif ctx.integerType()
1777
- visit(ctx.integerType())
1778
- elsif ctx.logicalType()
1779
- visit(ctx.logicalType())
1780
- elsif ctx.numberType()
1781
- visit(ctx.numberType())
1782
- elsif ctx.realType()
1783
- visit(ctx.realType())
1784
- elsif ctx.stringType()
1785
- visit(ctx.stringType())
1786
- else
1787
- raise 'Invalid state'
1788
- end
1789
- end
1790
-
1791
- def visitSkipStmt(ctx)
1792
- Model::Statements::Skip.new()
1793
- end
1794
-
1795
- def visitStmt(ctx)
1796
- if ctx.aliasStmt()
1797
- visit(ctx.aliasStmt())
1798
- elsif ctx.assignmentStmt()
1799
- visit(ctx.assignmentStmt())
1800
- elsif ctx.caseStmt()
1801
- visit(ctx.caseStmt())
1802
- elsif ctx.compoundStmt()
1803
- visit(ctx.compoundStmt())
1804
- elsif ctx.escapeStmt()
1805
- visit(ctx.escapeStmt())
1806
- elsif ctx.ifStmt()
1807
- visit(ctx.ifStmt())
1808
- elsif ctx.nullStmt()
1809
- visit(ctx.nullStmt())
1810
- elsif ctx.procedureCallStmt()
1811
- visit(ctx.procedureCallStmt())
1812
- elsif ctx.repeatStmt()
1813
- visit(ctx.repeatStmt())
1814
- elsif ctx.returnStmt()
1815
- visit(ctx.returnStmt())
1816
- elsif ctx.skipStmt()
1817
- visit(ctx.skipStmt())
1818
- else
1819
- raise 'Invalid state'
1820
- end
1821
- end
1822
-
1823
- def visitStringLiteral(ctx)
1824
- if ctx.SimpleStringLiteral()
1825
- handleSimpleStringLiteral(ctx.SimpleStringLiteral())
1826
- elsif ctx.EncodedStringLiteral()
1827
- handleEncodedStringLiteral(ctx.EncodedStringLiteral())
1828
- else
1829
- raise 'Invalid state'
1830
- end
1831
- end
1832
-
1833
- def visitStringType(ctx)
1834
- width = if ctx.widthSpec()
1835
- visit(ctx.widthSpec().width().numericExpression().simpleExpression())
1836
- end
1837
- fixed = if ctx.widthSpec()
1838
- !!ctx.widthSpec().FIXED()
1839
- end
1840
-
1841
- Model::Types::String.new({
1842
- width: width,
1843
- fixed: fixed
1844
- })
1845
- end
1846
-
1847
- def visitSubsuper(ctx)
1848
- raise 'Invalid state'
1849
- end
1850
-
1851
- def visitSubtypeConstraint(ctx)
1852
- raise 'Invalid state'
1853
- end
1854
-
1855
- def visitSubtypeConstraintBody(ctx)
1856
- raise 'Invalid state'
1857
- end
1858
-
1859
- def visitSubtypeConstraintDecl(ctx)
1860
- id = visit(ctx.subtypeConstraintHead().subtypeConstraintId())
1861
- applies_to = visit(ctx.subtypeConstraintHead().entityRef())
1862
- abstract_supertype = !!ctx.subtypeConstraintBody().abstractSupertype()
1863
- total_over = if ctx.subtypeConstraintBody().totalOver()
1864
- ctx.subtypeConstraintBody().totalOver().entityRef().map{|ctx| visit(ctx)}
1865
- end
1866
- subtype_expression = if ctx.subtypeConstraintBody().supertypeExpression()
1867
- visit(ctx.subtypeConstraintBody().supertypeExpression())
1868
- end
1869
-
1870
- Model::SubtypeConstraint.new({
1871
- id: id,
1872
- applies_to: applies_to,
1873
- abstract_supertype: abstract_supertype,
1874
- total_over: total_over,
1875
- subtype_expression: subtype_expression
1876
- })
1877
- end
1878
-
1879
- def visitSubtypeConstraintHead(ctx)
1880
- raise 'Invalid state'
1881
- end
1882
-
1883
- def visitSubtypeConstraintId(ctx)
1884
- handleSimpleId(ctx.SimpleId())
1885
- end
1886
-
1887
- def visitSubtypeDeclaration(ctx)
1888
- raise 'Invalid state'
1889
- end
1890
-
1891
- def visitSupertypeConstraint(ctx)
1892
- raise 'Invalid state'
1893
- end
1894
-
1895
- def visitSupertypeExpression(ctx)
1896
- if ctx.supertypeFactor().length >= 2
1897
- operands = ctx.supertypeFactor().map{|ctx| visit(ctx)}
1898
- operators = ctx.ANDOR().map{|ctx| Model::Operators::Andor.new()}
1899
-
1900
- handleBinaryExpression(operands, operators)
1901
- else
1902
- visit(ctx.supertypeFactor()[0])
1903
- end
1904
- end
1905
-
1906
- def visitSupertypeFactor(ctx)
1907
- if ctx.supertypeTerm().length >= 2
1908
- operands = ctx.supertypeTerm().map{|ctx| visit(ctx)}
1909
- operators = ctx.AND().map{|ctx| Model::Operators::And.new()}
1910
-
1911
- handleBinaryExpression(operands, operators)
1912
- else
1913
- visit(ctx.supertypeTerm()[0])
1914
- end
1915
- end
1916
-
1917
- def visitSupertypeRule(ctx)
1918
- raise 'Invalid state'
1919
- end
1920
-
1921
- def visitSupertypeTerm(ctx)
1922
- if ctx.entityRef()
1923
- visit(ctx.entityRef())
1924
- elsif ctx.oneOf()
1925
- visit(ctx.oneOf())
1926
- elsif ctx.supertypeExpression()
1927
- visit(ctx.supertypeExpression())
1928
- else
1929
- raise 'Invalid state'
1930
- end
1931
- end
1932
-
1933
- def visitSyntax(ctx)
1934
- schemas = ctx.schemaDecl().map{|ctx| visit(ctx)}
1935
-
1936
- Model::Repository.new({
1937
- schemas: schemas
1938
- })
1939
- end
1940
-
1941
- def visitTerm(ctx)
1942
- if ctx.factor().length >= 2
1943
- operands = ctx.factor().map{|ctx| visit(ctx)}
1944
- operators = ctx.multiplicationLikeOp().map{|ctx| visit(ctx)}
1945
-
1946
- handleBinaryExpression(operands, operators)
1947
- else
1948
- visit(ctx.factor()[0])
1949
- end
1950
- end
1951
-
1952
- def visitTotalOver(ctx)
1953
- raise 'Invalid state'
1954
- end
1955
-
1956
- def visitTypeDecl(ctx)
1957
- id = visit(ctx.typeId())
1958
- type = visit(ctx.underlyingType())
1959
- where = if ctx.whereClause()
1960
- ctx.whereClause().domainRule().map{|ctx| visit(ctx)}
1961
- end
1962
-
1963
- Model::Type.new({
1964
- id: id,
1965
- type: type,
1966
- where: where
1967
- })
1968
- end
1969
-
1970
- def visitTypeId(ctx)
1971
- handleSimpleId(ctx.SimpleId())
1972
- end
1973
-
1974
- def visitTypeLabel(ctx)
1975
- if ctx.typeLabelId()
1976
- visit(ctx.typeLabelId())
1977
- elsif ctx.typeLabelRef()
1978
- visit(ctx.typeLabelRef())
1979
- else
1980
- raise 'Invalid state'
1981
- end
1982
- end
1983
-
1984
- def visitTypeLabelId(ctx)
1985
- handleSimpleId(ctx.SimpleId())
1986
- end
1987
-
1988
- def visitUnaryOp(ctx)
1989
- if ctx.text == '+'
1990
- Model::Operators::UnaryPlus.new()
1991
- elsif ctx.text == '-'
1992
- Model::Operators::UnaryMinus.new()
1993
- elsif ctx.NOT()
1994
- Model::Operators::Not.new()
1995
- else
1996
- raise 'Invalid state'
1997
- end
1998
- end
1999
-
2000
- def visitUnderlyingType(ctx)
2001
- if ctx.concreteTypes()
2002
- visit(ctx.concreteTypes())
2003
- elsif ctx.constructedTypes()
2004
- visit(ctx.constructedTypes())
2005
- else
2006
- raise 'Invalid state'
2007
- end
2008
- end
2009
-
2010
- def visitUniqueClause(ctx)
2011
- raise 'Invalid state'
2012
- end
2013
-
2014
- def visitUniqueRule(ctx)
2015
- id = if ctx.ruleLabelId()
2016
- visit(ctx.ruleLabelId())
2017
- end
2018
- attributes = ctx.referencedAttribute().map{|ctx| visit(ctx)}
2019
-
2020
- Model::Unique.new({
2021
- id: id,
2022
- attributes: attributes
2023
- })
2024
- end
2025
-
2026
- def visitUntilControl(ctx)
2027
- raise 'Invalid state'
2028
- end
2029
-
2030
- def visitUseClause(ctx)
2031
- schema = visit(ctx.schemaRef())
2032
- items = ctx.namedTypeOrRename().map{|ctx| visit(ctx)}
2033
-
2034
- Model::Use.new({
2035
- schema: schema,
2036
- items: items
2037
- })
2038
- end
2039
-
2040
- def visitVariableId(ctx)
2041
- handleSimpleId(ctx.SimpleId())
2042
- end
2043
-
2044
- def visitWhereClause(ctx)
2045
- raise 'Invalid state'
2046
- end
2047
-
2048
- def visitWhileControl(ctx)
2049
- raise 'Invalid state'
2050
- end
2051
-
2052
- def visitWidth(ctx)
2053
- raise 'Invalid state'
2054
- end
2055
-
2056
- def visitWidthSpec(ctx)
2057
- raise 'Invalid state'
2058
- end
2059
-
2060
- private
2061
-
2062
- def handleEnumerationItem(ctx)
2063
- id = handleSimpleId(ctx.SimpleId())
2064
-
2065
- Model::EnumerationItem.new({
2066
- id: id
2067
- })
2068
- end
2069
-
2070
- def handleBinaryExpression(operands, operators)
2071
- if operands.length != operators.length + 1
2072
- raise 'Invalid state'
2073
- end
2074
-
2075
- expression = Model::Expressions::Expression.new({
2076
- operator: operators[0],
2077
- operands: [operands[0], operands[1]]
2078
- })
2079
- operators[1..(operators.length - 1)].each_with_index do |operator, i|
2080
- expression = Model::Expressions::Expression.new({
2081
- operator: operator,
2082
- operands: [expression, operands[i + 2]]
2083
- })
2084
- end
2085
- expression
2086
- end
2087
-
2088
- def handleBinaryLiteral(ctx)
2089
- value = ctx.text[1..(ctx.text.length - 1)]
2090
-
2091
- Model::Literals::Binary.new({
2092
- value: value
2093
- })
2094
- end
2095
-
2096
- def handleIntegerLiteral(ctx)
2097
- value = ctx.text
2098
-
2099
- Model::Literals::Integer.new({
2100
- value: value
2101
- })
2102
- end
2103
-
2104
- def handleRealLiteral(ctx)
2105
- value = ctx.text
2106
-
2107
- Model::Literals::Real.new({
2108
- value: value
2109
- })
2110
- end
2111
-
2112
- def handleSimpleId(ctx)
2113
- ctx.text
2114
- end
2115
-
2116
- def handleSimpleStringLiteral(ctx)
2117
- value = ctx.text[1..(ctx.text.length - 2)]
2118
-
2119
- Model::Literals::String.new({
2120
- value: value
2121
- })
2122
- end
2123
-
2124
- def handleEncodedStringLiteral(ctx)
2125
- value = ctx.text[1..(ctx.text.length - 2)]
2126
-
2127
- Model::Literals::String.new({
2128
- value: value,
2129
- encoded: true
2130
- })
2131
- end
2132
- end
2133
- end
1
+ require 'express_parser'
2
+ require 'expressir/model'
3
+
4
+ # static shorthands are unwrapped
5
+ # - entity attributes, function/procedure parameters, local variables
6
+ #
7
+ # reference type is not recognized
8
+ # see note in A.1.5 Interpreted identifiers
9
+ # > It is expected that identifiers matching these syntax rules are known to an implementation.
10
+ # > How the implementation obtains this information is of no concern to the definition of the language. One
11
+ # > method of gaining this information is multi-pass parsing: the first pass collects the identifiers from their
12
+ # > declarations, so that subsequent passes are then able to distinguish a veriable_ref from a function_ref,
13
+ # > for example.
14
+ #
15
+ # - xxxRef - merged to SimpleReference
16
+ # - entityConstructor, functionCall - merged to Call
17
+ #
18
+ # difference between generalized and instantiable types is not recognized
19
+ # see note in 8.6.2 Parameter data types
20
+ # > A syntactic construct such as ARRAY[1:3] OF REAL satisfies two syntactic productions —
21
+ # > aggregation_type and general_aggregation_type. It is considered to be instantiable no matter which
22
+ # > production it is required to satisfy in the syntax.
23
+
24
+ module Expressir
25
+ module ExpressExp
26
+ class Visitor < ::ExpressParser::Visitor
27
+ REMARK_CHANNEL = 2
28
+
29
+ def initialize(tokens)
30
+ @tokens = tokens
31
+ @attached_remarks = Set.new
32
+
33
+ super()
34
+ end
35
+
36
+ def visit(ctx)
37
+ result = super(ctx)
38
+ attach_parent(ctx, result)
39
+ attach_remarks(ctx, result)
40
+ result
41
+ end
42
+
43
+ def visit_if(ctx)
44
+ visit(ctx) if ctx
45
+ end
46
+
47
+ def visit_if_map(ctx)
48
+ ctx.map{|ctx2| visit(ctx2)} if ctx
49
+ end
50
+
51
+ def visit_if_map_flatten(ctx)
52
+ ctx.map{|ctx2| visit(ctx2)}.flatten if ctx
53
+ end
54
+
55
+ def attach_parent(ctx, node)
56
+ if node.class.method_defined? :children
57
+ node.children.each do |child_node|
58
+ if child_node.class.method_defined? :parent
59
+ child_node.parent = node
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ def attach_remarks(ctx, node)
66
+ # get remark tokens
67
+ start_index, stop_index = if ctx.instance_of? ::ExpressParser::SyntaxContext
68
+ [0, @tokens.size - 1]
69
+ else
70
+ [ctx.start.token_index, ctx.stop.token_index]
71
+ end
72
+ # puts [start_index, stop_index, ctx.class].inspect
73
+
74
+ remark_tokens = @tokens[start_index..stop_index].select{|x| x.channel == REMARK_CHANNEL}
75
+ if remark_tokens
76
+ remark_tokens.each do |remark_token|
77
+ remark_text = remark_token.text
78
+
79
+ # check if it is tagged remark
80
+ match = if remark_text.start_with?('--')
81
+ remark_text[2..-1].match(/^"([^"]*)"(.*)$/)
82
+ elsif remark_text.start_with?('(*') and remark_text.end_with?('*)')
83
+ remark_text[2..-3].match(/^"([^"]*)"(.*)$/m)
84
+ end
85
+ if !match
86
+ next
87
+ end
88
+
89
+ # don't attach already attached tagged remark
90
+ if @attached_remarks.include? remark_token
91
+ next
92
+ end
93
+
94
+ # attach tagged remark
95
+ remark_tag = match[1]
96
+ remark_content = match[2].strip
97
+
98
+ target_node = nil
99
+ current_node = node
100
+ if current_node.class.method_defined? :find
101
+ target_node = current_node.find(remark_tag)
102
+ end
103
+ while !target_node and current_node.class.method_defined? :parent and current_node.parent.class.method_defined? :find
104
+ current_node = current_node.parent
105
+ target_node = current_node.find(remark_tag)
106
+ end
107
+
108
+ if target_node
109
+ target_node.remarks ||= []
110
+ target_node.remarks << remark_content
111
+
112
+ # mark remark as attached, so that it is not attached again at higher nesting level
113
+ @attached_remarks << remark_token
114
+ end
115
+ end
116
+ end
117
+ end
118
+
119
+ def visit_attribute_ref(ctx)
120
+ ctx__attribute_id = ctx.attribute_id
121
+
122
+ id = visit_if(ctx__attribute_id)
123
+
124
+ Model::Expressions::SimpleReference.new({
125
+ id: id
126
+ })
127
+ end
128
+
129
+ def visit_constant_ref(ctx)
130
+ ctx__constant_id = ctx.constant_id
131
+
132
+ id = visit_if(ctx__constant_id)
133
+
134
+ Model::Expressions::SimpleReference.new({
135
+ id: id
136
+ })
137
+ end
138
+
139
+ def visit_entity_ref(ctx)
140
+ ctx__entity_id = ctx.entity_id
141
+
142
+ id = visit_if(ctx__entity_id)
143
+
144
+ Model::Expressions::SimpleReference.new({
145
+ id: id
146
+ })
147
+ end
148
+
149
+ def visit_enumeration_ref(ctx)
150
+ ctx__enumeration_id = ctx.enumeration_id
151
+
152
+ id = visit_if(ctx__enumeration_id)
153
+
154
+ Model::Expressions::SimpleReference.new({
155
+ id: id
156
+ })
157
+ end
158
+
159
+ def visit_function_ref(ctx)
160
+ ctx__function_id = ctx.function_id
161
+
162
+ id = visit_if(ctx__function_id)
163
+
164
+ Model::Expressions::SimpleReference.new({
165
+ id: id
166
+ })
167
+ end
168
+
169
+ def visit_parameter_ref(ctx)
170
+ ctx__parameter_id = ctx.parameter_id
171
+
172
+ id = visit_if(ctx__parameter_id)
173
+
174
+ Model::Expressions::SimpleReference.new({
175
+ id: id
176
+ })
177
+ end
178
+
179
+ def visit_procedure_ref(ctx)
180
+ ctx__procedure_id = ctx.procedure_id
181
+
182
+ id = visit_if(ctx__procedure_id)
183
+
184
+ Model::Expressions::SimpleReference.new({
185
+ id: id
186
+ })
187
+ end
188
+
189
+ def visit_rule_label_ref(ctx)
190
+ ctx__rule_label_id = ctx.rule_label_id
191
+
192
+ id = visit_if(ctx__rule_label_id)
193
+
194
+ Model::Expressions::SimpleReference.new({
195
+ id: id
196
+ })
197
+ end
198
+
199
+ def visit_rule_ref(ctx)
200
+ ctx__rule_id = ctx.rule_id
201
+
202
+ id = visit_if(ctx__rule_id)
203
+
204
+ Model::Expressions::SimpleReference.new({
205
+ id: id
206
+ })
207
+ end
208
+
209
+ def visit_schema_ref(ctx)
210
+ ctx__schema_id = ctx.schema_id
211
+
212
+ id = visit_if(ctx__schema_id)
213
+
214
+ Model::Expressions::SimpleReference.new({
215
+ id: id
216
+ })
217
+ end
218
+
219
+ def visit_subtype_constraint_ref(ctx)
220
+ ctx__subtype_constraint_id = ctx.subtype_constraint_id
221
+
222
+ id = visit_if(ctx__subtype_constraint_id)
223
+
224
+ Model::Expressions::SimpleReference.new({
225
+ id: id
226
+ })
227
+ end
228
+
229
+ def visit_type_label_ref(ctx)
230
+ ctx__type_label_id = ctx.type_label_id
231
+
232
+ id = visit_if(ctx__type_label_id)
233
+
234
+ Model::Expressions::SimpleReference.new({
235
+ id: id
236
+ })
237
+ end
238
+
239
+ def visit_type_ref(ctx)
240
+ ctx__type_id = ctx.type_id
241
+
242
+ id = visit_if(ctx__type_id)
243
+
244
+ Model::Expressions::SimpleReference.new({
245
+ id: id
246
+ })
247
+ end
248
+
249
+ def visit_variable_ref(ctx)
250
+ ctx__variable_id = ctx.variable_id
251
+
252
+ id = visit_if(ctx__variable_id)
253
+
254
+ Model::Expressions::SimpleReference.new({
255
+ id: id
256
+ })
257
+ end
258
+
259
+ def visit_abstract_entity_declaration(ctx)
260
+ raise 'Invalid state'
261
+ end
262
+
263
+ def visit_abstract_supertype(ctx)
264
+ raise 'Invalid state'
265
+ end
266
+
267
+ def visit_abstract_supertype_declaration(ctx)
268
+ ctx__subtype_constraint = ctx.subtype_constraint
269
+
270
+ visit_if(ctx__subtype_constraint)
271
+ end
272
+
273
+ def visit_actual_parameter_list(ctx)
274
+ ctx__parameter = ctx.parameter
275
+
276
+ visit_if_map(ctx__parameter)
277
+ end
278
+
279
+ def visit_add_like_op(ctx)
280
+ ctx__text = ctx.text
281
+ ctx__ADDITION = ctx__text == '+'
282
+ ctx__SUBTRACTION = ctx__text == '-'
283
+ ctx__OR = ctx.OR
284
+ ctx__XOR = ctx.XOR
285
+
286
+ if ctx__ADDITION
287
+ Model::Expressions::BinaryExpression::ADDITION
288
+ elsif ctx__SUBTRACTION
289
+ Model::Expressions::BinaryExpression::SUBTRACTION
290
+ elsif ctx__OR
291
+ Model::Expressions::BinaryExpression::OR
292
+ elsif ctx__XOR
293
+ Model::Expressions::BinaryExpression::XOR
294
+ else
295
+ raise 'Invalid state'
296
+ end
297
+ end
298
+
299
+ def visit_aggregate_initializer(ctx)
300
+ ctx__element = ctx.element
301
+
302
+ items = visit_if_map(ctx__element)
303
+
304
+ Model::Expressions::AggregateInitializer.new({
305
+ items: items
306
+ })
307
+ end
308
+
309
+ def visit_aggregate_source(ctx)
310
+ ctx__simple_expression = ctx.simple_expression
311
+
312
+ visit_if(ctx__simple_expression)
313
+ end
314
+
315
+ def visit_aggregate_type(ctx)
316
+ ctx__type_label = ctx.type_label
317
+ ctx__parameter_type = ctx.parameter_type
318
+
319
+ id = visit_if(ctx__type_label)
320
+ base_type = visit_if(ctx__parameter_type)
321
+
322
+ Model::Types::Aggregate.new({
323
+ id: id,
324
+ base_type: base_type
325
+ })
326
+ end
327
+
328
+ def visit_aggregation_types(ctx)
329
+ ctx__array_type = ctx.array_type
330
+ ctx__bag_type = ctx.bag_type
331
+ ctx__list_type = ctx.list_type
332
+ ctx__set_type = ctx.set_type
333
+
334
+ visit_if(ctx__array_type || ctx__bag_type || ctx__list_type || ctx__set_type)
335
+ end
336
+
337
+ def visit_algorithm_head(ctx)
338
+ raise 'Invalid state'
339
+ end
340
+
341
+ def visit_alias_stmt(ctx)
342
+ ctx__variable_id = ctx.variable_id
343
+ ctx__general_ref = ctx.general_ref
344
+ ctx__qualifier = ctx.qualifier
345
+ ctx__stmt = ctx.stmt
346
+
347
+ id = visit_if(ctx__variable_id)
348
+ expression = handle_qualified_ref(visit_if(ctx__general_ref), ctx__qualifier)
349
+ statements = visit_if_map(ctx__stmt)
350
+
351
+ Model::Statements::Alias.new({
352
+ id: id,
353
+ expression: expression,
354
+ statements: statements
355
+ })
356
+ end
357
+
358
+ def visit_array_type(ctx)
359
+ ctx__bound_spec = ctx.bound_spec
360
+ ctx__OPTIONAL = ctx.OPTIONAL
361
+ ctx__UNIQUE = ctx.UNIQUE
362
+ ctx__instantiable_type = ctx.instantiable_type
363
+ ctx__bound_spec__bound1 = ctx__bound_spec&.bound1
364
+ ctx__bound_spec__bound2 = ctx__bound_spec&.bound2
365
+
366
+ bound1 = visit_if(ctx__bound_spec__bound1)
367
+ bound2 = visit_if(ctx__bound_spec__bound2)
368
+ optional = !!ctx__OPTIONAL
369
+ unique = !!ctx__UNIQUE
370
+ base_type = visit_if(ctx__instantiable_type)
371
+
372
+ Model::Types::Array.new({
373
+ bound1: bound1,
374
+ bound2: bound2,
375
+ optional: optional,
376
+ unique: unique,
377
+ base_type: base_type
378
+ })
379
+ end
380
+
381
+ def visit_assignment_stmt(ctx)
382
+ ctx__general_ref = ctx.general_ref
383
+ ctx__qualifier = ctx.qualifier
384
+ ctx__expression = ctx.expression
385
+
386
+ ref = handle_qualified_ref(visit_if(ctx__general_ref), ctx__qualifier)
387
+ expression = visit_if(ctx__expression)
388
+
389
+ Model::Statements::Assignment.new({
390
+ ref: ref,
391
+ expression: expression
392
+ })
393
+ end
394
+
395
+ def visit_attribute_decl(ctx)
396
+ ctx__attribute_id = ctx.attribute_id
397
+ ctx__redeclared_attribute = ctx.redeclared_attribute
398
+ ctx__redeclared_attribute__qualified_attribute = ctx__redeclared_attribute&.qualified_attribute
399
+ ctx__redeclared_attribute__attribute_id = ctx__redeclared_attribute&.attribute_id
400
+
401
+ id = visit_if(ctx__attribute_id || ctx__redeclared_attribute__attribute_id)
402
+ supertype_attribute = visit_if(ctx__redeclared_attribute__qualified_attribute)
403
+
404
+ Model::Attribute.new({
405
+ id: id,
406
+ supertype_attribute: supertype_attribute
407
+ })
408
+ end
409
+
410
+ def visit_attribute_id(ctx)
411
+ ctx__SimpleId = ctx.SimpleId
412
+
413
+ handle_simple_id(ctx__SimpleId)
414
+ end
415
+
416
+ def visit_attribute_qualifier(ctx)
417
+ ctx__attribute_ref = ctx.attribute_ref
418
+
419
+ attribute = visit_if(ctx__attribute_ref)
420
+
421
+ Model::Expressions::AttributeReference.new({
422
+ attribute: attribute
423
+ })
424
+ end
425
+
426
+ def visit_attribute_reference(ctx)
427
+ raise 'Invalid state'
428
+ end
429
+
430
+ def visit_bag_type(ctx)
431
+ ctx__bound_spec = ctx.bound_spec
432
+ ctx__instantiable_type = ctx.instantiable_type
433
+ ctx__bound_spec__bound1 = ctx__bound_spec&.bound1
434
+ ctx__bound_spec__bound2 = ctx__bound_spec&.bound2
435
+
436
+ bound1 = visit_if(ctx__bound_spec__bound1)
437
+ bound2 = visit_if(ctx__bound_spec__bound2)
438
+ base_type = visit_if(ctx__instantiable_type)
439
+
440
+ Model::Types::Bag.new({
441
+ bound1: bound1,
442
+ bound2: bound2,
443
+ base_type: base_type
444
+ })
445
+ end
446
+
447
+ def visit_binary_type(ctx)
448
+ ctx__width_spec = ctx.width_spec
449
+ ctx__width_spec__width = ctx__width_spec&.width
450
+ ctx__width_spec__FIXED = ctx__width_spec&.FIXED
451
+
452
+ width = visit_if(ctx__width_spec__width)
453
+ fixed = !!ctx__width_spec__FIXED
454
+
455
+ Model::Types::Binary.new({
456
+ width: width,
457
+ fixed: fixed
458
+ })
459
+ end
460
+
461
+ def visit_boolean_type(ctx)
462
+ Model::Types::Boolean.new
463
+ end
464
+
465
+ def visit_bound1(ctx)
466
+ ctx__numeric_expression = ctx.numeric_expression
467
+
468
+ visit_if(ctx__numeric_expression)
469
+ end
470
+
471
+ def visit_bound2(ctx)
472
+ ctx__numeric_expression = ctx.numeric_expression
473
+
474
+ visit_if(ctx__numeric_expression)
475
+ end
476
+
477
+ def visit_bound_spec(ctx)
478
+ raise 'Invalid state'
479
+ end
480
+
481
+ def visit_built_in_constant(ctx)
482
+ ctx__text = ctx.text
483
+
484
+ id = ctx__text
485
+
486
+ Model::Expressions::SimpleReference.new({
487
+ id: id
488
+ })
489
+ end
490
+
491
+ def visit_built_in_function(ctx)
492
+ ctx__text = ctx.text
493
+
494
+ id = ctx__text
495
+
496
+ Model::Expressions::SimpleReference.new({
497
+ id: id
498
+ })
499
+ end
500
+
501
+ def visit_built_in_procedure(ctx)
502
+ ctx__text = ctx.text
503
+
504
+ id = ctx__text
505
+
506
+ Model::Expressions::SimpleReference.new({
507
+ id: id
508
+ })
509
+ end
510
+
511
+ def visit_case_action(ctx)
512
+ ctx__case_label = ctx.case_label
513
+ ctx__stmt = ctx.stmt
514
+
515
+ labels = visit_if_map(ctx__case_label)
516
+ statement = visit_if(ctx__stmt)
517
+
518
+ Model::Statements::CaseAction.new({
519
+ labels: labels,
520
+ statement: statement
521
+ })
522
+ end
523
+
524
+ def visit_case_label(ctx)
525
+ ctx__expression = ctx.expression
526
+
527
+ visit_if(ctx__expression)
528
+ end
529
+
530
+ def visit_case_stmt(ctx)
531
+ ctx__selector = ctx.selector
532
+ ctx__case_action = ctx.case_action
533
+ ctx__stmt = ctx.stmt
534
+ ctx__selector__expression = ctx__selector&.expression
535
+
536
+ expression = visit_if(ctx__selector__expression)
537
+ actions = visit_if_map_flatten(ctx__case_action)
538
+ otherwise_statement = visit_if(ctx__stmt)
539
+
540
+ Model::Statements::Case.new({
541
+ expression: expression,
542
+ actions: actions,
543
+ otherwise_statement: otherwise_statement
544
+ })
545
+ end
546
+
547
+ def visit_compound_stmt(ctx)
548
+ ctx__stmt = ctx.stmt
549
+
550
+ statements = visit_if_map(ctx__stmt)
551
+
552
+ Model::Statements::Compound.new({
553
+ statements: statements
554
+ })
555
+ end
556
+
557
+ def visit_concrete_types(ctx)
558
+ ctx__aggregation_types = ctx.aggregation_types
559
+ ctx__simple_types = ctx.simple_types
560
+ ctx__type_ref = ctx.type_ref
561
+
562
+ visit_if(ctx__aggregation_types || ctx__simple_types || ctx__type_ref)
563
+ end
564
+
565
+ def visit_constant_body(ctx)
566
+ ctx__constant_id = ctx.constant_id
567
+ ctx__instantiable_type = ctx.instantiable_type
568
+ ctx__expression = ctx.expression
569
+
570
+ id = visit_if(ctx__constant_id)
571
+ type = visit_if(ctx__instantiable_type)
572
+ expression = visit_if(ctx__expression)
573
+
574
+ Model::Constant.new({
575
+ id: id,
576
+ type: type,
577
+ expression: expression
578
+ })
579
+ end
580
+
581
+ def visit_constant_decl(ctx)
582
+ ctx__constant_body = ctx.constant_body
583
+
584
+ visit_if_map(ctx__constant_body)
585
+ end
586
+
587
+ def visit_constant_factor(ctx)
588
+ ctx__built_in_constant = ctx.built_in_constant
589
+ ctx__constant_ref = ctx.constant_ref
590
+
591
+ visit_if(ctx__built_in_constant || ctx__constant_ref)
592
+ end
593
+
594
+ def visit_constant_id(ctx)
595
+ ctx__SimpleId = ctx.SimpleId
596
+
597
+ handle_simple_id(ctx__SimpleId)
598
+ end
599
+
600
+ def visit_constructed_types(ctx)
601
+ ctx__enumeration_type = ctx.enumeration_type
602
+ ctx__select_type = ctx.select_type
603
+
604
+ visit_if(ctx__enumeration_type || ctx__select_type)
605
+ end
606
+
607
+ def visit_declaration(ctx)
608
+ ctx__entity_decl = ctx.entity_decl
609
+ ctx__function_decl = ctx.function_decl
610
+ ctx__procedure_decl = ctx.procedure_decl
611
+ ctx__subtype_constraint_decl = ctx.subtype_constraint_decl
612
+ ctx__type_decl = ctx.type_decl
613
+
614
+ visit_if(ctx__entity_decl || ctx__function_decl || ctx__procedure_decl || ctx__subtype_constraint_decl || ctx__type_decl)
615
+ end
616
+
617
+ def visit_derived_attr(ctx)
618
+ ctx__attribute_decl = ctx.attribute_decl
619
+ ctx__parameter_type = ctx.parameter_type
620
+ ctx__expression = ctx.expression
621
+
622
+ attribute = visit_if(ctx__attribute_decl)
623
+ type = visit_if(ctx__parameter_type)
624
+ expression = visit_if(ctx__expression)
625
+
626
+ Model::Attribute.new({
627
+ id: attribute.id,
628
+ kind: Model::Attribute::DERIVED,
629
+ supertype_attribute: attribute.supertype_attribute,
630
+ type: type,
631
+ expression: expression
632
+ })
633
+ end
634
+
635
+ def visit_derive_clause(ctx)
636
+ ctx__derived_attr = ctx.derived_attr
637
+
638
+ visit_if_map(ctx__derived_attr)
639
+ end
640
+
641
+ def visit_domain_rule(ctx)
642
+ ctx__rule_label_id = ctx.rule_label_id
643
+ ctx__expression = ctx.expression
644
+
645
+ id = visit_if(ctx__rule_label_id)
646
+ expression = visit_if(ctx__expression)
647
+
648
+ Model::Where.new({
649
+ id: id,
650
+ expression: expression
651
+ })
652
+ end
653
+
654
+ def visit_element(ctx)
655
+ ctx__expression = ctx.expression
656
+ ctx__repetition = ctx.repetition
657
+
658
+ if ctx__repetition
659
+ expression = visit_if(ctx__expression)
660
+ repetition = visit_if(ctx__repetition)
661
+
662
+ Model::Expressions::AggregateItem.new({
663
+ expression: expression,
664
+ repetition: repetition
665
+ })
666
+ else
667
+ visit_if(ctx__expression)
668
+ end
669
+ end
670
+
671
+ def visit_entity_body(ctx)
672
+ raise 'Invalid state'
673
+ end
674
+
675
+ def visit_entity_constructor(ctx)
676
+ ctx__entity_ref = ctx.entity_ref
677
+ ctx__expression = ctx.expression
678
+
679
+ ref = visit_if(ctx__entity_ref)
680
+ parameters = visit_if_map(ctx__expression)
681
+
682
+ Model::Expressions::Call.new({
683
+ ref: ref,
684
+ parameters: parameters
685
+ })
686
+ end
687
+
688
+ def visit_entity_decl(ctx)
689
+ ctx__entity_head = ctx.entity_head
690
+ ctx__entity_body = ctx.entity_body
691
+ ctx__entity_head__entity_id = ctx__entity_head&.entity_id
692
+ ctx__entity_head__subsuper = ctx__entity_head&.subsuper
693
+ ctx__entity_head__subsuper__supertype_constraint = ctx__entity_head__subsuper&.supertype_constraint
694
+ ctx__entity_head__subsuper__supertype_constraint__abstract_entity_declaration = ctx__entity_head__subsuper__supertype_constraint&.abstract_entity_declaration
695
+ ctx__entity_head__subsuper__supertype_constraint__abstract_supertype_declaration = ctx__entity_head__subsuper__supertype_constraint&.abstract_supertype_declaration
696
+ ctx__entity_head__subsuper__supertype_constraint__supertype_rule = ctx__entity_head__subsuper__supertype_constraint&.supertype_rule
697
+ ctx__entity_head__subsuper__subtype_declaration = ctx__entity_head__subsuper&.subtype_declaration
698
+ ctx__entity_body__explicit_attr = ctx__entity_body&.explicit_attr
699
+ ctx__entity_body__derive_clause = ctx__entity_body&.derive_clause
700
+ ctx__entity_body__inverse_clause = ctx__entity_body&.inverse_clause
701
+ ctx__entity_body__unique_clause = ctx__entity_body&.unique_clause
702
+ ctx__entity_body__where_clause = ctx__entity_body&.where_clause
703
+
704
+ id = visit_if(ctx__entity_head__entity_id)
705
+ abstract = !!(ctx__entity_head__subsuper__supertype_constraint__abstract_entity_declaration || ctx__entity_head__subsuper__supertype_constraint__abstract_supertype_declaration)
706
+ supertype_expression = visit_if(ctx__entity_head__subsuper__supertype_constraint__abstract_supertype_declaration || ctx__entity_head__subsuper__supertype_constraint__supertype_rule)
707
+ subtype_of = visit_if(ctx__entity_head__subsuper__subtype_declaration)
708
+ attributes = [
709
+ *visit_if_map_flatten(ctx__entity_body__explicit_attr),
710
+ *visit_if(ctx__entity_body__derive_clause),
711
+ *visit_if(ctx__entity_body__inverse_clause)
712
+ ]
713
+ unique = visit_if(ctx__entity_body__unique_clause)
714
+ where = visit_if(ctx__entity_body__where_clause)
715
+
716
+ Model::Entity.new({
717
+ id: id,
718
+ abstract: abstract,
719
+ supertype_expression: supertype_expression,
720
+ subtype_of: subtype_of,
721
+ attributes: attributes,
722
+ unique: unique,
723
+ where: where
724
+ })
725
+ end
726
+
727
+ def visit_entity_head(ctx)
728
+ raise 'Invalid state'
729
+ end
730
+
731
+ def visit_entity_id(ctx)
732
+ ctx__SimpleId = ctx.SimpleId
733
+
734
+ handle_simple_id(ctx__SimpleId)
735
+ end
736
+
737
+ def visit_enumeration_extension(ctx)
738
+ raise 'Invalid state'
739
+ end
740
+
741
+ def visit_enumeration_id(ctx)
742
+ ctx__SimpleId = ctx.SimpleId
743
+
744
+ handle_simple_id(ctx__SimpleId)
745
+ end
746
+
747
+ def visit_enumeration_items(ctx)
748
+ ctx__enumeration_item = ctx.enumeration_item
749
+
750
+ visit_if_map(ctx__enumeration_item)
751
+ end
752
+
753
+ def visit_enumeration_item(ctx)
754
+ ctx__enumeration_id = ctx.enumeration_id
755
+
756
+ id = visit_if(ctx__enumeration_id)
757
+
758
+ Model::EnumerationItem.new({
759
+ id: id
760
+ })
761
+ end
762
+
763
+ def visit_enumeration_reference(ctx)
764
+ ctx__type_ref = ctx.type_ref
765
+ ctx__enumeration_ref = ctx.enumeration_ref
766
+
767
+ if ctx__type_ref
768
+ ref = visit_if(ctx__type_ref)
769
+ attribute = visit_if(ctx__enumeration_ref)
770
+
771
+ Model::Expressions::AttributeReference.new({
772
+ ref: ref,
773
+ attribute: attribute
774
+ })
775
+ else
776
+ visit_if(ctx__enumeration_ref)
777
+ end
778
+ end
779
+
780
+ def visit_enumeration_type(ctx)
781
+ ctx__EXTENSIBLE = ctx.EXTENSIBLE
782
+ ctx__enumeration_items = ctx.enumeration_items
783
+ ctx__enumeration_extension = ctx.enumeration_extension
784
+ ctx__enumeration_extension__type_ref = ctx__enumeration_extension&.type_ref
785
+ ctx__enumeration_extension__enumeration_items = ctx__enumeration_extension&.enumeration_items
786
+
787
+ extensible = !!ctx__EXTENSIBLE
788
+ items = visit_if(ctx__enumeration_items)
789
+ extension_type = visit_if(ctx__enumeration_extension__type_ref)
790
+ extension_items = visit_if(ctx__enumeration_extension__enumeration_items)
791
+
792
+ Model::Types::Enumeration.new({
793
+ extensible: extensible,
794
+ items: items,
795
+ extension_type: extension_type,
796
+ extension_items: extension_items
797
+ })
798
+ end
799
+
800
+ def visit_escape_stmt(ctx)
801
+ Model::Statements::Escape.new
802
+ end
803
+
804
+ def visit_explicit_attr(ctx)
805
+ ctx__attribute_decl = ctx.attribute_decl
806
+ ctx__OPTIONAL = ctx.OPTIONAL
807
+ ctx__parameter_type = ctx.parameter_type
808
+
809
+ attributes = visit_if_map(ctx__attribute_decl)
810
+ optional = !!ctx__OPTIONAL
811
+ type = visit_if(ctx__parameter_type)
812
+
813
+ attributes.map do |attribute|
814
+ Model::Attribute.new({
815
+ id: attribute.id,
816
+ kind: Model::Attribute::EXPLICIT,
817
+ supertype_attribute: attribute.supertype_attribute,
818
+ optional: optional,
819
+ type: type
820
+ })
821
+ end
822
+ end
823
+
824
+ def visit_expression(ctx)
825
+ ctx__simple_expression = ctx.simple_expression
826
+ ctx__rel_op_extended = ctx.rel_op_extended
827
+
828
+ if ctx__simple_expression.length == 2
829
+ operator = visit_if(ctx__rel_op_extended)
830
+ operand1 = visit_if(ctx__simple_expression[0])
831
+ operand2 = visit_if(ctx__simple_expression[1])
832
+
833
+ Model::Expressions::BinaryExpression.new({
834
+ operator: operator,
835
+ operand1: operand1,
836
+ operand2: operand2
837
+ })
838
+ else
839
+ visit_if(ctx__simple_expression[0])
840
+ end
841
+ end
842
+
843
+ def visit_factor(ctx)
844
+ ctx__simple_factor = ctx.simple_factor
845
+
846
+ if ctx__simple_factor.length == 2
847
+ operator = Model::Expressions::BinaryExpression::EXPONENTIATION
848
+ operand1 = visit(ctx__simple_factor[0])
849
+ operand2 = visit(ctx__simple_factor[1])
850
+
851
+ Model::Expressions::BinaryExpression.new({
852
+ operator: operator,
853
+ operand1: operand1,
854
+ operand2: operand2
855
+ })
856
+ elsif ctx__simple_factor.length == 1
857
+ visit_if(ctx__simple_factor[0])
858
+ else
859
+ raise 'Invalid state'
860
+ end
861
+ end
862
+
863
+ def visit_formal_parameter(ctx)
864
+ ctx__parameter_id = ctx.parameter_id
865
+ ctx__parameter_type = ctx.parameter_type
866
+
867
+ ids = visit_if_map(ctx__parameter_id)
868
+ type = visit_if(ctx__parameter_type)
869
+
870
+ ids.map do |id|
871
+ Model::Parameter.new({
872
+ id: id,
873
+ type: type
874
+ })
875
+ end
876
+ end
877
+
878
+ def visit_function_call(ctx)
879
+ ctx__built_in_function = ctx.built_in_function
880
+ ctx__function_ref = ctx.function_ref
881
+ ctx__actual_parameter_list = ctx.actual_parameter_list
882
+
883
+ ref = visit_if(ctx__built_in_function || ctx__function_ref)
884
+ parameters = visit_if(ctx__actual_parameter_list)
885
+
886
+ Model::Expressions::Call.new({
887
+ ref: ref,
888
+ parameters: parameters
889
+ })
890
+ end
891
+
892
+ def visit_function_decl(ctx)
893
+ ctx__function_head = ctx.function_head
894
+ ctx__algorithm_head = ctx.algorithm_head
895
+ ctx__stmt = ctx.stmt
896
+ ctx__function_head__function_id = ctx__function_head&.function_id
897
+ ctx__function_head__formal_parameter = ctx__function_head&.formal_parameter
898
+ ctx__function_head__parameter_type = ctx__function_head&.parameter_type
899
+ ctx__algorithm_head__declaration = ctx__algorithm_head&.declaration
900
+ ctx__algorithm_head__constant_decl = ctx__algorithm_head&.constant_decl
901
+ ctx__algorithm_head__local_decl = ctx__algorithm_head&.local_decl
902
+
903
+ id = visit_if(ctx__function_head__function_id)
904
+ parameters = visit_if_map_flatten(ctx__function_head__formal_parameter)
905
+ return_type = visit_if(ctx__function_head__parameter_type)
906
+ declarations = visit_if_map(ctx__algorithm_head__declaration)
907
+ constants = visit_if(ctx__algorithm_head__constant_decl)
908
+ variables = visit_if(ctx__algorithm_head__local_decl)
909
+ statements = visit_if_map(ctx__stmt)
910
+
911
+ Model::Function.new({
912
+ id: id,
913
+ parameters: parameters,
914
+ return_type: return_type,
915
+ declarations: declarations,
916
+ constants: constants,
917
+ variables: variables,
918
+ statements: statements
919
+ })
920
+ end
921
+
922
+ def visit_function_head(ctx)
923
+ raise 'Invalid state'
924
+ end
925
+
926
+ def visit_function_id(ctx)
927
+ ctx__SimpleId = ctx.SimpleId
928
+
929
+ handle_simple_id(ctx__SimpleId)
930
+ end
931
+
932
+ def visit_generalized_types(ctx)
933
+ ctx__aggregate_type = ctx.aggregate_type
934
+ ctx__general_aggregation_types = ctx.general_aggregation_types
935
+ ctx__generic_entity_type = ctx.generic_entity_type
936
+ ctx__generic_type = ctx.generic_type
937
+
938
+ visit_if(ctx__aggregate_type || ctx__general_aggregation_types || ctx__generic_entity_type || ctx__generic_type)
939
+ end
940
+
941
+ def visit_general_aggregation_types(ctx)
942
+ ctx__general_array_type = ctx.general_array_type
943
+ ctx__general_bag_type = ctx.general_bag_type
944
+ ctx__general_list_type = ctx.general_list_type
945
+ ctx__general_set_type = ctx.general_set_type
946
+
947
+ visit_if(ctx__general_array_type || ctx__general_bag_type || ctx__general_list_type || ctx__general_set_type)
948
+ end
949
+
950
+ def visit_general_array_type(ctx)
951
+ ctx__bound_spec = ctx.bound_spec
952
+ ctx__OPTIONAL = ctx.OPTIONAL
953
+ ctx__UNIQUE = ctx.UNIQUE
954
+ ctx__parameter_type = ctx.parameter_type
955
+ ctx__bound_spec__bound1 = ctx__bound_spec&.bound1
956
+ ctx__bound_spec__bound2 = ctx__bound_spec&.bound2
957
+
958
+ bound1 = visit_if(ctx__bound_spec__bound1)
959
+ bound2 = visit_if(ctx__bound_spec__bound2)
960
+ optional = !!ctx__OPTIONAL
961
+ unique = !!ctx__UNIQUE
962
+ base_type = visit_if(ctx__parameter_type)
963
+
964
+ Model::Types::Array.new({
965
+ bound1: bound1,
966
+ bound2: bound2,
967
+ optional: optional,
968
+ unique: unique,
969
+ base_type: base_type
970
+ })
971
+ end
972
+
973
+ def visit_general_bag_type(ctx)
974
+ ctx__bound_spec = ctx.bound_spec
975
+ ctx__parameter_type = ctx.parameter_type
976
+ ctx__bound_spec__bound1 = ctx__bound_spec&.bound1
977
+ ctx__bound_spec__bound2 = ctx__bound_spec&.bound2
978
+
979
+ bound1 = visit_if(ctx__bound_spec__bound1)
980
+ bound2 = visit_if(ctx__bound_spec__bound2)
981
+ base_type = visit_if(ctx__parameter_type)
982
+
983
+ Model::Types::Bag.new({
984
+ bound1: bound1,
985
+ bound2: bound2,
986
+ base_type: base_type
987
+ })
988
+ end
989
+
990
+ def visit_general_list_type(ctx)
991
+ ctx__bound_spec = ctx.bound_spec
992
+ ctx__UNIQUE = ctx.UNIQUE
993
+ ctx__parameter_type = ctx.parameter_type
994
+ ctx__bound_spec__bound1 = ctx__bound_spec&.bound1
995
+ ctx__bound_spec__bound2 = ctx__bound_spec&.bound2
996
+
997
+ bound1 = visit_if(ctx__bound_spec__bound1)
998
+ bound2 = visit_if(ctx__bound_spec__bound2)
999
+ unique = !!ctx__UNIQUE
1000
+ base_type = visit_if(ctx__parameter_type)
1001
+
1002
+ Model::Types::List.new({
1003
+ bound1: bound1,
1004
+ bound2: bound2,
1005
+ unique: unique,
1006
+ base_type: base_type
1007
+ })
1008
+ end
1009
+
1010
+ def visit_general_ref(ctx)
1011
+ ctx__parameter_ref = ctx.parameter_ref
1012
+ ctx__variable_id = ctx.variable_id
1013
+
1014
+ visit_if(ctx__parameter_ref || ctx__variable_id)
1015
+ end
1016
+
1017
+ def visit_general_set_type(ctx)
1018
+ ctx__bound_spec = ctx.bound_spec
1019
+ ctx__parameter_type = ctx.parameter_type
1020
+ ctx__bound_spec__bound1 = ctx__bound_spec&.bound1
1021
+ ctx__bound_spec__bound2 = ctx__bound_spec&.bound2
1022
+
1023
+ bound1 = visit_if(ctx__bound_spec__bound1)
1024
+ bound2 = visit_if(ctx__bound_spec__bound2)
1025
+ base_type = visit_if(ctx__parameter_type)
1026
+
1027
+ Model::Types::Set.new({
1028
+ bound1: bound1,
1029
+ bound2: bound2,
1030
+ base_type: base_type
1031
+ })
1032
+ end
1033
+
1034
+ def visit_generic_entity_type(ctx)
1035
+ ctx__type_label = ctx.type_label
1036
+
1037
+ id = visit_if(ctx__type_label)
1038
+
1039
+ Model::Types::GenericEntity.new({
1040
+ id: id
1041
+ })
1042
+ end
1043
+
1044
+ def visit_generic_type(ctx)
1045
+ ctx__type_label = ctx.type_label
1046
+
1047
+ id = visit_if(ctx__type_label)
1048
+
1049
+ Model::Types::Generic.new({
1050
+ id: id
1051
+ })
1052
+ end
1053
+
1054
+ def visit_group_qualifier(ctx)
1055
+ ctx__entity_ref = ctx.entity_ref
1056
+
1057
+ entity = visit_if(ctx__entity_ref)
1058
+
1059
+ Model::Expressions::GroupReference.new({
1060
+ entity: entity
1061
+ })
1062
+ end
1063
+
1064
+ def visit_group_reference(ctx)
1065
+ raise 'Invalid state'
1066
+ end
1067
+
1068
+ def visit_if_stmt(ctx)
1069
+ ctx__logical_expression = ctx.logical_expression
1070
+ ctx__if_stmt_statements = ctx.if_stmt_statements
1071
+ ctx__if_stmt_else_statements = ctx.if_stmt_else_statements
1072
+
1073
+ expression = visit_if(ctx__logical_expression)
1074
+ statements = visit_if(ctx__if_stmt_statements)
1075
+ else_statements = visit_if(ctx__if_stmt_else_statements)
1076
+
1077
+ Model::Statements::If.new({
1078
+ expression: expression,
1079
+ statements: statements,
1080
+ else_statements: else_statements
1081
+ })
1082
+ end
1083
+
1084
+ def visit_if_stmt_statements(ctx)
1085
+ ctx__stmt = ctx.stmt
1086
+
1087
+ visit_if_map(ctx__stmt)
1088
+ end
1089
+
1090
+ def visit_if_stmt_else_statements(ctx)
1091
+ ctx__stmt = ctx.stmt
1092
+
1093
+ visit_if_map(ctx__stmt)
1094
+ end
1095
+
1096
+ def visit_increment(ctx)
1097
+ ctx__numeric_expression = ctx.numeric_expression
1098
+
1099
+ visit_if(ctx__numeric_expression)
1100
+ end
1101
+
1102
+ def visit_increment_control(ctx)
1103
+ raise 'Invalid state'
1104
+ end
1105
+
1106
+ def visit_index(ctx)
1107
+ ctx__numeric_expression = ctx.numeric_expression
1108
+
1109
+ visit_if(ctx__numeric_expression)
1110
+ end
1111
+
1112
+ def visit_index1(ctx)
1113
+ ctx__index = ctx.index
1114
+
1115
+ visit_if(ctx__index)
1116
+ end
1117
+
1118
+ def visit_index2(ctx)
1119
+ ctx__index = ctx.index
1120
+
1121
+ visit_if(ctx__index)
1122
+ end
1123
+
1124
+ def visit_index_qualifier(ctx)
1125
+ ctx__index1 = ctx.index1
1126
+ ctx__index2 = ctx.index2
1127
+
1128
+ index1 = visit_if(ctx__index1)
1129
+ index2 = visit_if(ctx__index2)
1130
+
1131
+ Model::Expressions::IndexReference.new({
1132
+ index1: index1,
1133
+ index2: index2
1134
+ })
1135
+ end
1136
+
1137
+ def visit_index_reference(ctx)
1138
+ raise 'Invalid state'
1139
+ end
1140
+
1141
+ def visit_instantiable_type(ctx)
1142
+ ctx__concrete_types = ctx.concrete_types
1143
+ ctx__entity_ref = ctx.entity_ref
1144
+
1145
+ visit_if(ctx__concrete_types || ctx__entity_ref)
1146
+ end
1147
+
1148
+ def visit_integer_type(ctx)
1149
+ Model::Types::Integer.new
1150
+ end
1151
+
1152
+ def visit_interface_specification(ctx)
1153
+ ctx__reference_clause = ctx.reference_clause
1154
+ ctx__use_clause = ctx.use_clause
1155
+
1156
+ visit_if(ctx__reference_clause || ctx__use_clause)
1157
+ end
1158
+
1159
+ def visit_interval(ctx)
1160
+ ctx__interval_low = ctx.interval_low
1161
+ ctx__interval_op = ctx.interval_op
1162
+ ctx__interval_item = ctx.interval_item
1163
+ ctx__interval_high = ctx.interval_high
1164
+
1165
+ low = visit_if(ctx__interval_low)
1166
+ operator1 = visit_if(ctx__interval_op[0])
1167
+ item = visit_if(ctx__interval_item)
1168
+ operator2 = visit_if(ctx__interval_op[1])
1169
+ high = visit_if(ctx__interval_high)
1170
+
1171
+ Model::Expressions::Interval.new({
1172
+ low: low,
1173
+ operator1: operator1,
1174
+ item: item,
1175
+ operator2: operator2,
1176
+ high: high
1177
+ })
1178
+ end
1179
+
1180
+ def visit_interval_high(ctx)
1181
+ ctx__simple_expression = ctx.simple_expression
1182
+
1183
+ visit_if(ctx__simple_expression)
1184
+ end
1185
+
1186
+ def visit_interval_item(ctx)
1187
+ ctx__simple_expression = ctx.simple_expression
1188
+
1189
+ visit_if(ctx__simple_expression)
1190
+ end
1191
+
1192
+ def visit_interval_low(ctx)
1193
+ ctx__simple_expression = ctx.simple_expression
1194
+
1195
+ visit_if(ctx__simple_expression)
1196
+ end
1197
+
1198
+ def visit_interval_op(ctx)
1199
+ ctx__text = ctx.text
1200
+ ctx__LESS_THAN = ctx__text == '<'
1201
+ ctx__LESS_THAN_OR_EQUAL = ctx__text == '<='
1202
+
1203
+ if ctx__LESS_THAN
1204
+ Model::Expressions::BinaryExpression::LESS_THAN
1205
+ elsif ctx__LESS_THAN_OR_EQUAL
1206
+ Model::Expressions::BinaryExpression::LESS_THAN_OR_EQUAL
1207
+ else
1208
+ raise 'Invalid state'
1209
+ end
1210
+ end
1211
+
1212
+ def visit_inverse_attr(ctx)
1213
+ ctx__attribute_decl = ctx.attribute_decl
1214
+ ctx__inverse_attr_type = ctx.inverse_attr_type
1215
+ ctx__entity_ref = ctx.entity_ref
1216
+ ctx__attribute_ref = ctx.attribute_ref
1217
+
1218
+ attribute = visit_if(ctx__attribute_decl)
1219
+ type = visit_if(ctx__inverse_attr_type)
1220
+ expression = if ctx__entity_ref
1221
+ ref = visit(ctx__entity_ref)
1222
+ attribute_ref = visit(ctx__attribute_ref)
1223
+
1224
+ Model::Expressions::AttributeReference.new({
1225
+ ref: ref,
1226
+ attribute: attribute_ref
1227
+ })
1228
+ else
1229
+ visit(ctx__attribute_ref)
1230
+ end
1231
+
1232
+ Model::Attribute.new({
1233
+ id: attribute.id,
1234
+ kind: Model::Attribute::INVERSE,
1235
+ supertype_attribute: attribute.supertype_attribute,
1236
+ type: type,
1237
+ expression: expression
1238
+ })
1239
+ end
1240
+
1241
+ def visit_inverse_attr_type(ctx)
1242
+ ctx__SET = ctx.SET
1243
+ ctx__BAG = ctx.BAG
1244
+ ctx__bound_spec = ctx.bound_spec
1245
+ ctx__entity_ref = ctx.entity_ref
1246
+ ctx__bound_spec__bound1 = ctx__bound_spec&.bound1
1247
+ ctx__bound_spec__bound2 = ctx__bound_spec&.bound2
1248
+
1249
+ if ctx__SET
1250
+ bound1 = visit_if(ctx__bound_spec__bound1)
1251
+ bound2 = visit_if(ctx__bound_spec__bound2)
1252
+ base_type = visit_if(ctx__entity_ref)
1253
+
1254
+ Model::Types::Set.new({
1255
+ bound1: bound1,
1256
+ bound2: bound2,
1257
+ base_type: base_type
1258
+ })
1259
+ elsif ctx__BAG
1260
+ bound1 = visit_if(ctx__bound_spec__bound1)
1261
+ bound2 = visit_if(ctx__bound_spec__bound2)
1262
+ base_type = visit_if(ctx__entity_ref)
1263
+
1264
+ Model::Types::Bag.new({
1265
+ bound1: bound1,
1266
+ bound2: bound2,
1267
+ base_type: base_type
1268
+ })
1269
+ else
1270
+ visit_if(ctx__entity_ref)
1271
+ end
1272
+ end
1273
+
1274
+ def visit_inverse_clause(ctx)
1275
+ ctx__inverse_attr = ctx.inverse_attr
1276
+
1277
+ visit_if_map(ctx__inverse_attr)
1278
+ end
1279
+
1280
+ def visit_list_type(ctx)
1281
+ ctx__bound_spec = ctx.bound_spec
1282
+ ctx__UNIQUE = ctx.UNIQUE
1283
+ ctx__instantiable_type = ctx.instantiable_type
1284
+ ctx__bound_spec__bound1 = ctx__bound_spec&.bound1
1285
+ ctx__bound_spec__bound2 = ctx__bound_spec&.bound2
1286
+
1287
+ bound1 = visit_if(ctx__bound_spec__bound1)
1288
+ bound2 = visit_if(ctx__bound_spec__bound2)
1289
+ unique = !!ctx__UNIQUE
1290
+ base_type = visit_if(ctx__instantiable_type)
1291
+
1292
+ Model::Types::List.new({
1293
+ bound1: bound1,
1294
+ bound2: bound2,
1295
+ unique: unique,
1296
+ base_type: base_type
1297
+ })
1298
+ end
1299
+
1300
+ def visit_literal(ctx)
1301
+ ctx__BinaryLiteral = ctx.BinaryLiteral
1302
+ ctx__IntegerLiteral = ctx.IntegerLiteral
1303
+ ctx__logical_literal = ctx.logical_literal
1304
+ ctx__RealLiteral = ctx.RealLiteral
1305
+ ctx__string_literal = ctx.string_literal
1306
+
1307
+ if ctx__BinaryLiteral
1308
+ handle_binary_literal(ctx__BinaryLiteral)
1309
+ elsif ctx__IntegerLiteral
1310
+ handle_integer_literal(ctx__IntegerLiteral)
1311
+ elsif ctx__logical_literal
1312
+ visit(ctx__logical_literal)
1313
+ elsif ctx__RealLiteral
1314
+ handle_real_literal(ctx__RealLiteral)
1315
+ elsif ctx__string_literal
1316
+ visit(ctx__string_literal)
1317
+ else
1318
+ raise 'Invalid state'
1319
+ end
1320
+ end
1321
+
1322
+ def visit_local_decl(ctx)
1323
+ ctx__local_variable = ctx.local_variable
1324
+
1325
+ visit_if_map_flatten(ctx__local_variable)
1326
+ end
1327
+
1328
+ def visit_local_variable(ctx)
1329
+ ctx__variable_id = ctx.variable_id
1330
+ ctx__parameter_type = ctx.parameter_type
1331
+ ctx__expression = ctx.expression
1332
+
1333
+ ids = visit_if_map(ctx__variable_id)
1334
+ type = visit_if(ctx__parameter_type)
1335
+ expression = visit_if(ctx__expression)
1336
+
1337
+ ids.map do |id|
1338
+ Model::Variable.new({
1339
+ id: id,
1340
+ type: type,
1341
+ expression: expression
1342
+ })
1343
+ end
1344
+ end
1345
+
1346
+ def visit_logical_expression(ctx)
1347
+ ctx__expression = ctx.expression
1348
+
1349
+ visit_if(ctx__expression)
1350
+ end
1351
+
1352
+ def visit_logical_literal(ctx)
1353
+ ctx__TRUE = ctx.TRUE
1354
+ ctx__FALSE = ctx.FALSE
1355
+ ctx__UNKNOWN = ctx.UNKNOWN
1356
+
1357
+ value = if ctx__TRUE
1358
+ Model::Literals::Logical::TRUE
1359
+ elsif ctx__FALSE
1360
+ Model::Literals::Logical::FALSE
1361
+ elsif ctx__UNKNOWN
1362
+ Model::Literals::Logical::UNKNOWN
1363
+ else
1364
+ raise 'Invalid state'
1365
+ end
1366
+
1367
+ Model::Literals::Logical.new({
1368
+ value: value
1369
+ })
1370
+ end
1371
+
1372
+ def visit_logical_type(ctx)
1373
+ Model::Types::Logical.new
1374
+ end
1375
+
1376
+ def visit_multiplication_like_op(ctx)
1377
+ ctx__text = ctx.text
1378
+ ctx__MULTIPLICATION = ctx__text == '*'
1379
+ ctx__REAL_DIVISION = ctx__text == '/'
1380
+ ctx__INTEGER_DIVISION = ctx.DIV
1381
+ ctx__MODULO = ctx.MOD
1382
+ ctx__AND = ctx.AND
1383
+ ctx__COMBINE = ctx__text == '||'
1384
+
1385
+ if ctx__MULTIPLICATION
1386
+ Model::Expressions::BinaryExpression::MULTIPLICATION
1387
+ elsif ctx__REAL_DIVISION
1388
+ Model::Expressions::BinaryExpression::REAL_DIVISION
1389
+ elsif ctx__INTEGER_DIVISION
1390
+ Model::Expressions::BinaryExpression::INTEGER_DIVISION
1391
+ elsif ctx__MODULO
1392
+ Model::Expressions::BinaryExpression::MODULO
1393
+ elsif ctx__AND
1394
+ Model::Expressions::BinaryExpression::AND
1395
+ elsif ctx__COMBINE
1396
+ Model::Expressions::BinaryExpression::COMBINE
1397
+ else
1398
+ raise 'Invalid state'
1399
+ end
1400
+ end
1401
+
1402
+ def visit_named_types(ctx)
1403
+ ctx__entity_ref = ctx.entity_ref
1404
+ ctx__type_ref = ctx.type_ref
1405
+
1406
+ visit_if(ctx__entity_ref || ctx__type_ref)
1407
+ end
1408
+
1409
+ def visit_named_type_or_rename(ctx)
1410
+ ctx__named_types = ctx.named_types
1411
+ ctx__entity_id = ctx.entity_id
1412
+ ctx__type_id = ctx.type_id
1413
+
1414
+ ref = visit_if(ctx__named_types)
1415
+ id = visit_if(ctx__entity_id || ctx__type_id)
1416
+
1417
+ if id
1418
+ Model::RenamedRef.new({
1419
+ ref: ref,
1420
+ id: id
1421
+ })
1422
+ else
1423
+ ref
1424
+ end
1425
+ end
1426
+
1427
+ def visit_null_stmt(ctx)
1428
+ Model::Statements::Null.new
1429
+ end
1430
+
1431
+ def visit_number_type(ctx)
1432
+ Model::Types::Number.new
1433
+ end
1434
+
1435
+ def visit_numeric_expression(ctx)
1436
+ ctx__simple_expression = ctx.simple_expression
1437
+
1438
+ visit_if(ctx__simple_expression)
1439
+ end
1440
+
1441
+ def visit_one_of(ctx)
1442
+ ctx__supertype_expression = ctx.supertype_expression
1443
+
1444
+ ref = Model::Expressions::SimpleReference.new({ id: 'ONEOF' })
1445
+ parameters = visit_if_map(ctx__supertype_expression)
1446
+
1447
+ Model::Expressions::Call.new({
1448
+ ref: ref,
1449
+ parameters: parameters
1450
+ })
1451
+ end
1452
+
1453
+ def visit_parameter(ctx)
1454
+ ctx__expression = ctx.expression
1455
+
1456
+ visit_if(ctx__expression)
1457
+ end
1458
+
1459
+ def visit_parameter_id(ctx)
1460
+ ctx__SimpleId = ctx.SimpleId
1461
+
1462
+ handle_simple_id(ctx__SimpleId)
1463
+ end
1464
+
1465
+ def visit_parameter_type(ctx)
1466
+ ctx__generalized_types = ctx.generalized_types
1467
+ ctx__named_types = ctx.named_types
1468
+ ctx__simple_types = ctx.simple_types
1469
+
1470
+ visit_if(ctx__generalized_types || ctx__named_types || ctx__simple_types)
1471
+ end
1472
+
1473
+ def visit_population(ctx)
1474
+ ctx__entity_ref = ctx.entity_ref
1475
+
1476
+ visit_if(ctx__entity_ref)
1477
+ end
1478
+
1479
+ def visit_precision_spec(ctx)
1480
+ ctx__numeric_expression = ctx.numeric_expression
1481
+
1482
+ visit_if(ctx__numeric_expression)
1483
+ end
1484
+
1485
+ def visit_primary(ctx)
1486
+ ctx__literal = ctx.literal
1487
+ ctx__qualifiable_factor = ctx.qualifiable_factor
1488
+ ctx__qualifier = ctx.qualifier
1489
+
1490
+ if ctx__literal
1491
+ visit(ctx__literal)
1492
+ elsif ctx__qualifiable_factor
1493
+ handle_qualified_ref(visit(ctx__qualifiable_factor), ctx__qualifier)
1494
+ else
1495
+ raise 'Invalid state'
1496
+ end
1497
+ end
1498
+
1499
+ def visit_procedure_call_stmt(ctx)
1500
+ ctx__built_in_procedure = ctx.built_in_procedure
1501
+ ctx__procedure_ref = ctx.procedure_ref
1502
+ ctx__actual_parameter_list = ctx.actual_parameter_list
1503
+
1504
+ ref = visit_if(ctx__built_in_procedure || ctx__procedure_ref)
1505
+ parameters = visit_if(ctx__actual_parameter_list)
1506
+
1507
+ Model::Statements::Call.new({
1508
+ ref: ref,
1509
+ parameters: parameters
1510
+ })
1511
+ end
1512
+
1513
+ def visit_procedure_decl(ctx)
1514
+ ctx__procedure_head = ctx.procedure_head
1515
+ ctx__algorithm_head = ctx.algorithm_head
1516
+ ctx__stmt = ctx.stmt
1517
+ ctx__procedure_head__procedure_id = ctx__procedure_head&.procedure_id
1518
+ ctx__procedure_head__procedure_head_parameter = ctx__procedure_head&.procedure_head_parameter
1519
+ ctx__algorithm_head__declaration = ctx__algorithm_head&.declaration
1520
+ ctx__algorithm_head__constant_decl = ctx__algorithm_head&.constant_decl
1521
+ ctx__algorithm_head__local_decl = ctx__algorithm_head&.local_decl
1522
+
1523
+ id = visit_if(ctx__procedure_head__procedure_id)
1524
+ parameters = visit_if_map_flatten(ctx__procedure_head__procedure_head_parameter)
1525
+ declarations = visit_if_map(ctx__algorithm_head__declaration)
1526
+ constants = visit_if(ctx__algorithm_head__constant_decl)
1527
+ variables = visit_if(ctx__algorithm_head__local_decl)
1528
+ statements = visit_if_map(ctx__stmt)
1529
+
1530
+ Model::Procedure.new({
1531
+ id: id,
1532
+ parameters: parameters,
1533
+ declarations: declarations,
1534
+ constants: constants,
1535
+ variables: variables,
1536
+ statements: statements
1537
+ })
1538
+ end
1539
+
1540
+ def visit_procedure_head(ctx)
1541
+ raise 'Invalid state'
1542
+ end
1543
+
1544
+ def visit_procedure_head_parameter(ctx)
1545
+ ctx__formal_parameter = ctx.formal_parameter
1546
+ ctx__VAR = ctx.VAR
1547
+
1548
+ parameters = visit(ctx__formal_parameter)
1549
+
1550
+ if ctx.VAR
1551
+ parameters.map do |parameter|
1552
+ Model::Parameter.new({
1553
+ id: parameter.id,
1554
+ var: true,
1555
+ type: parameter.type
1556
+ })
1557
+ end
1558
+ else
1559
+ parameters
1560
+ end
1561
+ end
1562
+
1563
+ def visit_procedure_id(ctx)
1564
+ ctx__SimpleId = ctx.SimpleId
1565
+
1566
+ handle_simple_id(ctx__SimpleId)
1567
+ end
1568
+
1569
+ def visit_qualifiable_factor(ctx)
1570
+ ctx__attribute_ref = ctx.attribute_ref
1571
+ ctx__constant_factor = ctx.constant_factor
1572
+ ctx__function_call = ctx.function_call
1573
+ ctx__general_ref = ctx.general_ref
1574
+ ctx__population = ctx.population
1575
+
1576
+ visit_if(ctx__attribute_ref || ctx__constant_factor || ctx__function_call || ctx__general_ref || ctx__population)
1577
+ end
1578
+
1579
+ def visit_qualified_attribute(ctx)
1580
+ ctx__group_qualifier = ctx.group_qualifier
1581
+ ctx__attribute_qualifier = ctx.attribute_qualifier
1582
+
1583
+ id = 'SELF'
1584
+ group_reference = visit_if(ctx__group_qualifier)
1585
+ attribute_reference = visit_if(ctx__attribute_qualifier)
1586
+
1587
+ Model::Expressions::AttributeReference.new({
1588
+ ref: Model::Expressions::GroupReference.new({
1589
+ ref: Model::Expressions::SimpleReference.new({
1590
+ id: id
1591
+ }),
1592
+ entity: group_reference.entity
1593
+ }),
1594
+ attribute: attribute_reference.attribute
1595
+ })
1596
+ end
1597
+
1598
+ def visit_qualifier(ctx)
1599
+ ctx__attribute_qualifier = ctx.attribute_qualifier
1600
+ ctx__group_qualifier = ctx.group_qualifier
1601
+ ctx__index_qualifier = ctx.index_qualifier
1602
+
1603
+ visit_if(ctx__attribute_qualifier || ctx__group_qualifier || ctx__index_qualifier)
1604
+ end
1605
+
1606
+ def visit_query_expression(ctx)
1607
+ ctx__variable_id = ctx.variable_id
1608
+ ctx__aggregate_source = ctx.aggregate_source
1609
+ ctx__logical_expression = ctx.logical_expression
1610
+
1611
+ id = visit_if(ctx__variable_id)
1612
+ source = visit_if(ctx__aggregate_source)
1613
+ expression = visit_if(ctx__logical_expression)
1614
+
1615
+ Model::Expressions::QueryExpression.new({
1616
+ id: id,
1617
+ source: source,
1618
+ expression: expression
1619
+ })
1620
+ end
1621
+
1622
+ def visit_real_type(ctx)
1623
+ ctx__precision_spec = ctx.precision_spec
1624
+
1625
+ precision = visit_if(ctx__precision_spec)
1626
+
1627
+ Model::Types::Real.new({
1628
+ precision: precision
1629
+ })
1630
+ end
1631
+
1632
+ def visit_redeclared_attribute(ctx)
1633
+ raise 'Invalid state'
1634
+ end
1635
+
1636
+ def visit_referenced_attribute(ctx)
1637
+ ctx__attribute_ref = ctx.attribute_ref
1638
+ ctx__qualified_attribute = ctx.qualified_attribute
1639
+
1640
+ visit_if(ctx__attribute_ref || ctx__qualified_attribute)
1641
+ end
1642
+
1643
+ def visit_reference_clause(ctx)
1644
+ ctx__schema_ref = ctx.schema_ref
1645
+ ctx__resource_or_rename = ctx.resource_or_rename
1646
+
1647
+ schema = visit_if(ctx__schema_ref)
1648
+ items = visit_if_map(ctx__resource_or_rename)
1649
+
1650
+ Model::Interface.new({
1651
+ kind: Model::Interface::REFERENCE,
1652
+ schema: schema,
1653
+ items: items
1654
+ })
1655
+ end
1656
+
1657
+ def visit_rel_op(ctx)
1658
+ ctx__text = ctx.text
1659
+ ctx__LESS_THAN = ctx__text == '<'
1660
+ ctx__GREATER_THAN = ctx__text == '>'
1661
+ ctx__LESS_THAN_OR_EQUAL = ctx__text == '<='
1662
+ ctx__GREATER_THAN_OR_EQUAL = ctx__text == '>='
1663
+ ctx__NOT_EQUAL = ctx__text == '<>'
1664
+ ctx__EQUAL = ctx__text == '='
1665
+ ctx__INSTANCE_NOT_EQUAL = ctx__text == ':<>:'
1666
+ ctx__INSTANCE_EQUAL = ctx__text == ':=:'
1667
+
1668
+ if ctx__LESS_THAN
1669
+ Model::Expressions::BinaryExpression::LESS_THAN
1670
+ elsif ctx__GREATER_THAN
1671
+ Model::Expressions::BinaryExpression::GREATER_THAN
1672
+ elsif ctx__LESS_THAN_OR_EQUAL
1673
+ Model::Expressions::BinaryExpression::LESS_THAN_OR_EQUAL
1674
+ elsif ctx__GREATER_THAN_OR_EQUAL
1675
+ Model::Expressions::BinaryExpression::GREATER_THAN_OR_EQUAL
1676
+ elsif ctx__NOT_EQUAL
1677
+ Model::Expressions::BinaryExpression::NOT_EQUAL
1678
+ elsif ctx__EQUAL
1679
+ Model::Expressions::BinaryExpression::EQUAL
1680
+ elsif ctx__INSTANCE_NOT_EQUAL
1681
+ Model::Expressions::BinaryExpression::INSTANCE_NOT_EQUAL
1682
+ elsif ctx__INSTANCE_EQUAL
1683
+ Model::Expressions::BinaryExpression::INSTANCE_EQUAL
1684
+ else
1685
+ raise 'Invalid state'
1686
+ end
1687
+ end
1688
+
1689
+ def visit_rel_op_extended(ctx)
1690
+ ctx__rel_op = ctx.rel_op
1691
+ ctx__IN = ctx.IN
1692
+ ctx__LIKE = ctx.LIKE
1693
+
1694
+ if ctx__rel_op
1695
+ visit(ctx__rel_op)
1696
+ elsif ctx__IN
1697
+ Model::Expressions::BinaryExpression::IN
1698
+ elsif ctx__LIKE
1699
+ Model::Expressions::BinaryExpression::LIKE
1700
+ else
1701
+ raise 'Invalid state'
1702
+ end
1703
+ end
1704
+
1705
+ def visit_rename_id(ctx)
1706
+ ctx__constant_id = ctx.constant_id
1707
+ ctx__entity_id = ctx.entity_id
1708
+ ctx__function_id = ctx.function_id
1709
+ ctx__procedure_id = ctx.procedure_id
1710
+ ctx__type_id = ctx.type_id
1711
+
1712
+ visit_if(ctx__constant_id || ctx__entity_id || ctx__function_id || ctx__procedure_id || ctx__type_id)
1713
+ end
1714
+
1715
+ def visit_repeat_control(ctx)
1716
+ raise 'Invalid state'
1717
+ end
1718
+
1719
+ def visit_repeat_stmt(ctx)
1720
+ ctx__repeat_control = ctx.repeat_control
1721
+ ctx__stmt = ctx.stmt
1722
+ ctx__repeat_control__increment_control = ctx__repeat_control&.increment_control
1723
+ ctx__repeat_control__increment_control__variable_id = ctx__repeat_control__increment_control&.variable_id
1724
+ ctx__repeat_control__increment_control__bound1 = ctx__repeat_control__increment_control&.bound1
1725
+ ctx__repeat_control__increment_control__bound2 = ctx__repeat_control__increment_control&.bound2
1726
+ ctx__repeat_control__increment_control__increment = ctx__repeat_control__increment_control&.increment
1727
+ ctx__repeat_control__while_control = ctx__repeat_control&.while_control
1728
+ ctx__repeat_control__until_control = ctx__repeat_control&.until_control
1729
+
1730
+ id = visit_if(ctx__repeat_control__increment_control__variable_id)
1731
+ bound1 = visit_if(ctx__repeat_control__increment_control__bound1)
1732
+ bound2 = visit_if(ctx__repeat_control__increment_control__bound2)
1733
+ increment = visit_if(ctx__repeat_control__increment_control__increment)
1734
+ while_expression = visit_if(ctx__repeat_control__while_control)
1735
+ until_expression = visit_if(ctx__repeat_control__until_control)
1736
+ statements = visit_if_map(ctx__stmt)
1737
+
1738
+ Model::Statements::Repeat.new({
1739
+ id: id,
1740
+ bound1: bound1,
1741
+ bound2: bound2,
1742
+ increment: increment,
1743
+ while_expression: while_expression,
1744
+ until_expression: until_expression,
1745
+ statements: statements
1746
+ })
1747
+ end
1748
+
1749
+ def visit_repetition(ctx)
1750
+ ctx__numeric_expression = ctx.numeric_expression
1751
+
1752
+ visit_if(ctx__numeric_expression)
1753
+ end
1754
+
1755
+ def visit_resource_or_rename(ctx)
1756
+ ctx__resource_ref = ctx.resource_ref
1757
+ ctx__rename_id = ctx.rename_id
1758
+
1759
+ if ctx__resource_ref
1760
+ if ctx__rename_id
1761
+ ref = visit(ctx__resource_ref)
1762
+ id = visit(ctx__rename_id)
1763
+
1764
+ Model::RenamedRef.new({
1765
+ ref: ref,
1766
+ id: id
1767
+ })
1768
+ else
1769
+ visit(ctx__resource_ref)
1770
+ end
1771
+ else
1772
+ raise 'Invalid state'
1773
+ end
1774
+ end
1775
+
1776
+ def visit_resource_ref(ctx)
1777
+ ctx__constant_ref = ctx.constant_ref
1778
+ ctx__entity_ref = ctx.entity_ref
1779
+ ctx__function_ref = ctx.function_ref
1780
+ ctx__procedure_ref = ctx.procedure_ref
1781
+ ctx__type_ref = ctx.type_ref
1782
+
1783
+ visit_if(ctx__constant_ref || ctx__entity_ref || ctx__function_ref || ctx__procedure_ref || ctx__type_ref)
1784
+ end
1785
+
1786
+ def visit_return_stmt(ctx)
1787
+ ctx__expression = ctx.expression
1788
+
1789
+ expression = visit_if(ctx__expression)
1790
+
1791
+ Model::Statements::Return.new({
1792
+ expression: expression
1793
+ })
1794
+ end
1795
+
1796
+ def visit_rule_decl(ctx)
1797
+ ctx__rule_head = ctx.rule_head
1798
+ ctx__algorithm_head = ctx.algorithm_head
1799
+ ctx__stmt = ctx.stmt
1800
+ ctx__where_clause = ctx.where_clause
1801
+ ctx__rule_head__rule_id = ctx__rule_head&.rule_id
1802
+ ctx__rule_head__entity_ref = ctx__rule_head&.entity_ref
1803
+ ctx__algorithm_head__declaration = ctx__algorithm_head&.declaration
1804
+ ctx__algorithm_head__constant_decl = ctx__algorithm_head&.constant_decl
1805
+ ctx__algorithm_head__local_decl = ctx__algorithm_head&.local_decl
1806
+
1807
+ id = visit_if(ctx__rule_head__rule_id)
1808
+ applies_to = visit_if_map(ctx__rule_head__entity_ref)
1809
+ declarations = visit_if_map(ctx__algorithm_head__declaration)
1810
+ constants = visit_if(ctx__algorithm_head__constant_decl)
1811
+ variables = visit_if(ctx__algorithm_head__local_decl)
1812
+ statements = visit_if_map(ctx__stmt)
1813
+ where = visit_if(ctx__where_clause)
1814
+
1815
+ Model::Rule.new({
1816
+ id: id,
1817
+ applies_to: applies_to,
1818
+ declarations: declarations,
1819
+ constants: constants,
1820
+ variables: variables,
1821
+ statements: statements,
1822
+ where: where
1823
+ })
1824
+ end
1825
+
1826
+ def visit_rule_head(ctx)
1827
+ raise 'Invalid state'
1828
+ end
1829
+
1830
+ def visit_rule_id(ctx)
1831
+ ctx__SimpleId = ctx.SimpleId
1832
+
1833
+ handle_simple_id(ctx__SimpleId)
1834
+ end
1835
+
1836
+ def visit_rule_label_id(ctx)
1837
+ ctx__SimpleId = ctx.SimpleId
1838
+
1839
+ handle_simple_id(ctx__SimpleId)
1840
+ end
1841
+
1842
+ def visit_schema_body(ctx)
1843
+ raise 'Invalid state'
1844
+ end
1845
+
1846
+ def visit_schema_body_declaration(ctx)
1847
+ ctx__declaration = ctx.declaration
1848
+ ctx__rule_decl = ctx.rule_decl
1849
+
1850
+ visit_if(ctx__declaration || ctx__rule_decl)
1851
+ end
1852
+
1853
+ def visit_schema_decl(ctx)
1854
+ ctx__schema_id = ctx.schema_id
1855
+ ctx__schema_version_id = ctx.schema_version_id
1856
+ ctx__schema_body = ctx.schema_body
1857
+ ctx__schema_body__interface_specification = ctx__schema_body&.interface_specification
1858
+ ctx__schema_body__constant_decl = ctx__schema_body&.constant_decl
1859
+ ctx__schema_body__schema_body_declaration = ctx__schema_body&.schema_body_declaration
1860
+
1861
+ id = visit_if(ctx__schema_id)
1862
+ version = visit_if(ctx__schema_version_id)
1863
+ interfaces = visit_if_map(ctx__schema_body__interface_specification)
1864
+ constants = visit_if(ctx__schema_body__constant_decl)
1865
+ declarations = visit_if_map(ctx__schema_body__schema_body_declaration)
1866
+
1867
+ Model::Schema.new({
1868
+ id: id,
1869
+ version: version,
1870
+ interfaces: interfaces,
1871
+ constants: constants,
1872
+ declarations: declarations
1873
+ })
1874
+ end
1875
+
1876
+ def visit_schema_id(ctx)
1877
+ ctx__SimpleId = ctx.SimpleId
1878
+
1879
+ handle_simple_id(ctx__SimpleId)
1880
+ end
1881
+
1882
+ def visit_schema_version_id(ctx)
1883
+ ctx__string_literal = ctx.string_literal
1884
+
1885
+ visit_if(ctx__string_literal)
1886
+ end
1887
+
1888
+ def visit_selector(ctx)
1889
+ raise 'Invalid state'
1890
+ end
1891
+
1892
+ def visit_select_extension(ctx)
1893
+ ctx__named_types = ctx.named_types
1894
+
1895
+ visit_if_map(ctx__named_types)
1896
+ end
1897
+
1898
+ def visit_select_list(ctx)
1899
+ ctx__named_types = ctx.named_types
1900
+
1901
+ visit_if_map(ctx__named_types)
1902
+ end
1903
+
1904
+ def visit_select_type(ctx)
1905
+ ctx__EXTENSIBLE = ctx.EXTENSIBLE
1906
+ ctx__GENERIC_ENTITY = ctx.GENERIC_ENTITY
1907
+ ctx__select_list = ctx.select_list
1908
+ ctx__select_extension = ctx.select_extension
1909
+ ctx__select_extension__type_ref = ctx.select_extension&.type_ref
1910
+ ctx__select_extension__select_list = ctx__select_extension&.select_list
1911
+
1912
+ extensible = !!ctx__EXTENSIBLE
1913
+ generic_entity = !!ctx__GENERIC_ENTITY
1914
+ items = visit_if(ctx__select_list)
1915
+ extension_type = visit_if(ctx__select_extension__type_ref)
1916
+ extension_items = visit_if(ctx__select_extension__select_list)
1917
+
1918
+ Model::Types::Select.new({
1919
+ extensible: extensible,
1920
+ generic_entity: generic_entity,
1921
+ items: items,
1922
+ extension_type: extension_type,
1923
+ extension_items: extension_items
1924
+ })
1925
+ end
1926
+
1927
+ def visit_set_type(ctx)
1928
+ ctx__bound_spec = ctx.bound_spec
1929
+ ctx__instantiable_type = ctx.instantiable_type
1930
+ ctx__bound_spec__bound1 = ctx__bound_spec&.bound1
1931
+ ctx__bound_spec__bound2 = ctx__bound_spec&.bound2
1932
+
1933
+ bound1 = visit_if(ctx__bound_spec__bound1)
1934
+ bound2 = visit_if(ctx__bound_spec__bound2)
1935
+ base_type = visit_if(ctx__instantiable_type)
1936
+
1937
+ Model::Types::Set.new({
1938
+ bound1: bound1,
1939
+ bound2: bound2,
1940
+ base_type: base_type
1941
+ })
1942
+ end
1943
+
1944
+ def visit_simple_expression(ctx)
1945
+ ctx__term = ctx.term
1946
+ ctx__add_like_op = ctx.add_like_op
1947
+
1948
+ if ctx__term
1949
+ if ctx__term.length >= 2
1950
+ if ctx__add_like_op and ctx__add_like_op.length == ctx__term.length - 1
1951
+ operands = ctx__term.map(&self.method(:visit))
1952
+ operators = ctx__add_like_op.map(&self.method(:visit))
1953
+
1954
+ handle_binary_expression(operands, operators)
1955
+ else
1956
+ raise 'Invalid state'
1957
+ end
1958
+ elsif ctx__term.length == 1
1959
+ visit(ctx__term[0])
1960
+ else
1961
+ raise 'Invalid state'
1962
+ end
1963
+ end
1964
+ end
1965
+
1966
+ def visit_simple_factor(ctx)
1967
+ ctx__aggregate_initializer = ctx.aggregate_initializer
1968
+ ctx__entity_constructor = ctx.entity_constructor
1969
+ ctx__enumeration_reference = ctx.enumeration_reference
1970
+ ctx__interval = ctx.interval
1971
+ ctx__query_expression = ctx.query_expression
1972
+ ctx__simple_factor_expression = ctx.simple_factor_expression
1973
+ ctx__simple_factor_unary_expression = ctx.simple_factor_unary_expression
1974
+
1975
+ visit_if(ctx__aggregate_initializer || ctx__entity_constructor || ctx__enumeration_reference || ctx__interval || ctx__query_expression || ctx__simple_factor_expression || ctx__simple_factor_unary_expression)
1976
+ end
1977
+
1978
+ def visit_simple_factor_expression(ctx)
1979
+ ctx__expression = ctx.expression
1980
+ ctx__primary = ctx.primary
1981
+
1982
+ visit_if(ctx__expression || ctx__primary)
1983
+ end
1984
+
1985
+ def visit_simple_factor_unary_expression(ctx)
1986
+ ctx__unary_op = ctx.unary_op
1987
+ ctx__simple_factor_expression = ctx.simple_factor_expression
1988
+
1989
+ operator = visit_if(ctx__unary_op)
1990
+ operand = visit_if(ctx__simple_factor_expression)
1991
+
1992
+ Model::Expressions::UnaryExpression.new({
1993
+ operator: operator,
1994
+ operand: operand
1995
+ })
1996
+ end
1997
+
1998
+ def visit_simple_types(ctx)
1999
+ ctx__binary_type = ctx.binary_type
2000
+ ctx__boolean_type = ctx.boolean_type
2001
+ ctx__integer_type = ctx.integer_type
2002
+ ctx__logical_type = ctx.logical_type
2003
+ ctx__number_type = ctx.number_type
2004
+ ctx__real_type = ctx.real_type
2005
+ ctx__string_type = ctx.string_type
2006
+
2007
+ visit_if(ctx__binary_type || ctx__boolean_type || ctx__integer_type || ctx__logical_type || ctx__number_type || ctx__real_type || ctx__string_type)
2008
+ end
2009
+
2010
+ def visit_skip_stmt(ctx)
2011
+ Model::Statements::Skip.new
2012
+ end
2013
+
2014
+ def visit_stmt(ctx)
2015
+ ctx__alias_stmt = ctx.alias_stmt
2016
+ ctx__assignment_stmt = ctx.assignment_stmt
2017
+ ctx__case_stmt = ctx.case_stmt
2018
+ ctx__compound_stmt = ctx.compound_stmt
2019
+ ctx__escape_stmt = ctx.escape_stmt
2020
+ ctx__if_stmt = ctx.if_stmt
2021
+ ctx__null_stmt = ctx.null_stmt
2022
+ ctx__procedure_call_stmt = ctx.procedure_call_stmt
2023
+ ctx__repeat_stmt = ctx.repeat_stmt
2024
+ ctx__return_stmt = ctx.return_stmt
2025
+ ctx__skip_stmt = ctx.skip_stmt
2026
+
2027
+ visit_if(ctx__alias_stmt || ctx__assignment_stmt || ctx__case_stmt || ctx__compound_stmt || ctx__escape_stmt || ctx__if_stmt || ctx__null_stmt || ctx__procedure_call_stmt || ctx__repeat_stmt || ctx__return_stmt || ctx__skip_stmt)
2028
+ end
2029
+
2030
+ def visit_string_literal(ctx)
2031
+ ctx__SimpleStringLiteral = ctx.SimpleStringLiteral
2032
+ ctx__EncodedStringLiteral = ctx.EncodedStringLiteral
2033
+
2034
+ if ctx__SimpleStringLiteral
2035
+ handle_simple_string_literal(ctx__SimpleStringLiteral)
2036
+ elsif ctx__EncodedStringLiteral
2037
+ handle_encoded_string_literal(ctx__EncodedStringLiteral)
2038
+ else
2039
+ raise 'Invalid state'
2040
+ end
2041
+ end
2042
+
2043
+ def visit_string_type(ctx)
2044
+ ctx__width_spec = ctx.width_spec
2045
+ ctx__width_spec__width = ctx__width_spec&.width
2046
+ ctx__width_spec__FIXED = ctx__width_spec&.FIXED
2047
+
2048
+ width = visit_if(ctx__width_spec__width)
2049
+ fixed = !!ctx__width_spec__FIXED
2050
+
2051
+ Model::Types::String.new({
2052
+ width: width,
2053
+ fixed: fixed
2054
+ })
2055
+ end
2056
+
2057
+ def visit_subsuper(ctx)
2058
+ raise 'Invalid state'
2059
+ end
2060
+
2061
+ def visit_subtype_constraint(ctx)
2062
+ ctx__supertype_expression = ctx.supertype_expression
2063
+
2064
+ visit_if(ctx__supertype_expression)
2065
+ end
2066
+
2067
+ def visit_subtype_constraint_body(ctx)
2068
+ raise 'Invalid state'
2069
+ end
2070
+
2071
+ def visit_subtype_constraint_decl(ctx)
2072
+ ctx__subtype_constraint_head = ctx.subtype_constraint_head
2073
+ ctx__subtype_constraint_body = ctx.subtype_constraint_body
2074
+ ctx__subtype_constraint_head__subtype_constraint_id = ctx__subtype_constraint_head&.subtype_constraint_id
2075
+ ctx__subtype_constraint_head__entity_ref = ctx__subtype_constraint_head&.entity_ref
2076
+ ctx__subtype_constraint_body__abstract_supertype = ctx__subtype_constraint_body&.abstract_supertype
2077
+ ctx__subtype_constraint_body__total_over = ctx__subtype_constraint_body&.total_over
2078
+ ctx__subtype_constraint_body__supertype_expression = ctx__subtype_constraint_body&.supertype_expression
2079
+
2080
+ id = visit_if(ctx__subtype_constraint_head__subtype_constraint_id)
2081
+ applies_to = visit_if(ctx__subtype_constraint_head__entity_ref)
2082
+ abstract = !!ctx__subtype_constraint_body__abstract_supertype
2083
+ total_over = visit_if(ctx__subtype_constraint_body__total_over)
2084
+ supertype_expression = visit_if(ctx__subtype_constraint_body__supertype_expression)
2085
+
2086
+ Model::SubtypeConstraint.new({
2087
+ id: id,
2088
+ applies_to: applies_to,
2089
+ abstract: abstract,
2090
+ total_over: total_over,
2091
+ supertype_expression: supertype_expression
2092
+ })
2093
+ end
2094
+
2095
+ def visit_subtype_constraint_head(ctx)
2096
+ raise 'Invalid state'
2097
+ end
2098
+
2099
+ def visit_subtype_constraint_id(ctx)
2100
+ ctx__SimpleId = ctx.SimpleId
2101
+
2102
+ handle_simple_id(ctx__SimpleId)
2103
+ end
2104
+
2105
+ def visit_subtype_declaration(ctx)
2106
+ ctx__entity_ref = ctx.entity_ref
2107
+
2108
+ visit_if_map(ctx__entity_ref)
2109
+ end
2110
+
2111
+ def visit_supertype_constraint(ctx)
2112
+ raise 'Invalid state'
2113
+ end
2114
+
2115
+ def visit_supertype_expression(ctx)
2116
+ ctx__supertype_factor = ctx.supertype_factor
2117
+ ctx__ANDOR = ctx.ANDOR
2118
+
2119
+ if ctx__supertype_factor
2120
+ if ctx__supertype_factor.length >= 2
2121
+ if ctx__ANDOR and ctx__ANDOR.length == ctx__supertype_factor.length - 1
2122
+ operands = ctx__supertype_factor.map(&self.method(:visit))
2123
+ operators = ctx__ANDOR.map{Model::Expressions::BinaryExpression::ANDOR}
2124
+
2125
+ handle_binary_expression(operands, operators)
2126
+ else
2127
+ raise 'Invalid state'
2128
+ end
2129
+ elsif ctx__supertype_factor.length == 1
2130
+ visit(ctx__supertype_factor[0])
2131
+ else
2132
+ raise 'Invalid state'
2133
+ end
2134
+ end
2135
+ end
2136
+
2137
+ def visit_supertype_factor(ctx)
2138
+ ctx__supertype_term = ctx.supertype_term
2139
+ ctx__AND = ctx.AND
2140
+
2141
+ if ctx__supertype_term
2142
+ if ctx__supertype_term.length >= 2
2143
+ if ctx__AND and ctx__AND.length == ctx__supertype_term.length - 1
2144
+ operands = ctx__supertype_term.map(&self.method(:visit))
2145
+ operators = ctx__AND.map{Model::Expressions::BinaryExpression::AND}
2146
+
2147
+ handle_binary_expression(operands, operators)
2148
+ else
2149
+ raise 'Invalid state'
2150
+ end
2151
+ elsif ctx__supertype_term.length == 1
2152
+ visit(ctx__supertype_term[0])
2153
+ else
2154
+ raise 'Invalid state'
2155
+ end
2156
+ end
2157
+ end
2158
+
2159
+ def visit_supertype_rule(ctx)
2160
+ ctx__subtype_constraint = ctx.subtype_constraint
2161
+
2162
+ visit_if(ctx__subtype_constraint)
2163
+ end
2164
+
2165
+ def visit_supertype_term(ctx)
2166
+ ctx__entity_ref = ctx.entity_ref
2167
+ ctx__one_of = ctx.one_of
2168
+ ctx__supertype_expression = ctx.supertype_expression
2169
+
2170
+ visit_if(ctx__entity_ref || ctx__one_of || ctx__supertype_expression)
2171
+ end
2172
+
2173
+ def visit_syntax(ctx)
2174
+ ctx__schema_decl = ctx.schema_decl
2175
+
2176
+ schemas = visit_if_map(ctx__schema_decl)
2177
+
2178
+ Model::Repository.new({
2179
+ schemas: schemas
2180
+ })
2181
+ end
2182
+
2183
+ def visit_term(ctx)
2184
+ ctx__factor = ctx.factor
2185
+ ctx__multiplication_like_op = ctx.multiplication_like_op
2186
+
2187
+ if ctx__factor
2188
+ if ctx__factor.length >= 2
2189
+ if ctx__multiplication_like_op and ctx__multiplication_like_op.length == ctx__factor.length - 1
2190
+ operands = ctx__factor.map(&self.method(:visit))
2191
+ operators = ctx__multiplication_like_op.map(&self.method(:visit))
2192
+
2193
+ handle_binary_expression(operands, operators)
2194
+ else
2195
+ raise 'Invalid state'
2196
+ end
2197
+ elsif ctx__factor.length == 1
2198
+ visit(ctx__factor[0])
2199
+ else
2200
+ raise 'Invalid state'
2201
+ end
2202
+ end
2203
+ end
2204
+
2205
+ def visit_total_over(ctx)
2206
+ ctx__entity_ref = ctx.entity_ref
2207
+
2208
+ visit_if_map(ctx__entity_ref)
2209
+ end
2210
+
2211
+ def visit_type_decl(ctx)
2212
+ ctx__type_id = ctx.type_id
2213
+ ctx__underlying_type = ctx.underlying_type
2214
+ ctx__where_clause = ctx.where_clause
2215
+
2216
+ id = visit_if(ctx__type_id)
2217
+ type = visit_if(ctx__underlying_type)
2218
+ where = visit_if(ctx__where_clause)
2219
+
2220
+ Model::Type.new({
2221
+ id: id,
2222
+ type: type,
2223
+ where: where
2224
+ })
2225
+ end
2226
+
2227
+ def visit_type_id(ctx)
2228
+ ctx__SimpleId = ctx.SimpleId
2229
+
2230
+ handle_simple_id(ctx__SimpleId)
2231
+ end
2232
+
2233
+ def visit_type_label(ctx)
2234
+ ctx__type_label_id = ctx.type_label_id
2235
+ ctx__type_label_ref = ctx.type_label_ref
2236
+
2237
+ visit_if(ctx__type_label_id || ctx__type_label_ref)
2238
+ end
2239
+
2240
+ def visit_type_label_id(ctx)
2241
+ ctx__SimpleId = ctx.SimpleId
2242
+
2243
+ handle_simple_id(ctx__SimpleId)
2244
+ end
2245
+
2246
+ def visit_unary_op(ctx)
2247
+ ctx__text = ctx.text
2248
+ ctx__PLUS = ctx__text == '+'
2249
+ ctx__MINUS = ctx__text == '-'
2250
+ ctx__NOT = ctx.NOT
2251
+
2252
+ if ctx__PLUS
2253
+ Model::Expressions::UnaryExpression::PLUS
2254
+ elsif ctx__MINUS
2255
+ Model::Expressions::UnaryExpression::MINUS
2256
+ elsif ctx__NOT
2257
+ Model::Expressions::UnaryExpression::NOT
2258
+ else
2259
+ raise 'Invalid state'
2260
+ end
2261
+ end
2262
+
2263
+ def visit_underlying_type(ctx)
2264
+ ctx__concrete_types = ctx.concrete_types
2265
+ ctx__constructed_types = ctx.constructed_types
2266
+
2267
+ visit_if(ctx__concrete_types || ctx__constructed_types)
2268
+ end
2269
+
2270
+ def visit_unique_clause(ctx)
2271
+ ctx__unique_rule = ctx.unique_rule
2272
+
2273
+ visit_if_map(ctx__unique_rule)
2274
+ end
2275
+
2276
+ def visit_unique_rule(ctx)
2277
+ ctx__rule_label_id = ctx.rule_label_id
2278
+ ctx__referenced_attribute = ctx.referenced_attribute
2279
+
2280
+ id = visit_if(ctx__rule_label_id)
2281
+ attributes = visit_if_map(ctx__referenced_attribute)
2282
+
2283
+ Model::Unique.new({
2284
+ id: id,
2285
+ attributes: attributes
2286
+ })
2287
+ end
2288
+
2289
+ def visit_until_control(ctx)
2290
+ ctx__logical_expression = ctx.logical_expression
2291
+
2292
+ visit_if(ctx__logical_expression)
2293
+ end
2294
+
2295
+ def visit_use_clause(ctx)
2296
+ ctx__schema_ref = ctx.schema_ref
2297
+ ctx__named_type_or_rename = ctx.named_type_or_rename
2298
+
2299
+ schema = visit_if(ctx__schema_ref)
2300
+ items = visit_if_map(ctx__named_type_or_rename)
2301
+
2302
+ Model::Interface.new({
2303
+ kind: Model::Interface::USE,
2304
+ schema: schema,
2305
+ items: items
2306
+ })
2307
+ end
2308
+
2309
+ def visit_variable_id(ctx)
2310
+ ctx__SimpleId = ctx.SimpleId
2311
+
2312
+ handle_simple_id(ctx__SimpleId)
2313
+ end
2314
+
2315
+ def visit_where_clause(ctx)
2316
+ ctx__domain_rule = ctx.domain_rule
2317
+
2318
+ visit_if_map(ctx__domain_rule)
2319
+ end
2320
+
2321
+ def visit_while_control(ctx)
2322
+ ctx__logical_expression = ctx.logical_expression
2323
+
2324
+ visit_if(ctx__logical_expression)
2325
+ end
2326
+
2327
+ def visit_width(ctx)
2328
+ ctx__numeric_expression = ctx.numeric_expression
2329
+
2330
+ visit_if(ctx__numeric_expression)
2331
+ end
2332
+
2333
+ def visit_width_spec(ctx)
2334
+ raise 'Invalid state'
2335
+ end
2336
+
2337
+ private
2338
+
2339
+ def handle_binary_expression(operands, operators)
2340
+ if operands.length != operators.length + 1
2341
+ raise 'Invalid state'
2342
+ end
2343
+
2344
+ expression = Model::Expressions::BinaryExpression.new({
2345
+ operator: operators[0],
2346
+ operand1: operands[0],
2347
+ operand2: operands[1]
2348
+ })
2349
+ operators[1..(operators.length - 1)].each_with_index do |operator, i|
2350
+ expression = Model::Expressions::BinaryExpression.new({
2351
+ operator: operator,
2352
+ operand1: expression,
2353
+ operand2: operands[i + 2]
2354
+ })
2355
+ end
2356
+ expression
2357
+ end
2358
+
2359
+ def handle_qualified_ref(ref, qualifiers)
2360
+ qualifiers.reduce(ref) do |ref, ctx|
2361
+ ctx__attribute_qualifier = ctx.attribute_qualifier
2362
+ ctx__group_qualifier = ctx.group_qualifier
2363
+ ctx__index_qualifier = ctx.index_qualifier
2364
+
2365
+ if ctx__attribute_qualifier
2366
+ attribute_reference = visit_if(ctx__attribute_qualifier)
2367
+
2368
+ Model::Expressions::AttributeReference.new({
2369
+ ref: ref,
2370
+ attribute: attribute_reference.attribute
2371
+ })
2372
+ elsif ctx__group_qualifier
2373
+ group_reference = visit_if(ctx__group_qualifier)
2374
+
2375
+ Model::Expressions::GroupReference.new({
2376
+ ref: ref,
2377
+ entity: group_reference.entity
2378
+ })
2379
+ elsif ctx__index_qualifier
2380
+ index_reference = visit_if(ctx__index_qualifier)
2381
+
2382
+ Model::Expressions::IndexReference.new({
2383
+ ref: ref,
2384
+ index1: index_reference.index1,
2385
+ index2: index_reference.index2
2386
+ })
2387
+ else
2388
+ raise 'Invalid state'
2389
+ end
2390
+ end
2391
+ end
2392
+
2393
+ def handle_binary_literal(ctx)
2394
+ ctx__text = ctx.text
2395
+
2396
+ value = ctx__text[1..(ctx__text.length - 1)]
2397
+
2398
+ Model::Literals::Binary.new({
2399
+ value: value
2400
+ })
2401
+ end
2402
+
2403
+ def handle_integer_literal(ctx)
2404
+ ctx__text = ctx.text
2405
+
2406
+ value = ctx__text
2407
+
2408
+ Model::Literals::Integer.new({
2409
+ value: value
2410
+ })
2411
+ end
2412
+
2413
+ def handle_real_literal(ctx)
2414
+ ctx__text = ctx.text
2415
+
2416
+ value = ctx__text
2417
+
2418
+ Model::Literals::Real.new({
2419
+ value: value
2420
+ })
2421
+ end
2422
+
2423
+ def handle_simple_id(ctx)
2424
+ ctx__text = ctx.text
2425
+
2426
+ ctx__text
2427
+ end
2428
+
2429
+ def handle_simple_string_literal(ctx)
2430
+ ctx__text = ctx.text
2431
+
2432
+ value = ctx__text[1..(ctx__text.length - 2)]
2433
+
2434
+ Model::Literals::String.new({
2435
+ value: value
2436
+ })
2437
+ end
2438
+
2439
+ def handle_encoded_string_literal(ctx)
2440
+ ctx__text = ctx.text
2441
+
2442
+ value = ctx__text[1..(ctx__text.length - 2)]
2443
+
2444
+ Model::Literals::String.new({
2445
+ value: value,
2446
+ encoded: true
2447
+ })
2448
+ end
2449
+ end
2450
+ end
2134
2451
  end