expressir 0.2.24-arm64-darwin → 1.1.0-arm64-darwin

Sign up to get free protection for your applications and to get access to all the features.
Files changed (212) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +7 -6
  3. data/.gitignore +2 -2
  4. data/.yardopts +11 -0
  5. data/Rakefile +3 -0
  6. data/demo.rb +5 -5
  7. data/exe/format +10 -73
  8. data/exe/format-test +81 -0
  9. data/expressir.gemspec +3 -1
  10. data/lib/expressir.rb +0 -1
  11. data/lib/expressir/cli.rb +0 -6
  12. data/lib/expressir/{express_exp → express}/2.4/express_parser.bundle +0 -0
  13. data/lib/expressir/{express_exp → express}/2.5/express_parser.bundle +0 -0
  14. data/lib/expressir/{express_exp → express}/2.6/express_parser.bundle +0 -0
  15. data/lib/expressir/{express_exp → express}/2.7/express_parser.bundle +0 -0
  16. data/lib/expressir/{express_exp → express}/3.0/express_parser.bundle +0 -0
  17. data/lib/expressir/express/cache.rb +51 -0
  18. data/lib/expressir/{express_exp → express}/formatter.rb +306 -239
  19. data/lib/expressir/express/hyperlink_formatter.rb +36 -0
  20. data/lib/expressir/express/model_visitor.rb +24 -0
  21. data/lib/expressir/express/parser.rb +81 -0
  22. data/lib/expressir/express/resolve_references_model_visitor.rb +31 -0
  23. data/lib/expressir/express/schema_head_formatter.rb +23 -0
  24. data/lib/expressir/{express_exp → express}/visitor.rb +318 -270
  25. data/lib/expressir/model.rb +52 -43
  26. data/lib/expressir/model/cache.rb +6 -2
  27. data/lib/expressir/model/data_type.rb +9 -0
  28. data/lib/expressir/model/data_types/aggregate.rb +31 -0
  29. data/lib/expressir/model/data_types/array.rb +31 -0
  30. data/lib/expressir/model/data_types/bag.rb +25 -0
  31. data/lib/expressir/model/data_types/binary.rb +22 -0
  32. data/lib/expressir/model/data_types/boolean.rb +10 -0
  33. data/lib/expressir/model/data_types/enumeration.rb +25 -0
  34. data/lib/expressir/model/data_types/enumeration_item.rb +26 -0
  35. data/lib/expressir/model/data_types/generic.rb +26 -0
  36. data/lib/expressir/model/data_types/generic_entity.rb +26 -0
  37. data/lib/expressir/model/data_types/integer.rb +10 -0
  38. data/lib/expressir/model/data_types/list.rb +28 -0
  39. data/lib/expressir/model/data_types/logical.rb +10 -0
  40. data/lib/expressir/model/data_types/number.rb +10 -0
  41. data/lib/expressir/model/data_types/real.rb +19 -0
  42. data/lib/expressir/model/data_types/select.rb +28 -0
  43. data/lib/expressir/model/data_types/set.rb +25 -0
  44. data/lib/expressir/model/data_types/string.rb +22 -0
  45. data/lib/expressir/model/declaration.rb +9 -0
  46. data/lib/expressir/model/declarations/attribute.rb +47 -0
  47. data/lib/expressir/model/declarations/constant.rb +34 -0
  48. data/lib/expressir/model/declarations/entity.rb +53 -0
  49. data/lib/expressir/model/declarations/function.rb +67 -0
  50. data/lib/expressir/model/declarations/interface.rb +28 -0
  51. data/lib/expressir/model/declarations/interface_item.rb +23 -0
  52. data/lib/expressir/model/declarations/interfaced_item.rb +37 -0
  53. data/lib/expressir/model/declarations/parameter.rb +34 -0
  54. data/lib/expressir/model/declarations/procedure.rb +64 -0
  55. data/lib/expressir/model/declarations/remark_item.rb +21 -0
  56. data/lib/expressir/model/declarations/rule.rb +71 -0
  57. data/lib/expressir/model/declarations/schema.rb +117 -0
  58. data/lib/expressir/model/declarations/schema_version.rb +22 -0
  59. data/lib/expressir/model/declarations/schema_version_item.rb +22 -0
  60. data/lib/expressir/model/declarations/subtype_constraint.rb +40 -0
  61. data/lib/expressir/model/declarations/type.rb +45 -0
  62. data/lib/expressir/model/declarations/unique_rule.rb +31 -0
  63. data/lib/expressir/model/declarations/variable.rb +34 -0
  64. data/lib/expressir/model/declarations/where_rule.rb +31 -0
  65. data/lib/expressir/model/expression.rb +9 -0
  66. data/lib/expressir/model/expressions/aggregate_initializer.rb +7 -3
  67. data/lib/expressir/model/expressions/aggregate_initializer_item.rb +22 -0
  68. data/lib/expressir/model/expressions/binary_expression.rb +16 -5
  69. data/lib/expressir/model/expressions/entity_constructor.rb +9 -4
  70. data/lib/expressir/model/expressions/function_call.rb +22 -0
  71. data/lib/expressir/model/expressions/interval.rb +17 -6
  72. data/lib/expressir/model/expressions/query_expression.rb +11 -7
  73. data/lib/expressir/model/expressions/unary_expression.rb +9 -3
  74. data/lib/expressir/model/identifier.rb +26 -4
  75. data/lib/expressir/model/literal.rb +9 -0
  76. data/lib/expressir/model/literals/binary.rb +6 -2
  77. data/lib/expressir/model/literals/integer.rb +6 -2
  78. data/lib/expressir/model/literals/logical.rb +6 -2
  79. data/lib/expressir/model/literals/real.rb +6 -2
  80. data/lib/expressir/model/literals/string.rb +8 -3
  81. data/lib/expressir/model/model_element.rb +70 -37
  82. data/lib/expressir/model/reference.rb +9 -0
  83. data/lib/expressir/model/references/attribute_reference.rb +22 -0
  84. data/lib/expressir/model/references/group_reference.rb +22 -0
  85. data/lib/expressir/model/references/index_reference.rb +27 -0
  86. data/lib/expressir/model/references/simple_reference.rb +24 -0
  87. data/lib/expressir/model/repository.rb +8 -2
  88. data/lib/expressir/model/statement.rb +9 -0
  89. data/lib/expressir/model/statements/alias.rb +12 -8
  90. data/lib/expressir/model/statements/assignment.rb +8 -3
  91. data/lib/expressir/model/statements/case.rb +11 -5
  92. data/lib/expressir/model/statements/case_action.rb +8 -3
  93. data/lib/expressir/model/statements/compound.rb +7 -3
  94. data/lib/expressir/model/statements/escape.rb +3 -1
  95. data/lib/expressir/model/statements/if.rb +12 -6
  96. data/lib/expressir/model/statements/null.rb +3 -1
  97. data/lib/expressir/model/statements/procedure_call.rb +22 -0
  98. data/lib/expressir/model/statements/repeat.rb +20 -12
  99. data/lib/expressir/model/statements/return.rb +6 -2
  100. data/lib/expressir/model/statements/skip.rb +3 -1
  101. data/lib/expressir/model/supertype_expression.rb +9 -0
  102. data/lib/expressir/model/supertype_expressions/binary_supertype_expression.rb +29 -0
  103. data/lib/expressir/model/supertype_expressions/oneof_supertype_expression.rb +19 -0
  104. data/lib/expressir/version.rb +1 -1
  105. data/rakelib/cross-ruby.rake +1 -1
  106. data/spec/expressir/{express_exp → express}/cache_spec.rb +9 -9
  107. data/spec/expressir/express/formatter_spec.rb +127 -0
  108. data/spec/expressir/{express_exp → express}/parser_spec.rb +24 -24
  109. data/spec/expressir/model/model_element_spec.rb +181 -129
  110. data/{original/examples → spec}/syntax/multiple.exp +1 -1
  111. data/spec/syntax/multiple.yaml +198 -0
  112. data/{original/examples → spec}/syntax/multiple_formatted.exp +1 -1
  113. data/{original/examples → spec}/syntax/multiple_hyperlink_formatted.exp +4 -4
  114. data/{original/examples → spec}/syntax/multiple_schema_head_hyperlink_formatted.exp +1 -1
  115. data/{original/examples → spec}/syntax/remark.exp +0 -0
  116. data/{original/examples → spec}/syntax/remark.yaml +87 -73
  117. data/{original/examples → spec}/syntax/remark_formatted.exp +0 -0
  118. data/spec/syntax/single.exp +4 -0
  119. data/spec/syntax/single.yaml +18 -0
  120. data/spec/syntax/single_formatted.exp +10 -0
  121. data/spec/syntax/single_formatted.yaml +36 -0
  122. data/{original/examples → spec}/syntax/syntax.exp +11 -11
  123. data/{original/examples → spec}/syntax/syntax.yaml +1181 -1111
  124. data/{original/examples → spec}/syntax/syntax_formatted.exp +11 -11
  125. data/spec/syntax/syntax_hyperlink_formatted.exp +902 -0
  126. data/{original/examples → spec}/syntax/syntax_schema_head_formatted.exp +1 -1
  127. metadata +124 -114
  128. data/lib/expressir/express.rb +0 -11
  129. data/lib/expressir/express/aggregate_dimension.rb +0 -38
  130. data/lib/expressir/express/attribute.rb +0 -15
  131. data/lib/expressir/express/comment.rb +0 -7
  132. data/lib/expressir/express/defined_type.rb +0 -36
  133. data/lib/expressir/express/derived.rb +0 -65
  134. data/lib/expressir/express/derived_aggregate.rb +0 -43
  135. data/lib/expressir/express/entity.rb +0 -137
  136. data/lib/expressir/express/explicit.rb +0 -70
  137. data/lib/expressir/express/explicit_aggregate.rb +0 -46
  138. data/lib/expressir/express/explicit_or_derived.rb +0 -16
  139. data/lib/expressir/express/global_rule.rb +0 -44
  140. data/lib/expressir/express/interface_specification.rb +0 -51
  141. data/lib/expressir/express/interfaced_item.rb +0 -38
  142. data/lib/expressir/express/inverse.rb +0 -46
  143. data/lib/expressir/express/inverse_aggregate.rb +0 -37
  144. data/lib/expressir/express/model_element.rb +0 -7
  145. data/lib/expressir/express/named_type.rb +0 -19
  146. data/lib/expressir/express/remark.rb +0 -8
  147. data/lib/expressir/express/repository.rb +0 -306
  148. data/lib/expressir/express/schema_definition.rb +0 -96
  149. data/lib/expressir/express/subtype_constraint.rb +0 -14
  150. data/lib/expressir/express/type.rb +0 -26
  151. data/lib/expressir/express/type_aggregate.rb +0 -42
  152. data/lib/expressir/express/type_enum.rb +0 -29
  153. data/lib/expressir/express/type_parser.rb +0 -45
  154. data/lib/expressir/express/type_select.rb +0 -82
  155. data/lib/expressir/express/unique_rule.rb +0 -35
  156. data/lib/expressir/express/where_rule.rb +0 -32
  157. data/lib/expressir/express_exp/cache.rb +0 -48
  158. data/lib/expressir/express_exp/hyperlink_formatter.rb +0 -27
  159. data/lib/expressir/express_exp/parser.rb +0 -64
  160. data/lib/expressir/express_exp/schema_head_formatter.rb +0 -9
  161. data/lib/expressir/express_parser.rb +0 -30
  162. data/lib/expressir/model/attribute.rb +0 -38
  163. data/lib/expressir/model/constant.rb +0 -28
  164. data/lib/expressir/model/entity.rb +0 -42
  165. data/lib/expressir/model/enumeration_item.rb +0 -22
  166. data/lib/expressir/model/expressions/aggregate_item.rb +0 -17
  167. data/lib/expressir/model/expressions/attribute_reference.rb +0 -17
  168. data/lib/expressir/model/expressions/call.rb +0 -17
  169. data/lib/expressir/model/expressions/group_reference.rb +0 -17
  170. data/lib/expressir/model/expressions/index_reference.rb +0 -19
  171. data/lib/expressir/model/expressions/simple_reference.rb +0 -15
  172. data/lib/expressir/model/function.rb +0 -57
  173. data/lib/expressir/model/interface.rb +0 -20
  174. data/lib/expressir/model/interface_item.rb +0 -15
  175. data/lib/expressir/model/interfaced_item.rb +0 -31
  176. data/lib/expressir/model/parameter.rb +0 -28
  177. data/lib/expressir/model/procedure.rb +0 -55
  178. data/lib/expressir/model/remark_item.rb +0 -15
  179. data/lib/expressir/model/rule.rb +0 -60
  180. data/lib/expressir/model/schema.rb +0 -98
  181. data/lib/expressir/model/statements/call.rb +0 -17
  182. data/lib/expressir/model/subtype_constraint.rb +0 -32
  183. data/lib/expressir/model/type.rb +0 -37
  184. data/lib/expressir/model/types/aggregate.rb +0 -28
  185. data/lib/expressir/model/types/array.rb +0 -23
  186. data/lib/expressir/model/types/bag.rb +0 -19
  187. data/lib/expressir/model/types/binary.rb +0 -17
  188. data/lib/expressir/model/types/boolean.rb +0 -8
  189. data/lib/expressir/model/types/enumeration.rb +0 -21
  190. data/lib/expressir/model/types/generic.rb +0 -24
  191. data/lib/expressir/model/types/generic_entity.rb +0 -24
  192. data/lib/expressir/model/types/integer.rb +0 -8
  193. data/lib/expressir/model/types/list.rb +0 -21
  194. data/lib/expressir/model/types/logical.rb +0 -8
  195. data/lib/expressir/model/types/number.rb +0 -8
  196. data/lib/expressir/model/types/real.rb +0 -15
  197. data/lib/expressir/model/types/select.rb +0 -23
  198. data/lib/expressir/model/types/set.rb +0 -19
  199. data/lib/expressir/model/types/string.rb +0 -17
  200. data/lib/expressir/model/unique.rb +0 -26
  201. data/lib/expressir/model/variable.rb +0 -28
  202. data/lib/expressir/model/where.rb +0 -26
  203. data/lib/expressir/parser.rb +0 -6
  204. data/lib/expressir/parser/owl_parser.rb +0 -8
  205. data/original/examples/syntax/multiple.yaml +0 -184
  206. data/original/examples/syntax/single.exp +0 -3
  207. data/original/examples/syntax/single.yaml +0 -9
  208. data/original/examples/syntax/single_formatted.exp +0 -6
  209. data/original/examples/syntax/single_formatted.yaml +0 -19
  210. data/spec/acceptance/express_to_owl_spec.rb +0 -18
  211. data/spec/expressir/express/repository_spec.rb +0 -25
  212. data/spec/expressir/express_exp/formatter_spec.rb +0 -111
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c54f25073ecc7278ea37324e1477cff4da9c26b9c3a10232fd46ce56a5249d06
4
- data.tar.gz: 2e1608be278b9e437c25e03de624a83ee4a1f6f3f0eb97dbccb2cff97fe6e9a0
3
+ metadata.gz: 4caa2c0ff518f736c26feaa5607a109899412b48cbaee1a52e70ebc479a73cb6
4
+ data.tar.gz: 23ea8b2be6b47f496f71abf90e85e8f29b1f7912d3c1ef8b5f2fa72a02a43bf6
5
5
  SHA512:
6
- metadata.gz: f1f2f68a36cb6570af3a9dbb05ddbd0ff9569b67dceb5f6caa1144338fff16fa08d8ef25f3858f8056bc6236ca17002a1c4c379b7b1776f9a7954eb14c91ab18
7
- data.tar.gz: ea2c69c479755d193a420e6a8d54aacf4627ef90f4bd1bd17b71ecbc3fef8d02dcf53003edb78167f85a745f0a447aff02c35b3dac2e180b90bde46205c3c1fc
6
+ metadata.gz: a8078dd333cf35c5a270b88240cb69031570e978348c666fb8698bc4088e28deff85af9a70645bca51253b1fc9f945ca71d232ee07f488c743b4cb02a4fa632e
7
+ data.tar.gz: 3ea61208b7a93387693fe9ddbfaaf6aea924abb08a56ecca4fd9d450cdb44a11b10055cef1b68dae14d169d4f1cbfe5f4fd5f94116230ff35798bab0f6d426f1
@@ -40,11 +40,12 @@ jobs:
40
40
  ruby-version: ${{ matrix.ruby }}
41
41
  bundler-cache: true
42
42
 
43
- - run: bundle exec rake compile
43
+ - uses: actions/cache@v2
44
+ with:
45
+ path: lib/expressir/express/express_parser.*
46
+ key: v4-${{ runner.os }}-${{ matrix.ruby }}-${{ hashFiles('ext/express-parser/extconf.rb', 'ext/express-parser/antlrgen/**', 'ext/express-parser/express_parser.cpp', '.git/modules/ext/express-parser/antlr4-upstream/HEAD') }}
44
47
 
45
- - run: bundle exec rake
48
+ - if: hashFiles('lib/expressir/express/express_parser.*') == ''
49
+ run: bundle exec rake compile
46
50
 
47
- - uses: actions/upload-artifact@v2
48
- with:
49
- name: express_parser-${{ matrix.os }}-${{ matrix.ruby }}
50
- path: lib/expressir/express_exp/express_parser.so
51
+ - run: bundle exec rake
data/.gitignore CHANGED
@@ -8,8 +8,8 @@
8
8
  /tmp/
9
9
  /Gemfile.lock
10
10
  /.idea
11
- /lib/expressir/express_exp/express_parser.bundle
12
- /original/examples/syntax/*-pretty.exp
11
+ /lib/expressir/express/express_parser.bundle
12
+ /spec/syntax/*-pretty.exp
13
13
 
14
14
  # rspec failure tracking
15
15
  .rspec_status
data/.yardopts ADDED
@@ -0,0 +1,11 @@
1
+ # macro must be defined first, see https://stackoverflow.com/a/10344776/1823988
2
+ lib/expressir/model/model_element.rb
3
+ lib/expressir/model/data_type.rb
4
+ lib/expressir/model/declaration.rb
5
+ lib/expressir/model/expression.rb
6
+ lib/expressir/model/literal.rb
7
+ lib/expressir/model/reference.rb
8
+ lib/expressir/model/statement.rb
9
+ lib/expressir/model/supertype_expression.rb
10
+
11
+ lib/**/*.rb
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
  require "rake/extensiontask"
4
+ require "yard"
4
5
 
5
6
  RSpec::Core::RakeTask.new(:spec)
6
7
 
@@ -9,3 +10,5 @@ task :default => :spec
9
10
  GEMSPEC = Gem::Specification.load("expressir.gemspec")
10
11
 
11
12
  Gem::PackageTask.new(GEMSPEC).define
13
+
14
+ YARD::Rake::YardocTask.new
data/demo.rb CHANGED
@@ -1,18 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'expressir'
4
- require 'expressir/express_exp/parser'
4
+ require 'expressir/express/parser'
5
5
 
6
6
  # This file is from:
7
7
  # https://github.com/metanorma/annotated-express/blob/master/data/resources/action_schema/action_schema.exp
8
8
  file = 'action_schema.exp'
9
9
 
10
- # repo = Expressir::ExpressExp::Parser.from_exp(file)
10
+ # repo = Expressir::Express::Parser.from_exp(file)
11
11
  # schema = repo.schemas.find{|schema| schema.id == "support_resource_schema"}
12
12
 
13
- repo = Expressir::ExpressExp::Parser.from_exp(file)
13
+ repo = Expressir::Express::Parser.from_exp(file)
14
14
  schema = repo.schemas.find{|schema| schema.id == "action_schema"}
15
15
  entity = schema.entities.find{|entity| entity.id == "action_directive_relationship"}
16
- where = entity.where.find{|where| where.id == "WR1"}
16
+ where_rule = entity.where_rules.find{|where_rule| where_rule.id == "WR1"}
17
17
 
18
- puts where.inspect
18
+ puts where_rule.inspect
data/exe/format CHANGED
@@ -1,81 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "yaml"
4
- require "tempfile"
5
- require "expressir/express_exp/parser"
6
- require "expressir/express_exp/formatter"
7
- require "expressir/express_exp/schema_head_formatter"
8
- require "expressir/express_exp/hyperlink_formatter"
9
- require "expressir/express_exp/cache"
4
+ require "expressir/express/parser"
5
+ require "expressir/express/formatter"
6
+ require "expressir/express/schema_head_formatter"
7
+ require "expressir/express/hyperlink_formatter"
10
8
 
11
- exp_files = [
12
- # basic test
13
- # '../iso-10303-stepmod/data/resources/action_schema/action_schema_annotated.exp',
14
- # '../iso-10303-stepmod/data/resources/basic_attribute_schema/basic_attribute_schema_annotated.exp',
15
- # '../iso-10303-stepmod/data/resources/support_resource_schema/support_resource_schema_annotated.exp',
16
- # cyclic reference test
17
- # '../iso-10303-stepmod/data/modules/analysis/mim_annotated.exp',
18
- # '../iso-10303-stepmod/data/modules/analysis_product_relationships/mim_annotated.exp',
19
- # cyclic reference test 2
20
- # '../iso-10303-stepmod/data/resources/product_property_definition_schema/product_property_definition_schema_annotated.exp',
21
- # '../iso-10303-stepmod/data/resources/product_property_representation_schema/product_property_representation_schema_annotated.exp',
22
- # renamed reference test (36s)
23
- # '../iso-10303-stepmod/ballots/ballots/ap210_wg12/express/resources/mathematical_functions_schema.exp',
24
- # '../iso-10303-stepmod/data/resources/iso13584_expressions_schema/iso13584_expressions_schema.exp',
25
- # annotated-express test (12s)
26
- # see https://github.com/metanorma/annotated-express/blob/master/data/documents/resources/fundamentals_of_product_description_and_support/sections/04-schemas.adoc
27
- '../iso-10303-stepmod/data/resources/action_schema/action_schema_annotated.exp',
28
- '../iso-10303-stepmod/data/resources/application_context_schema/application_context_schema_annotated.exp',
29
- '../iso-10303-stepmod/data/resources/approval_schema/approval_schema_annotated.exp',
30
- '../iso-10303-stepmod/data/resources/basic_attribute_schema/basic_attribute_schema_annotated.exp',
31
- '../iso-10303-stepmod/data/resources/certification_schema/certification_schema_annotated.exp',
32
- '../iso-10303-stepmod/data/resources/contract_schema/contract_schema_annotated.exp',
33
- '../iso-10303-stepmod/data/resources/date_time_schema/date_time_schema_annotated.exp',
34
- '../iso-10303-stepmod/data/resources/document_schema/document_schema.exp',
35
- '../iso-10303-stepmod/data/resources/effectivity_schema/effectivity_schema_annotated.exp',
36
- '../iso-10303-stepmod/data/resources/experience_schema/experience_schema_annotated.exp',
37
- '../iso-10303-stepmod/data/resources/external_reference_schema/external_reference_schema_annotated.exp',
38
- '../iso-10303-stepmod/data/resources/group_schema/group_schema_annotated.exp',
39
- '../iso-10303-stepmod/data/resources/language_schema/language_schema_annotated.exp',
40
- '../iso-10303-stepmod/data/resources/location_schema/location_schema_annotated.exp',
41
- '../iso-10303-stepmod/data/resources/management_resources_schema/management_resources_schema_annotated.exp',
42
- '../iso-10303-stepmod/data/resources/measure_schema/measure_schema_annotated.exp',
43
- '../iso-10303-stepmod/data/resources/person_organization_schema/person_organization_schema_annotated.exp',
44
- '../iso-10303-stepmod/data/resources/process_property_schema/process_property_schema_annotated.exp',
45
- '../iso-10303-stepmod/data/resources/product_definition_schema/product_definition_schema_annotated.exp',
46
- '../iso-10303-stepmod/data/resources/product_property_definition_schema/product_property_definition_schema_annotated.exp',
47
- '../iso-10303-stepmod/data/resources/product_property_representation_schema/product_property_representation_schema_annotated.exp',
48
- '../iso-10303-stepmod/data/resources/qualifications_schema/qualifications_schema_annotated.exp',
49
- '../iso-10303-stepmod/data/resources/security_classification_schema/security_classification_schema_annotated.exp',
50
- '../iso-10303-stepmod/data/resources/support_resource_schema/support_resource_schema_annotated.exp',
51
- # full test (6m18s + 8s = 6m26s)
52
- # *`bundle exec ../stepmod-utils/exe/stepmod-find-express-files ../iso-10303-stepmod`.strip.split("\n").map{|file| File.exists?(file.sub(/\.exp$/, '_annotated.exp')) ? file.sub(/\.exp$/, '_annotated.exp') : file}
53
- ]
9
+ exp_files = ARGV
54
10
 
55
- start = Time.now
56
- repository = Expressir::ExpressExp::Parser.from_files(exp_files)
57
- puts "Parser.from_files time: #{(Time.now - start).round(2)}s"
58
-
59
- temp_file = Tempfile.new
60
- begin
61
- start = Time.now
62
- Expressir::ExpressExp::Cache.to_file(temp_file, repository)
63
- puts "Cache.to_file time: #{(Time.now - start).round(2)}s"
64
-
65
- start = Time.now
66
- repository = Expressir::ExpressExp::Cache.from_file(temp_file)
67
- puts "Cache.from_file time: #{(Time.now - start).round(2)}s"
68
- ensure
69
- temp_file.close
70
- temp_file.unlink
71
- end
72
-
73
- start = Time.now
74
- formatter = Class.new(Expressir::ExpressExp::Formatter) do
75
- include Expressir::ExpressExp::SchemaHeadFormatter
76
- include Expressir::ExpressExp::HyperlinkFormatter
11
+ repository = Expressir::Express::Parser.from_files(exp_files)
12
+ formatter = Class.new(Expressir::Express::Formatter) do
13
+ include Expressir::Express::SchemaHeadFormatter
14
+ include Expressir::Express::HyperlinkFormatter
77
15
  end
78
16
  result = repository.to_hash(formatter: formatter, skip_empty: true)
79
- puts "Repository.to_hash time: #{(Time.now - start).round(2)}s"
80
17
 
81
- # puts YAML.dump(result)
18
+ puts YAML.dump(result)
data/exe/format-test ADDED
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "yaml"
4
+ require "tempfile"
5
+ require "expressir/express/parser"
6
+ require "expressir/express/formatter"
7
+ require "expressir/express/schema_head_formatter"
8
+ require "expressir/express/hyperlink_formatter"
9
+ require "expressir/express/cache"
10
+
11
+ exp_files = [
12
+ # basic test
13
+ # '../iso-10303-stepmod/data/resources/action_schema/action_schema_annotated.exp',
14
+ # '../iso-10303-stepmod/data/resources/basic_attribute_schema/basic_attribute_schema_annotated.exp',
15
+ # '../iso-10303-stepmod/data/resources/support_resource_schema/support_resource_schema_annotated.exp',
16
+ # cyclic reference test
17
+ # '../iso-10303-stepmod/data/modules/analysis/mim_annotated.exp',
18
+ # '../iso-10303-stepmod/data/modules/analysis_product_relationships/mim_annotated.exp',
19
+ # cyclic reference test 2
20
+ # '../iso-10303-stepmod/data/resources/product_property_definition_schema/product_property_definition_schema_annotated.exp',
21
+ # '../iso-10303-stepmod/data/resources/product_property_representation_schema/product_property_representation_schema_annotated.exp',
22
+ # renamed reference test (36s)
23
+ # '../iso-10303-stepmod/ballots/ballots/ap210_wg12/express/resources/mathematical_functions_schema.exp',
24
+ # '../iso-10303-stepmod/data/resources/iso13584_expressions_schema/iso13584_expressions_schema.exp',
25
+ # annotated-express test (12s)
26
+ # see https://github.com/metanorma/annotated-express/blob/master/data/documents/resources/fundamentals_of_product_description_and_support/sections/04-schemas.adoc
27
+ '../iso-10303-stepmod/data/resources/action_schema/action_schema_annotated.exp',
28
+ '../iso-10303-stepmod/data/resources/application_context_schema/application_context_schema_annotated.exp',
29
+ '../iso-10303-stepmod/data/resources/approval_schema/approval_schema_annotated.exp',
30
+ '../iso-10303-stepmod/data/resources/basic_attribute_schema/basic_attribute_schema_annotated.exp',
31
+ '../iso-10303-stepmod/data/resources/certification_schema/certification_schema_annotated.exp',
32
+ '../iso-10303-stepmod/data/resources/contract_schema/contract_schema_annotated.exp',
33
+ '../iso-10303-stepmod/data/resources/date_time_schema/date_time_schema_annotated.exp',
34
+ '../iso-10303-stepmod/data/resources/document_schema/document_schema.exp',
35
+ '../iso-10303-stepmod/data/resources/effectivity_schema/effectivity_schema_annotated.exp',
36
+ '../iso-10303-stepmod/data/resources/experience_schema/experience_schema_annotated.exp',
37
+ '../iso-10303-stepmod/data/resources/external_reference_schema/external_reference_schema_annotated.exp',
38
+ '../iso-10303-stepmod/data/resources/group_schema/group_schema_annotated.exp',
39
+ '../iso-10303-stepmod/data/resources/language_schema/language_schema_annotated.exp',
40
+ '../iso-10303-stepmod/data/resources/location_schema/location_schema_annotated.exp',
41
+ '../iso-10303-stepmod/data/resources/management_resources_schema/management_resources_schema_annotated.exp',
42
+ '../iso-10303-stepmod/data/resources/measure_schema/measure_schema_annotated.exp',
43
+ '../iso-10303-stepmod/data/resources/person_organization_schema/person_organization_schema_annotated.exp',
44
+ '../iso-10303-stepmod/data/resources/process_property_schema/process_property_schema_annotated.exp',
45
+ '../iso-10303-stepmod/data/resources/product_definition_schema/product_definition_schema_annotated.exp',
46
+ '../iso-10303-stepmod/data/resources/product_property_definition_schema/product_property_definition_schema_annotated.exp',
47
+ '../iso-10303-stepmod/data/resources/product_property_representation_schema/product_property_representation_schema_annotated.exp',
48
+ '../iso-10303-stepmod/data/resources/qualifications_schema/qualifications_schema_annotated.exp',
49
+ '../iso-10303-stepmod/data/resources/security_classification_schema/security_classification_schema_annotated.exp',
50
+ '../iso-10303-stepmod/data/resources/support_resource_schema/support_resource_schema_annotated.exp',
51
+ # full test (6m18s + 8s = 6m26s)
52
+ # *`bundle exec ../stepmod-utils/exe/stepmod-find-express-files ../iso-10303-stepmod`.strip.split("\n").map{|file| File.exists?(file.sub(/\.exp$/, '_annotated.exp')) ? file.sub(/\.exp$/, '_annotated.exp') : file}
53
+ ]
54
+
55
+ start = Time.now
56
+ repository = Expressir::Express::Parser.from_files(exp_files)
57
+ puts "Parser.from_files time: #{(Time.now - start).round(2)}s"
58
+
59
+ temp_file = Tempfile.new
60
+ begin
61
+ start = Time.now
62
+ Expressir::Express::Cache.to_file(temp_file, repository)
63
+ puts "Cache.to_file time: #{(Time.now - start).round(2)}s"
64
+
65
+ start = Time.now
66
+ repository = Expressir::Express::Cache.from_file(temp_file)
67
+ puts "Cache.from_file time: #{(Time.now - start).round(2)}s"
68
+ ensure
69
+ temp_file.close
70
+ temp_file.unlink
71
+ end
72
+
73
+ start = Time.now
74
+ formatter = Class.new(Expressir::Express::Formatter) do
75
+ include Expressir::Express::SchemaHeadFormatter
76
+ include Expressir::Express::HyperlinkFormatter
77
+ end
78
+ result = repository.to_hash(formatter: formatter, skip_empty: true)
79
+ puts "Repository.to_hash time: #{(Time.now - start).round(2)}s"
80
+
81
+ # puts YAML.dump(result)
data/expressir.gemspec CHANGED
@@ -30,9 +30,9 @@ Gem::Specification.new do |spec|
30
30
 
31
31
  spec.extensions = File.join(*%w(ext express-parser extconf.rb))
32
32
 
33
- spec.add_runtime_dependency "nokogiri", "~> 1.10"
34
33
  spec.add_runtime_dependency "thor", "~> 1.0"
35
34
  spec.add_runtime_dependency "rice", "~> 3"
35
+ spec.add_development_dependency "asciidoctor", "~> 2.0.13"
36
36
  spec.add_development_dependency "antlr4-native", "~> 1.1.0"
37
37
  spec.add_development_dependency "bundler", "~> 2.0"
38
38
  spec.add_development_dependency "pry", "~> 0.12.2"
@@ -41,4 +41,6 @@ Gem::Specification.new do |spec|
41
41
  spec.add_development_dependency "rake-compiler", "~> 1.1"
42
42
  spec.add_development_dependency "rake-compiler-dock", "~> 1.1"
43
43
  spec.add_development_dependency "rspec", "~> 3.0"
44
+ spec.add_development_dependency "yard", "~> 0.9.26"
45
+ spec.add_development_dependency "webrick", "~> 1.7.0"
44
46
  end
data/lib/expressir.rb CHANGED
@@ -2,7 +2,6 @@ require "expressir/version"
2
2
 
3
3
  require "expressir/cli"
4
4
  require "expressir/config"
5
- require "expressir/express"
6
5
 
7
6
  module Expressir
8
7
  class Error < StandardError; end
data/lib/expressir/cli.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require "thor"
2
2
  require "expressir/cli/ui"
3
- require "expressir/express_parser"
4
3
 
5
4
  module Expressir
6
5
  module Cli
@@ -17,11 +16,6 @@ module Expressir
17
16
  def version
18
17
  Cli.ui.say("Version #{Expressir::VERSION}")
19
18
  end
20
-
21
- desc "express-to-owl FILE", "Express to OWL conversion"
22
- def express_to_owl(file)
23
- Cli.ui.say(ExpressParser.to_owl(file))
24
- end
25
19
  end
26
20
  end
27
21
  end
@@ -0,0 +1,51 @@
1
+ require 'yaml'
2
+ require 'zlib'
3
+ require 'expressir/model'
4
+
5
+ module Expressir
6
+ module Express
7
+ class Cache
8
+ # Save Express model into a cache file
9
+ # @param file [String] cache file path
10
+ # @param content [Model::ModelElement] Express model
11
+ # @param root_path [String] Express repository root path, to be stripped from Express file paths to create a portable cache file
12
+ # @param test_overwrite_version [String] don't use, only for tests
13
+ # @return [nil]
14
+ def self.to_file(file, content, root_path: nil, test_overwrite_version: nil)
15
+ version = test_overwrite_version || VERSION
16
+
17
+ cache = Model::Cache.new(
18
+ version: version,
19
+ content: content
20
+ )
21
+
22
+ hash = cache.to_hash(root_path: root_path)
23
+ yaml = YAML.dump(hash)
24
+ yaml_compressed = Zlib::Deflate.deflate(yaml)
25
+
26
+ File.binwrite(file, yaml_compressed)
27
+ nil
28
+ end
29
+
30
+ # Load Express model from a cache file
31
+ # @param file [String] cache file path
32
+ # @param root_path [String] Express repository root path, to be prepended to Express file paths if loading a portable cache file
33
+ # @param test_overwrite_version [String] don't use, only for tests
34
+ # @return [Model::ModelElement] Express model
35
+ def self.from_file(file, root_path: nil, test_overwrite_version: nil)
36
+ version = test_overwrite_version || VERSION
37
+
38
+ yaml_compressed = File.binread(file)
39
+ yaml = Zlib::Inflate.inflate(yaml_compressed)
40
+ hash = YAML.load(yaml)
41
+ cache = Model::ModelElement.from_hash(hash, root_path: root_path)
42
+
43
+ if cache.version != version
44
+ raise Error.new("Cache version mismatch, cache version is #{cache.version}, Expressir version is #{version}")
45
+ end
46
+
47
+ cache.content
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,12 +1,11 @@
1
1
  require 'expressir/model'
2
2
 
3
3
  module Expressir
4
- module ExpressExp
4
+ module Express
5
5
  class Formatter
6
6
  INDENT_CHAR = ' '
7
7
  INDENT_WIDTH = 2
8
8
  INDENT = INDENT_CHAR * INDENT_WIDTH
9
-
10
9
  OPERATOR_PRECEDENCE = {
11
10
  Model::Expressions::BinaryExpression::EXPONENTIATION => 1,
12
11
  Model::Expressions::BinaryExpression::MULTIPLICATION => 2,
@@ -29,71 +28,112 @@ module Expressir
29
28
  Model::Expressions::BinaryExpression::INSTANCE_NOT_EQUAL => 4,
30
29
  Model::Expressions::BinaryExpression::IN => 4,
31
30
  Model::Expressions::BinaryExpression::LIKE => 4,
32
- Model::Expressions::BinaryExpression::ANDOR => 4,
33
31
  }
32
+ SUPERTYPE_OPERATOR_PRECEDENCE = {
33
+ Model::SupertypeExpressions::BinarySupertypeExpression::AND => 1,
34
+ Model::SupertypeExpressions::BinarySupertypeExpression::ANDOR => 2,
35
+ }
36
+
37
+ private_constant :INDENT_CHAR
38
+ private_constant :INDENT_WIDTH
39
+ private_constant :INDENT
40
+ private_constant :OPERATOR_PRECEDENCE
41
+ private_constant :SUPERTYPE_OPERATOR_PRECEDENCE
34
42
 
43
+ # Formats Express model into an Express code
44
+ # @param [Model::ModelElement] node
45
+ # @return [String]
35
46
  def self.format(node)
36
47
  formatter = self.new
37
48
  formatter.format(node)
38
49
  end
39
50
 
51
+ # Formats Express model into an Express code
52
+ # @param [Model::ModelElement] node
53
+ # @return [String]
40
54
  def format(node)
41
- if node.is_a? Model::Attribute
42
- format_attribute(node)
43
- elsif node.is_a? Model::Constant
44
- format_constant(node)
45
- elsif node.is_a? Model::Entity
46
- format_entity(node)
47
- elsif node.is_a? Model::EnumerationItem
48
- format_enumeration_item(node)
49
- elsif node.is_a? Model::Function
50
- format_function(node)
51
- elsif node.is_a? Model::Interface
52
- format_interface(node)
53
- elsif node.is_a? Model::InterfaceItem
54
- format_interface_item(node)
55
- elsif node.is_a? Model::Parameter
56
- format_parameter(node)
57
- elsif node.is_a? Model::Procedure
58
- format_procedure(node)
59
- elsif node.is_a? Model::Repository
55
+ if node.is_a? Model::Repository
60
56
  format_repository(node)
61
- elsif node.is_a? Model::Rule
62
- format_rule(node)
63
- elsif node.is_a? Model::Schema
64
- format_schema(node)
65
- elsif node.is_a? Model::SubtypeConstraint
66
- format_subtype_constraint(node)
67
- elsif node.is_a? Model::Type
68
- format_type(node)
69
- elsif node.is_a? Model::Unique
70
- format_unique(node)
71
- elsif node.is_a? Model::Variable
72
- format_variable(node)
73
- elsif node.is_a? Model::Where
74
- format_where(node)
57
+ elsif node.is_a? Model::Declarations::Attribute
58
+ format_declarations_attribute(node)
59
+ elsif node.is_a? Model::Declarations::Constant
60
+ format_declarations_constant(node)
61
+ elsif node.is_a? Model::Declarations::Entity
62
+ format_declarations_entity(node)
63
+ elsif node.is_a? Model::Declarations::Function
64
+ format_declarations_function(node)
65
+ elsif node.is_a? Model::Declarations::Interface
66
+ format_declarations_interface(node)
67
+ elsif node.is_a? Model::Declarations::InterfaceItem
68
+ format_declarations_interface_item(node)
69
+ elsif node.is_a? Model::Declarations::Parameter
70
+ format_declarations_parameter(node)
71
+ elsif node.is_a? Model::Declarations::Procedure
72
+ format_declarations_procedure(node)
73
+ elsif node.is_a? Model::Declarations::Rule
74
+ format_declarations_rule(node)
75
+ elsif node.is_a? Model::Declarations::Schema
76
+ format_declarations_schema(node)
77
+ elsif node.is_a? Model::Declarations::SchemaVersion
78
+ format_declarations_schema_version(node)
79
+ elsif node.is_a? Model::Declarations::SubtypeConstraint
80
+ format_declarations_subtype_constraint(node)
81
+ elsif node.is_a? Model::Declarations::Type
82
+ format_declarations_type(node)
83
+ elsif node.is_a? Model::Declarations::UniqueRule
84
+ format_declarations_unique_rule(node)
85
+ elsif node.is_a? Model::Declarations::Variable
86
+ format_declarations_variable(node)
87
+ elsif node.is_a? Model::Declarations::WhereRule
88
+ format_declarations_where_rule(node)
89
+ elsif node.is_a? Model::DataTypes::Aggregate
90
+ format_data_types_aggregate(node)
91
+ elsif node.is_a? Model::DataTypes::Array
92
+ format_data_types_array(node)
93
+ elsif node.is_a? Model::DataTypes::Bag
94
+ format_data_types_bag(node)
95
+ elsif node.is_a? Model::DataTypes::Binary
96
+ format_data_types_binary(node)
97
+ elsif node.is_a? Model::DataTypes::Boolean
98
+ format_data_types_boolean(node)
99
+ elsif node.is_a? Model::DataTypes::Enumeration
100
+ format_data_types_enumeration(node)
101
+ elsif node.is_a? Model::DataTypes::EnumerationItem
102
+ format_data_types_enumeration_item(node)
103
+ elsif node.is_a? Model::DataTypes::GenericEntity
104
+ format_data_types_generic_entity(node)
105
+ elsif node.is_a? Model::DataTypes::Generic
106
+ format_data_types_generic(node)
107
+ elsif node.is_a? Model::DataTypes::Integer
108
+ format_data_types_integer(node)
109
+ elsif node.is_a? Model::DataTypes::List
110
+ format_data_types_list(node)
111
+ elsif node.is_a? Model::DataTypes::Logical
112
+ format_data_types_logical(node)
113
+ elsif node.is_a? Model::DataTypes::Number
114
+ format_data_types_number(node)
115
+ elsif node.is_a? Model::DataTypes::Real
116
+ format_data_types_real(node)
117
+ elsif node.is_a? Model::DataTypes::Select
118
+ format_data_types_select(node)
119
+ elsif node.is_a? Model::DataTypes::Set
120
+ format_data_types_set(node)
121
+ elsif node.is_a? Model::DataTypes::String
122
+ format_data_types_string(node)
75
123
  elsif node.is_a? Model::Expressions::AggregateInitializer
76
124
  format_expressions_aggregate_initializer(node)
77
- elsif node.is_a? Model::Expressions::AggregateItem
78
- format_expressions_aggregate_item(node)
79
- elsif node.is_a? Model::Expressions::AttributeReference
80
- format_expressions_attribute_reference(node)
125
+ elsif node.is_a? Model::Expressions::AggregateInitializerItem
126
+ format_expressions_aggregate_initializer_item(node)
81
127
  elsif node.is_a? Model::Expressions::BinaryExpression
82
128
  format_expressions_binary_expression(node)
83
- elsif node.is_a? Model::Expressions::Call
84
- format_expressions_call(node)
85
129
  elsif node.is_a? Model::Expressions::EntityConstructor
86
130
  format_expressions_entity_constructor(node)
87
- elsif node.is_a? Model::Expressions::GroupReference
88
- format_expressions_group_reference(node)
89
- elsif node.is_a? Model::Expressions::IndexReference
90
- format_expressions_index_reference(node)
131
+ elsif node.is_a? Model::Expressions::FunctionCall
132
+ format_expressions_function_call(node)
91
133
  elsif node.is_a? Model::Expressions::Interval
92
134
  format_expressions_interval(node)
93
135
  elsif node.is_a? Model::Expressions::QueryExpression
94
136
  format_expressions_query_expression(node)
95
- elsif node.is_a? Model::Expressions::SimpleReference
96
- format_expressions_simple_reference(node)
97
137
  elsif node.is_a? Model::Expressions::UnaryExpression
98
138
  format_expressions_unary_expression(node)
99
139
  elsif node.is_a? Model::Literals::Binary
@@ -106,12 +146,18 @@ module Expressir
106
146
  format_literals_real(node)
107
147
  elsif node.is_a? Model::Literals::String
108
148
  format_literals_string(node)
149
+ elsif node.is_a? Model::References::AttributeReference
150
+ format_references_attribute_reference(node)
151
+ elsif node.is_a? Model::References::GroupReference
152
+ format_references_group_reference(node)
153
+ elsif node.is_a? Model::References::IndexReference
154
+ format_references_index_reference(node)
155
+ elsif node.is_a? Model::References::SimpleReference
156
+ format_references_simple_reference(node)
109
157
  elsif node.is_a? Model::Statements::Alias
110
158
  format_statements_alias(node)
111
159
  elsif node.is_a? Model::Statements::Assignment
112
160
  format_statements_assignment(node)
113
- elsif node.is_a? Model::Statements::Call
114
- format_statements_call(node)
115
161
  elsif node.is_a? Model::Statements::Case
116
162
  format_statements_case(node)
117
163
  elsif node.is_a? Model::Statements::CaseAction
@@ -124,44 +170,18 @@ module Expressir
124
170
  format_statements_if(node)
125
171
  elsif node.is_a? Model::Statements::Null
126
172
  format_statements_null(node)
173
+ elsif node.is_a? Model::Statements::ProcedureCall
174
+ format_statements_procedure_call(node)
127
175
  elsif node.is_a? Model::Statements::Repeat
128
176
  format_statements_repeat(node)
129
177
  elsif node.is_a? Model::Statements::Return
130
178
  format_statements_return(node)
131
179
  elsif node.is_a? Model::Statements::Skip
132
180
  format_statements_skip(node)
133
- elsif node.is_a? Model::Types::Aggregate
134
- format_types_aggregate(node)
135
- elsif node.is_a? Model::Types::Array
136
- format_types_array(node)
137
- elsif node.is_a? Model::Types::Bag
138
- format_types_bag(node)
139
- elsif node.is_a? Model::Types::Binary
140
- format_types_binary(node)
141
- elsif node.is_a? Model::Types::Boolean
142
- format_types_boolean(node)
143
- elsif node.is_a? Model::Types::Enumeration
144
- format_types_enumeration(node)
145
- elsif node.is_a? Model::Types::GenericEntity
146
- format_types_generic_entity(node)
147
- elsif node.is_a? Model::Types::Generic
148
- format_types_generic(node)
149
- elsif node.is_a? Model::Types::Integer
150
- format_types_integer(node)
151
- elsif node.is_a? Model::Types::List
152
- format_types_list(node)
153
- elsif node.is_a? Model::Types::Logical
154
- format_types_logical(node)
155
- elsif node.is_a? Model::Types::Number
156
- format_types_number(node)
157
- elsif node.is_a? Model::Types::Real
158
- format_types_real(node)
159
- elsif node.is_a? Model::Types::Select
160
- format_types_select(node)
161
- elsif node.is_a? Model::Types::Set
162
- format_types_set(node)
163
- elsif node.is_a? Model::Types::String
164
- format_types_string(node)
181
+ elsif node.is_a? Model::SupertypeExpressions::BinarySupertypeExpression
182
+ format_supertype_expressions_binary_supertype_expression(node)
183
+ elsif node.is_a? Model::SupertypeExpressions::OneofSupertypeExpression
184
+ format_supertype_expressions_oneof_supertype_expression(node)
165
185
  else
166
186
  STDERR.puts "#{node.class.name} format not implemented"
167
187
  ''
@@ -170,7 +190,11 @@ module Expressir
170
190
 
171
191
  private
172
192
 
173
- def format_attribute(node)
193
+ def format_repository(node)
194
+ node.schemas.map{|x| format(x)}.join("\n\n")
195
+ end
196
+
197
+ def format_declarations_attribute(node)
174
198
  [
175
199
  *if node.supertype_attribute
176
200
  [
@@ -199,14 +223,14 @@ module Expressir
199
223
  end,
200
224
  ' ',
201
225
  format(node.type),
202
- *if node.kind == Model::Attribute::DERIVED
226
+ *if node.kind == Model::Declarations::Attribute::DERIVED
203
227
  [
204
228
  ' ',
205
229
  ':=',
206
230
  ' ',
207
231
  format(node.expression)
208
232
  ].join('')
209
- elsif node.kind == Model::Attribute::INVERSE
233
+ elsif node.kind == Model::Declarations::Attribute::INVERSE
210
234
  [
211
235
  ' ',
212
236
  'FOR',
@@ -218,7 +242,7 @@ module Expressir
218
242
  ].join('')
219
243
  end
220
244
 
221
- def format_constant(node)
245
+ def format_declarations_constant(node)
222
246
  [
223
247
  node.id,
224
248
  ' ',
@@ -233,10 +257,10 @@ module Expressir
233
257
  ].join('')
234
258
  end
235
259
 
236
- def format_entity(node)
237
- explicit_attributes = node.attributes.select{|x| x.kind == Model::Attribute::EXPLICIT}
238
- derived_attributes = node.attributes.select{|x| x.kind == Model::Attribute::DERIVED}
239
- inverse_attributes = node.attributes.select{|x| x.kind == Model::Attribute::INVERSE}
260
+ def format_declarations_entity(node)
261
+ explicit_attributes = node.attributes.select{|x| x.kind == Model::Declarations::Attribute::EXPLICIT}
262
+ derived_attributes = node.attributes.select{|x| x.kind == Model::Declarations::Attribute::DERIVED}
263
+ inverse_attributes = node.attributes.select{|x| x.kind == Model::Declarations::Attribute::INVERSE}
240
264
 
241
265
  [
242
266
  [
@@ -314,16 +338,16 @@ module Expressir
314
338
  indent(inverse_attributes.map{|x| format(x)}.join("\n")),
315
339
  ]
316
340
  end,
317
- *if node.unique.length > 0
341
+ *if node.unique_rules.length > 0
318
342
  [
319
343
  'UNIQUE',
320
- indent(node.unique.map{|x| format(x)}.join("\n"))
344
+ indent(node.unique_rules.map{|x| format(x)}.join("\n"))
321
345
  ]
322
346
  end,
323
- *if node.where.length > 0
347
+ *if node.where_rules.length > 0
324
348
  [
325
349
  'WHERE',
326
- indent(node.where.map{|x| format(x)}.join("\n")),
350
+ indent(node.where_rules.map{|x| format(x)}.join("\n")),
327
351
  ]
328
352
  end,
329
353
  [
@@ -333,11 +357,7 @@ module Expressir
333
357
  ].join("\n")
334
358
  end
335
359
 
336
- def format_enumeration_item(node)
337
- node.id
338
- end
339
-
340
- def format_function(node)
360
+ def format_declarations_function(node)
341
361
  [
342
362
  [
343
363
  'FUNCTION',
@@ -402,11 +422,11 @@ module Expressir
402
422
  ].join("\n")
403
423
  end
404
424
 
405
- def format_interface(node)
425
+ def format_declarations_interface(node)
406
426
  [
407
427
  case node.kind
408
- when Model::Interface::USE then 'USE'
409
- when Model::Interface::REFERENCE then 'REFERENCE'
428
+ when Model::Declarations::Interface::USE then 'USE'
429
+ when Model::Declarations::Interface::REFERENCE then 'REFERENCE'
410
430
  end,
411
431
  ' ',
412
432
  'FROM',
@@ -427,7 +447,7 @@ module Expressir
427
447
  ].join('')
428
448
  end
429
449
 
430
- def format_interface_item(node)
450
+ def format_declarations_interface_item(node)
431
451
  [
432
452
  format(node.ref),
433
453
  *if node.id
@@ -441,7 +461,7 @@ module Expressir
441
461
  ].join('')
442
462
  end
443
463
 
444
- def format_parameter(node)
464
+ def format_declarations_parameter(node)
445
465
  [
446
466
  *if node.var
447
467
  [
@@ -457,7 +477,7 @@ module Expressir
457
477
  ].join('')
458
478
  end
459
479
 
460
- def format_procedure(node)
480
+ def format_declarations_procedure(node)
461
481
  [
462
482
  [
463
483
  'PROCEDURE',
@@ -518,11 +538,7 @@ module Expressir
518
538
  ].join("\n")
519
539
  end
520
540
 
521
- def format_repository(node)
522
- node.schemas.map{|node| format(node)}.join("\n\n")
523
- end
524
-
525
- def format_rule(node)
541
+ def format_declarations_rule(node)
526
542
  [
527
543
  [
528
544
  'RULE',
@@ -574,10 +590,10 @@ module Expressir
574
590
  *if node.statements.length > 0
575
591
  indent(node.statements.map{|x| format(x)}.join("\n"))
576
592
  end,
577
- *if node.where.length > 0
593
+ *if node.where_rules.length > 0
578
594
  [
579
595
  'WHERE',
580
- indent(node.where.map{|x| format(x)}.join("\n"))
596
+ indent(node.where_rules.map{|x| format(x)}.join("\n"))
581
597
  ]
582
598
  end,
583
599
  [
@@ -587,7 +603,7 @@ module Expressir
587
603
  ].join("\n")
588
604
  end
589
605
 
590
- def format_schema_head(node)
606
+ def format_declarations_schema_head(node)
591
607
  [
592
608
  [
593
609
  'SCHEMA',
@@ -610,7 +626,7 @@ module Expressir
610
626
  ].join("\n")
611
627
  end
612
628
 
613
- def format_schema(node)
629
+ def format_declarations_schema(node)
614
630
  schema_declarations = [
615
631
  *if node.constants.length > 0
616
632
  [
@@ -643,7 +659,7 @@ module Expressir
643
659
  ]
644
660
 
645
661
  [
646
- format_schema_head(node),
662
+ format_declarations_schema_head(node),
647
663
  *if schema_declarations.length > 0
648
664
  [
649
665
  '',
@@ -659,7 +675,15 @@ module Expressir
659
675
  ].join("\n")
660
676
  end
661
677
 
662
- def format_subtype_constraint(node)
678
+ def format_declarations_schema_version(node)
679
+ [
680
+ "'",
681
+ node.value,
682
+ "'"
683
+ ].join('')
684
+ end
685
+
686
+ def format_declarations_subtype_constraint(node)
663
687
  [
664
688
  [
665
689
  'SUBTYPE_CONSTRAINT',
@@ -701,7 +725,7 @@ module Expressir
701
725
  ].join("\n")
702
726
  end
703
727
 
704
- def format_type(node)
728
+ def format_declarations_type(node)
705
729
  [
706
730
  [
707
731
  'TYPE',
@@ -710,13 +734,13 @@ module Expressir
710
734
  ' ',
711
735
  '=',
712
736
  ' ',
713
- format(node.type),
737
+ format(node.underlying_type),
714
738
  ';',
715
739
  ].join(''),
716
- *if node.where.length > 0
740
+ *if node.where_rules.length > 0
717
741
  [
718
742
  'WHERE',
719
- indent(node.where.map{|x| format(x)}.join("\n"))
743
+ indent(node.where_rules.map{|x| format(x)}.join("\n"))
720
744
  ]
721
745
  end,
722
746
  [
@@ -726,7 +750,7 @@ module Expressir
726
750
  ].join("\n")
727
751
  end
728
752
 
729
- def format_unique(node)
753
+ def format_declarations_unique_rule(node)
730
754
  [
731
755
  *if node.id
732
756
  [
@@ -740,7 +764,7 @@ module Expressir
740
764
  ].join('')
741
765
  end
742
766
 
743
- def format_variable(node)
767
+ def format_declarations_variable(node)
744
768
  [
745
769
  node.id,
746
770
  ' ',
@@ -759,7 +783,7 @@ module Expressir
759
783
  ].join('')
760
784
  end
761
785
 
762
- def format_where(node)
786
+ def format_declarations_where_rule(node)
763
787
  [
764
788
  *if node.id
765
789
  [
@@ -781,7 +805,7 @@ module Expressir
781
805
  ].join('')
782
806
  end
783
807
 
784
- def format_expressions_aggregate_item(node)
808
+ def format_expressions_aggregate_initializer_item(node)
785
809
  [
786
810
  format(node.expression),
787
811
  ':',
@@ -789,14 +813,6 @@ module Expressir
789
813
  ].join('')
790
814
  end
791
815
 
792
- def format_expressions_attribute_reference(node)
793
- [
794
- format(node.ref),
795
- '.',
796
- format(node.attribute)
797
- ].join('')
798
- end
799
-
800
816
  def format_expressions_binary_expression(node)
801
817
  [
802
818
  *if node.operand1.is_a? Model::Expressions::BinaryExpression and OPERATOR_PRECEDENCE[node.operand1.operator] > OPERATOR_PRECEDENCE[node.operator]
@@ -810,7 +826,6 @@ module Expressir
810
826
  case node.operator
811
827
  when Model::Expressions::BinaryExpression::ADDITION then '+'
812
828
  when Model::Expressions::BinaryExpression::AND then 'AND'
813
- when Model::Expressions::BinaryExpression::ANDOR then 'ANDOR'
814
829
  when Model::Expressions::BinaryExpression::COMBINE then '||'
815
830
  when Model::Expressions::BinaryExpression::EQUAL then '='
816
831
  when Model::Expressions::BinaryExpression::EXPONENTIATION then '**'
@@ -842,62 +857,39 @@ module Expressir
842
857
  ].join('')
843
858
  end
844
859
 
845
- def format_expressions_call(node)
860
+ def format_expressions_entity_constructor(node)
846
861
  [
847
- format(node.ref),
862
+ format(node.entity),
848
863
  '(',
849
864
  node.parameters.map{|x| format(x)}.join(', '),
850
865
  ')'
851
866
  ].join('')
852
867
  end
853
868
 
854
- def format_expressions_entity_constructor(node)
869
+ def format_expressions_function_call(node)
855
870
  [
856
- format(node.entity),
871
+ format(node.function),
857
872
  '(',
858
873
  node.parameters.map{|x| format(x)}.join(', '),
859
874
  ')'
860
875
  ].join('')
861
876
  end
862
877
 
863
- def format_expressions_group_reference(node)
864
- [
865
- format(node.ref),
866
- '\\',
867
- format(node.entity)
868
- ].join('')
869
- end
870
-
871
- def format_expressions_index_reference(node)
872
- [
873
- format(node.ref),
874
- '[',
875
- format(node.index1),
876
- *if node.index2
877
- [
878
- ':',
879
- format(node.index2)
880
- ].join('')
881
- end,
882
- ']'
883
- ].join('')
884
- end
885
-
886
878
  def format_expressions_interval(node)
887
879
  [
888
880
  '{',
889
881
  format(node.low),
890
882
  ' ',
891
883
  case node.operator1
892
- when Model::Expressions::BinaryExpression::LESS_THAN then '<'
893
- when Model::Expressions::BinaryExpression::LESS_THAN_OR_EQUAL then '<='
884
+ when Model::Expressions::Interval::LESS_THAN then '<'
885
+ when Model::Expressions::Interval::LESS_THAN_OR_EQUAL then '<='
894
886
  end,
895
887
  ' ',
896
888
  format(node.item),
897
889
  ' ',
898
890
  case node.operator2
899
- when Model::Expressions::BinaryExpression::LESS_THAN then '<'
900
- when Model::Expressions::BinaryExpression::LESS_THAN_OR_EQUAL then '<='
891
+ when Model::Expressions::Interval::LESS_THAN then '<'
892
+ when Model::Expressions::Interval::LESS_THAN_OR_EQUAL then '<='
901
893
  end,
902
894
  ' ',
903
895
  format(node.high),
@@ -923,10 +915,6 @@ module Expressir
923
915
  ].join('')
924
916
  end
925
917
 
926
- def format_expressions_simple_reference(node)
927
- node.id
928
- end
929
-
930
918
  def format_expressions_unary_expression(node)
931
919
  [
932
920
  case node.operator
@@ -986,6 +974,41 @@ module Expressir
986
974
  end
987
975
  end
988
976
 
977
+ def format_references_attribute_reference(node)
978
+ [
979
+ format(node.ref),
980
+ '.',
981
+ format(node.attribute)
982
+ ].join('')
983
+ end
984
+
985
+ def format_references_group_reference(node)
986
+ [
987
+ format(node.ref),
988
+ '\\',
989
+ format(node.entity)
990
+ ].join('')
991
+ end
992
+
993
+ def format_references_index_reference(node)
994
+ [
995
+ format(node.ref),
996
+ '[',
997
+ format(node.index1),
998
+ *if node.index2
999
+ [
1000
+ ':',
1001
+ format(node.index2)
1002
+ ].join('')
1003
+ end,
1004
+ ']'
1005
+ ].join('')
1006
+ end
1007
+
1008
+ def format_references_simple_reference(node)
1009
+ node.id
1010
+ end
1011
+
989
1012
  def format_statements_alias(node)
990
1013
  [
991
1014
  [
@@ -1020,9 +1043,9 @@ module Expressir
1020
1043
  ].join('')
1021
1044
  end
1022
1045
 
1023
- def format_statements_call(node)
1046
+ def format_statements_procedure_call(node)
1024
1047
  [
1025
- format(node.ref),
1048
+ format(node.procedure),
1026
1049
  *if node.parameters.length > 0
1027
1050
  [
1028
1051
  '(',
@@ -1200,11 +1223,45 @@ module Expressir
1200
1223
  ].join('')
1201
1224
  end
1202
1225
 
1203
- def format_types_aggregate(node)
1226
+ def format_supertype_expressions_binary_supertype_expression(node)
1227
+ [
1228
+ *if node.operand1.is_a? Model::SupertypeExpressions::BinarySupertypeExpression and SUPERTYPE_OPERATOR_PRECEDENCE[node.operand1.operator] > SUPERTYPE_OPERATOR_PRECEDENCE[node.operator]
1229
+ '('
1230
+ end,
1231
+ format(node.operand1),
1232
+ *if node.operand1.is_a? Model::SupertypeExpressions::BinarySupertypeExpression and SUPERTYPE_OPERATOR_PRECEDENCE[node.operand1.operator] > SUPERTYPE_OPERATOR_PRECEDENCE[node.operator]
1233
+ ')'
1234
+ end,
1235
+ ' ',
1236
+ case node.operator
1237
+ when Model::SupertypeExpressions::BinarySupertypeExpression::AND then 'AND'
1238
+ when Model::SupertypeExpressions::BinarySupertypeExpression::ANDOR then 'ANDOR'
1239
+ end,
1240
+ ' ',
1241
+ *if node.operand2.is_a? Model::SupertypeExpressions::BinarySupertypeExpression and SUPERTYPE_OPERATOR_PRECEDENCE[node.operand2.operator] > SUPERTYPE_OPERATOR_PRECEDENCE[node.operator]
1242
+ '('
1243
+ end,
1244
+ format(node.operand2),
1245
+ *if node.operand2.is_a? Model::SupertypeExpressions::BinarySupertypeExpression and SUPERTYPE_OPERATOR_PRECEDENCE[node.operand2.operator] > SUPERTYPE_OPERATOR_PRECEDENCE[node.operator]
1246
+ ')'
1247
+ end,
1248
+ ].join('')
1249
+ end
1250
+
1251
+ def format_supertype_expressions_oneof_supertype_expression(node)
1252
+ [
1253
+ 'ONEOF',
1254
+ '(',
1255
+ node.operands.map{|x| format(x)}.join(', '),
1256
+ ')'
1257
+ ].join('')
1258
+ end
1259
+
1260
+ def format_data_types_aggregate(node)
1204
1261
  'AGGREGATE'
1205
1262
  end
1206
1263
 
1207
- def format_types_array(node)
1264
+ def format_data_types_array(node)
1208
1265
  [
1209
1266
  'ARRAY',
1210
1267
  *if node.bound1 and node.bound2
@@ -1236,7 +1293,7 @@ module Expressir
1236
1293
  ].join('')
1237
1294
  end
1238
1295
 
1239
- def format_types_bag(node)
1296
+ def format_data_types_bag(node)
1240
1297
  [
1241
1298
  'BAG',
1242
1299
  *if node.bound1 and node.bound2
@@ -1256,7 +1313,7 @@ module Expressir
1256
1313
  ].join('')
1257
1314
  end
1258
1315
 
1259
- def format_types_binary(node)
1316
+ def format_data_types_binary(node)
1260
1317
  [
1261
1318
  'BINARY',
1262
1319
  *if node.width
@@ -1276,11 +1333,11 @@ module Expressir
1276
1333
  ].join('')
1277
1334
  end
1278
1335
 
1279
- def format_types_boolean(node)
1336
+ def format_data_types_boolean(node)
1280
1337
  'BOOLEAN'
1281
1338
  end
1282
1339
 
1283
- def format_types_enumeration(node)
1340
+ def format_data_types_enumeration(node)
1284
1341
  [
1285
1342
  *if node.extensible
1286
1343
  [
@@ -1289,44 +1346,51 @@ module Expressir
1289
1346
  ].join('')
1290
1347
  end,
1291
1348
  'ENUMERATION',
1292
- *if node.items.length > 0
1293
- item_indent = INDENT_CHAR * '('.length
1294
- [
1295
- ' ',
1296
- 'OF',
1297
- "\n",
1298
- indent([
1299
- '(',
1300
- node.items.map{|x| format(x)}.join(",\n#{item_indent}"),
1301
- ')'
1302
- ].join(''))
1303
- ].join('')
1304
- end,
1305
- *if node.extension_type
1349
+ *if node.based_on
1306
1350
  [
1307
1351
  ' ',
1308
1352
  'BASED_ON',
1309
1353
  ' ',
1310
- format(node.extension_type)
1354
+ format(node.based_on),
1355
+ *if node.items.length > 0
1356
+ item_indent = INDENT_CHAR * '('.length
1357
+ [
1358
+ ' ',
1359
+ 'WITH',
1360
+ "\n",
1361
+ indent([
1362
+ '(',
1363
+ node.items.map{|x| format(x)}.join(",\n#{item_indent}"),
1364
+ ')'
1365
+ ].join(''))
1366
+ ].join('')
1367
+ end
1311
1368
  ].join('')
1312
- end,
1313
- *if node.extension_items.length > 0
1314
- item_indent = INDENT_CHAR * '('.length
1369
+ else
1315
1370
  [
1316
- ' ',
1317
- 'WITH',
1318
- "\n",
1319
- indent([
1320
- '(',
1321
- node.extension_items.map{|x| format(x)}.join(",\n#{item_indent}"),
1322
- ')'
1323
- ].join(''))
1371
+ *if node.items.length > 0
1372
+ item_indent = INDENT_CHAR * '('.length
1373
+ [
1374
+ ' ',
1375
+ 'OF',
1376
+ "\n",
1377
+ indent([
1378
+ '(',
1379
+ node.items.map{|x| format(x)}.join(",\n#{item_indent}"),
1380
+ ')'
1381
+ ].join(''))
1382
+ ].join('')
1383
+ end
1324
1384
  ].join('')
1325
1385
  end
1326
1386
  ].join('')
1327
1387
  end
1328
1388
 
1329
- def format_types_generic_entity(node)
1389
+ def format_data_types_enumeration_item(node)
1390
+ node.id
1391
+ end
1392
+
1393
+ def format_data_types_generic_entity(node)
1330
1394
  [
1331
1395
  'GENERIC_ENTITY',
1332
1396
  *if node.id
@@ -1338,7 +1402,7 @@ module Expressir
1338
1402
  ].join('')
1339
1403
  end
1340
1404
 
1341
- def format_types_generic(node)
1405
+ def format_data_types_generic(node)
1342
1406
  [
1343
1407
  'GENERIC',
1344
1408
  *if node.id
@@ -1350,11 +1414,11 @@ module Expressir
1350
1414
  ].join('')
1351
1415
  end
1352
1416
 
1353
- def format_types_integer(node)
1417
+ def format_data_types_integer(node)
1354
1418
  'INTEGER'
1355
1419
  end
1356
1420
 
1357
- def format_types_list(node)
1421
+ def format_data_types_list(node)
1358
1422
  [
1359
1423
  'LIST',
1360
1424
  *if node.bound1 and node.bound2
@@ -1380,15 +1444,15 @@ module Expressir
1380
1444
  ].join('')
1381
1445
  end
1382
1446
 
1383
- def format_types_logical(node)
1447
+ def format_data_types_logical(node)
1384
1448
  'LOGICAL'
1385
1449
  end
1386
1450
 
1387
- def format_types_number(node)
1451
+ def format_data_types_number(node)
1388
1452
  'NUMBER'
1389
1453
  end
1390
1454
 
1391
- def format_types_real(node)
1455
+ def format_data_types_real(node)
1392
1456
  [
1393
1457
  'REAL',
1394
1458
  *if node.precision
@@ -1402,7 +1466,7 @@ module Expressir
1402
1466
  ].join('')
1403
1467
  end
1404
1468
 
1405
- def format_types_select(node)
1469
+ def format_data_types_select(node)
1406
1470
  [
1407
1471
  *if node.extensible
1408
1472
  [
@@ -1417,42 +1481,45 @@ module Expressir
1417
1481
  ].join('')
1418
1482
  end,
1419
1483
  'SELECT',
1420
- *if node.items.length > 0
1421
- item_indent = INDENT_CHAR * '('.length
1422
- [
1423
- "\n",
1424
- indent([
1425
- '(',
1426
- node.items.map{|x| format(x)}.join(",\n#{item_indent}"),
1427
- ')'
1428
- ].join(''))
1429
- ].join('')
1430
- end,
1431
- *if node.extension_type
1484
+ *if node.based_on
1432
1485
  [
1433
1486
  ' ',
1434
1487
  'BASED_ON',
1435
1488
  ' ',
1436
- format(node.extension_type)
1489
+ format(node.based_on),
1490
+ *if node.items.length > 0
1491
+ item_indent = INDENT_CHAR * '('.length
1492
+ [
1493
+ ' ',
1494
+ 'WITH',
1495
+ "\n",
1496
+ indent([
1497
+ '(',
1498
+ node.items.map{|x| format(x)}.join(",\n#{item_indent}"),
1499
+ ')'
1500
+ ].join(''))
1501
+ ].join('')
1502
+ end
1437
1503
  ].join('')
1438
- end,
1439
- *if node.extension_items.length > 0
1440
- item_indent = INDENT_CHAR * '('.length
1504
+ else
1441
1505
  [
1442
- ' ',
1443
- 'WITH',
1444
- "\n",
1445
- indent([
1446
- '(',
1447
- node.extension_items.map{|x| format(x)}.join(",\n#{item_indent}"),
1448
- ')'
1449
- ].join(''))
1506
+ *if node.items.length > 0
1507
+ item_indent = INDENT_CHAR * '('.length
1508
+ [
1509
+ "\n",
1510
+ indent([
1511
+ '(',
1512
+ node.items.map{|x| format(x)}.join(",\n#{item_indent}"),
1513
+ ')'
1514
+ ].join(''))
1515
+ ].join('')
1516
+ end
1450
1517
  ].join('')
1451
1518
  end
1452
1519
  ].join('')
1453
1520
  end
1454
1521
 
1455
- def format_types_set(node)
1522
+ def format_data_types_set(node)
1456
1523
  [
1457
1524
  'SET',
1458
1525
  *if node.bound1 and node.bound2
@@ -1472,7 +1539,7 @@ module Expressir
1472
1539
  ].join('')
1473
1540
  end
1474
1541
 
1475
- def format_types_string(node)
1542
+ def format_data_types_string(node)
1476
1543
  [
1477
1544
  'STRING',
1478
1545
  *if node.width
@@ -1502,7 +1569,7 @@ module Expressir
1502
1569
  [
1503
1570
  '(*',
1504
1571
  '"',
1505
- node.path,
1572
+ node.path || node.id,
1506
1573
  '"',
1507
1574
  ].join(''),
1508
1575
  remark,
@@ -1512,7 +1579,7 @@ module Expressir
1512
1579
  [
1513
1580
  '--',
1514
1581
  '"',
1515
- node.path,
1582
+ node.path || node.id,
1516
1583
  '"',
1517
1584
  ' ',
1518
1585
  remark
@@ -1533,7 +1600,7 @@ module Expressir
1533
1600
  def format_scope_remarks(node)
1534
1601
  [
1535
1602
  *format_remarks(node),
1536
- *node.children.select{|x| !x.is_a? Model::EnumerationItem or node.is_a? Model::Type}.flat_map{|x| format_scope_remarks(x)}
1603
+ *node.children.select{|x| !x.is_a? Model::DataTypes::EnumerationItem or node.is_a? Model::Declarations::Type}.flat_map{|x| format_scope_remarks(x)}
1537
1604
  ]
1538
1605
  end
1539
1606
  end