expressir 0.2.9 → 0.2.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/exe/format +20 -0
  3. data/expressir.gemspec +1 -0
  4. data/lib/expressir/express_exp/formatter.rb +146 -105
  5. data/lib/expressir/express_exp/hyperlink_formatter.rb +25 -0
  6. data/lib/expressir/express_exp/parser.rb +2 -0
  7. data/lib/expressir/express_exp/schema_head_formatter.rb +14 -0
  8. data/lib/expressir/express_exp/visitor.rb +132 -82
  9. data/lib/expressir/model.rb +2 -1
  10. data/lib/expressir/model/attribute.rb +5 -1
  11. data/lib/expressir/model/constant.rb +5 -1
  12. data/lib/expressir/model/entity.rb +13 -22
  13. data/lib/expressir/model/enumeration_item.rb +5 -1
  14. data/lib/expressir/model/expressions/aggregate_initializer.rb +4 -2
  15. data/lib/expressir/model/expressions/aggregate_item.rb +3 -1
  16. data/lib/expressir/model/expressions/attribute_reference.rb +3 -1
  17. data/lib/expressir/model/expressions/binary_expression.rb +3 -1
  18. data/lib/expressir/model/expressions/call.rb +4 -2
  19. data/lib/expressir/model/expressions/entity_constructor.rb +4 -2
  20. data/lib/expressir/model/expressions/group_reference.rb +3 -1
  21. data/lib/expressir/model/expressions/index_reference.rb +3 -1
  22. data/lib/expressir/model/expressions/interval.rb +3 -1
  23. data/lib/expressir/model/expressions/query_expression.rb +5 -2
  24. data/lib/expressir/model/expressions/simple_reference.rb +3 -1
  25. data/lib/expressir/model/expressions/unary_expression.rb +3 -1
  26. data/lib/expressir/model/function.rb +28 -39
  27. data/lib/expressir/model/identifier.rb +1 -3
  28. data/lib/expressir/model/informal_proposition.rb +5 -1
  29. data/lib/expressir/model/interface.rb +4 -2
  30. data/lib/expressir/model/literals/binary.rb +3 -1
  31. data/lib/expressir/model/literals/integer.rb +3 -1
  32. data/lib/expressir/model/literals/logical.rb +3 -1
  33. data/lib/expressir/model/literals/real.rb +3 -1
  34. data/lib/expressir/model/literals/string.rb +3 -1
  35. data/lib/expressir/model/model_element.rb +140 -0
  36. data/lib/expressir/model/parameter.rb +5 -1
  37. data/lib/expressir/model/procedure.rb +29 -40
  38. data/lib/expressir/model/renamed_ref.rb +3 -1
  39. data/lib/expressir/model/repository.rb +5 -5
  40. data/lib/expressir/model/rule.rb +32 -43
  41. data/lib/expressir/model/schema.rb +48 -48
  42. data/lib/expressir/model/statements/alias.rb +6 -3
  43. data/lib/expressir/model/statements/assignment.rb +3 -1
  44. data/lib/expressir/model/statements/call.rb +4 -2
  45. data/lib/expressir/model/statements/case.rb +4 -2
  46. data/lib/expressir/model/statements/case_action.rb +4 -2
  47. data/lib/expressir/model/statements/compound.rb +4 -2
  48. data/lib/expressir/model/statements/escape.rb +1 -1
  49. data/lib/expressir/model/statements/if.rb +5 -3
  50. data/lib/expressir/model/statements/null.rb +1 -1
  51. data/lib/expressir/model/statements/repeat.rb +6 -3
  52. data/lib/expressir/model/statements/return.rb +3 -1
  53. data/lib/expressir/model/statements/skip.rb +1 -1
  54. data/lib/expressir/model/subtype_constraint.rb +5 -2
  55. data/lib/expressir/model/type.rb +10 -11
  56. data/lib/expressir/model/types/aggregate.rb +5 -1
  57. data/lib/expressir/model/types/array.rb +3 -1
  58. data/lib/expressir/model/types/bag.rb +3 -1
  59. data/lib/expressir/model/types/binary.rb +3 -1
  60. data/lib/expressir/model/types/boolean.rb +1 -1
  61. data/lib/expressir/model/types/enumeration.rb +5 -3
  62. data/lib/expressir/model/types/generic.rb +5 -1
  63. data/lib/expressir/model/types/generic_entity.rb +5 -1
  64. data/lib/expressir/model/types/integer.rb +1 -1
  65. data/lib/expressir/model/types/list.rb +3 -1
  66. data/lib/expressir/model/types/logical.rb +1 -1
  67. data/lib/expressir/model/types/number.rb +1 -1
  68. data/lib/expressir/model/types/real.rb +3 -1
  69. data/lib/expressir/model/types/select.rb +5 -3
  70. data/lib/expressir/model/types/set.rb +3 -1
  71. data/lib/expressir/model/types/string.rb +3 -1
  72. data/lib/expressir/model/unique.rb +6 -2
  73. data/lib/expressir/model/variable.rb +5 -1
  74. data/lib/expressir/model/where.rb +5 -1
  75. data/lib/expressir/version.rb +1 -1
  76. data/original/examples/syntax/hyperlink.exp +8 -0
  77. data/original/examples/syntax/hyperlink_formatted.exp +19 -0
  78. data/original/examples/syntax/remark_formatted.exp +0 -5
  79. data/original/examples/syntax/simple.exp +3 -0
  80. data/original/examples/syntax/syntax.exp +197 -189
  81. data/original/examples/syntax/syntax_formatted.exp +362 -800
  82. data/spec/expressir/express_exp/{format_remark_spec.rb → formatter/remark_spec.rb} +2 -2
  83. data/spec/expressir/express_exp/{format_syntax_spec.rb → formatter/syntax_spec.rb} +2 -2
  84. data/spec/expressir/express_exp/hyperlink_formatter_spec.rb +24 -0
  85. data/spec/expressir/express_exp/{head_source_spec.rb → parser/head_source_spec.rb} +2 -5
  86. data/spec/expressir/express_exp/{parse_multiple_spec.rb → parser/multiple_spec.rb} +6 -1
  87. data/spec/expressir/express_exp/{parse_remark_spec.rb → parser/remark_spec.rb} +5 -5
  88. data/spec/expressir/express_exp/{source_spec.rb → parser/source_spec.rb} +2 -5
  89. data/spec/expressir/express_exp/{parse_syntax_spec.rb → parser/syntax_spec.rb} +1619 -1582
  90. data/spec/expressir/express_exp/schema_head_formatter_spec.rb +36 -0
  91. data/spec/expressir/model/{find_spec.rb → model_element/find_spec.rb} +7 -2
  92. data/spec/expressir/model/model_element/hash_spec.rb +66 -0
  93. metadata +34 -12
  94. data/lib/expressir/model/scope.rb +0 -66
  95. data/spec/expressir/express_exp/ap233_spec.rb +0 -22
@@ -0,0 +1,25 @@
1
+ require "expressir/express_exp/formatter"
2
+
3
+ module Expressir
4
+ module ExpressExp
5
+ class HyperlinkFormatter < Formatter
6
+ def format_expressions_simple_reference(node)
7
+ return node.id if node.parent.is_a? Model::Expressions::AttributeReference
8
+
9
+ # skip hyperlink if target node can't be found
10
+ target_node = node.find(node.id)
11
+ return node.id unless target_node
12
+
13
+ # skip hyperlink for implicit scopes
14
+ return node.id if target_node.is_a? Model::Statements::Alias or target_node.is_a? Model::Statements::Repeat or target_node.is_a? Model::Expressions::QueryExpression
15
+
16
+ # skip hyperlink if this node and target node are in the same main item
17
+ node_path_parts = node.path.split(".")
18
+ target_node_path_parts = target_node.path.split(".")
19
+ return node.id if node_path_parts[0..1] == target_node_path_parts[0..1]
20
+
21
+ "{{{<<express:#{target_node.path},#{node.id}>>}}}"
22
+ end
23
+ end
24
+ end
25
+ end
@@ -34,6 +34,8 @@ module Expressir
34
34
  visitor = Visitor.new(parser.tokens)
35
35
  repo = visitor.visit(parse_tree)
36
36
 
37
+ repo.schemas.each{|schema| schema.file = file}
38
+
37
39
  repo
38
40
  end
39
41
 
@@ -0,0 +1,14 @@
1
+ require "expressir/express_exp/formatter"
2
+
3
+ module Expressir
4
+ module ExpressExp
5
+ class SchemaHeadFormatter < Formatter
6
+ def format_schema(node)
7
+ [
8
+ "SCHEMA #{node.id}#{node.version ? " #{format(node.version)}" : ""};",
9
+ *node.interfaces.map{|x| format(x)}
10
+ ].join("\n")
11
+ end
12
+ end
13
+ end
14
+ end
@@ -14,7 +14,7 @@ require "set"
14
14
  # > method of gaining this information is multi-pass parsing: the first pass collects the identifiers from their
15
15
  # > declarations, so that subsequent passes are then able to distinguish a veriable_ref from a function_ref,
16
16
  # > for example.
17
- #
17
+ # - such multi-pass parsing is not implemented yet
18
18
  # - xxxRef - merged to SimpleReference
19
19
  # - entityConstructor, functionCall - merged to Call
20
20
  #
@@ -26,6 +26,10 @@ require "set"
26
26
  #
27
27
  # static shorthands are unwrapped
28
28
  # - entity attributes, function/procedure parameters, local variables
29
+ #
30
+ # all access to ctx members must happen before calling other visitor code
31
+ # - prevents segfault in ANTLR4 C++ runtime, not sure why they are caused
32
+ # - e.g. see visit_schema_decl
29
33
 
30
34
  module Expressir
31
35
  module ExpressExp
@@ -40,23 +44,34 @@ module Expressir
40
44
  end
41
45
 
42
46
  def visit(ctx)
43
- result = super(ctx)
44
- attach_source(ctx, result)
45
- attach_parent(ctx, result)
46
- attach_remarks(ctx, result)
47
- result
47
+ node = super(ctx)
48
+ attach_source(ctx, node)
49
+ attach_remarks(ctx, node)
50
+ node
48
51
  end
49
52
 
50
- def visit_if(ctx)
51
- visit(ctx) if ctx
53
+ def visit_if(ctx, default = nil)
54
+ if ctx
55
+ visit(ctx)
56
+ else
57
+ default
58
+ end
52
59
  end
53
60
 
54
61
  def visit_if_map(ctx)
55
- ctx.map{|ctx2| visit(ctx2)} if ctx
62
+ if ctx
63
+ ctx.map{|ctx2| visit(ctx2)}
64
+ else
65
+ []
66
+ end
56
67
  end
57
68
 
58
69
  def visit_if_map_flatten(ctx)
59
- ctx.map{|ctx2| visit(ctx2)}.flatten if ctx
70
+ if ctx
71
+ ctx.map{|ctx2| visit(ctx2)}.flatten
72
+ else
73
+ []
74
+ end
60
75
  end
61
76
 
62
77
  def get_tokens_source(tokens)
@@ -68,7 +83,7 @@ module Expressir
68
83
  end
69
84
 
70
85
  def get_tokens(ctx)
71
- start_index, stop_index = if ctx.instance_of? ::ExpressParser::SyntaxContext
86
+ start_index, stop_index = if ctx.is_a? ::ExpressParser::SyntaxContext
72
87
  [0, @tokens.size - 1]
73
88
  else
74
89
  [ctx.start.token_index, ctx.stop.token_index]
@@ -78,7 +93,7 @@ module Expressir
78
93
  end
79
94
 
80
95
  def get_head_tokens(ctx)
81
- start_index, stop_index = if ctx.instance_of? ::ExpressParser::SchemaDeclContext
96
+ start_index, stop_index = if ctx.is_a? ::ExpressParser::SchemaDeclContext
82
97
  start_index = ctx.start.token_index
83
98
  stop_index = if ctx.schema_body.interface_specification.length > 0
84
99
  ctx.schema_body.interface_specification.last.stop.token_index
@@ -108,29 +123,30 @@ module Expressir
108
123
  end
109
124
  end
110
125
 
111
- def attach_parent(ctx, node)
112
- if node.class.method_defined? :children
113
- node.children.each do |child_node|
114
- if child_node.class.method_defined? :parent and !child_node.parent
115
- child_node.parent = node
116
- end
117
- end
118
- end
119
- end
120
-
121
126
  def find_remark_target(node, path)
122
- current_node = node
123
- target_node = nil
127
+ target_node = node.find(path)
128
+ return target_node if target_node
124
129
 
125
- if current_node.class.method_defined? :find_or_create
126
- target_node = current_node.find_or_create(path)
127
- end
128
- while !target_node and current_node.class.method_defined? :parent and current_node.parent.class.method_defined? :find_or_create
129
- current_node = current_node.parent
130
- target_node = current_node.find_or_create(path)
131
- end
130
+ # check if path should create implicit informal proposal
131
+ # see https://github.com/lutaml/expressir/issues/50
132
+ rest, _, current_path = path.rpartition(".") # get last path part
133
+ _, _, current_path = current_path.rpartition(":") # ignore prefix
132
134
 
133
- target_node
135
+ # match informal proposition id
136
+ informal_proposition_id = current_path.match(/^IP\d+$/).to_a[0]
137
+ return unless informal_proposition_id
138
+
139
+ # find informal proposition target
140
+ target_node = node.find(rest)
141
+ return unless target_node and target_node.class.method_defined? :informal_propositions
142
+
143
+ # create implicit informal proposition
144
+ informal_proposition = Model::InformalProposition.new({
145
+ id: informal_proposition_id
146
+ })
147
+ target_node.informal_propositions << informal_proposition
148
+ informal_proposition.parent = target_node
149
+ informal_proposition
134
150
  end
135
151
 
136
152
  def attach_remarks(ctx, node)
@@ -416,8 +432,8 @@ module Expressir
416
432
 
417
433
  bound1 = visit_if(ctx__bound_spec__bound1)
418
434
  bound2 = visit_if(ctx__bound_spec__bound2)
419
- optional = !!ctx__OPTIONAL
420
- unique = !!ctx__UNIQUE
435
+ optional = ctx__OPTIONAL && true
436
+ unique = ctx__UNIQUE && true
421
437
  base_type = visit_if(ctx__instantiable_type)
422
438
 
423
439
  Model::Types::Array.new({
@@ -501,7 +517,7 @@ module Expressir
501
517
  ctx__width_spec__FIXED = ctx__width_spec&.FIXED
502
518
 
503
519
  width = visit_if(ctx__width_spec__width)
504
- fixed = !!ctx__width_spec__FIXED
520
+ fixed = ctx__width_spec__FIXED && true
505
521
 
506
522
  Model::Types::Binary.new({
507
523
  width: width,
@@ -753,16 +769,16 @@ module Expressir
753
769
  ctx__entity_body__where_clause = ctx__entity_body&.where_clause
754
770
 
755
771
  id = visit_if(ctx__entity_head__entity_id)
756
- abstract = !!(ctx__entity_head__subsuper__supertype_constraint__abstract_entity_declaration || ctx__entity_head__subsuper__supertype_constraint__abstract_supertype_declaration)
772
+ abstract = (ctx__entity_head__subsuper__supertype_constraint__abstract_entity_declaration || ctx__entity_head__subsuper__supertype_constraint__abstract_supertype_declaration) && true
757
773
  supertype_expression = visit_if(ctx__entity_head__subsuper__supertype_constraint__abstract_supertype_declaration || ctx__entity_head__subsuper__supertype_constraint__supertype_rule)
758
- subtype_of = visit_if(ctx__entity_head__subsuper__subtype_declaration)
774
+ subtype_of = visit_if(ctx__entity_head__subsuper__subtype_declaration, [])
759
775
  attributes = [
760
776
  *visit_if_map_flatten(ctx__entity_body__explicit_attr),
761
777
  *visit_if(ctx__entity_body__derive_clause),
762
778
  *visit_if(ctx__entity_body__inverse_clause)
763
779
  ]
764
- unique = visit_if(ctx__entity_body__unique_clause)
765
- where = visit_if(ctx__entity_body__where_clause)
780
+ unique = visit_if(ctx__entity_body__unique_clause, [])
781
+ where = visit_if(ctx__entity_body__where_clause, [])
766
782
 
767
783
  Model::Entity.new({
768
784
  id: id,
@@ -835,10 +851,10 @@ module Expressir
835
851
  ctx__enumeration_extension__type_ref = ctx__enumeration_extension&.type_ref
836
852
  ctx__enumeration_extension__enumeration_items = ctx__enumeration_extension&.enumeration_items
837
853
 
838
- extensible = !!ctx__EXTENSIBLE
839
- items = visit_if(ctx__enumeration_items)
854
+ extensible = ctx__EXTENSIBLE && true
855
+ items = visit_if(ctx__enumeration_items, [])
840
856
  extension_type = visit_if(ctx__enumeration_extension__type_ref)
841
- extension_items = visit_if(ctx__enumeration_extension__enumeration_items)
857
+ extension_items = visit_if(ctx__enumeration_extension__enumeration_items, [])
842
858
 
843
859
  Model::Types::Enumeration.new({
844
860
  extensible: extensible,
@@ -858,7 +874,7 @@ module Expressir
858
874
  ctx__parameter_type = ctx.parameter_type
859
875
 
860
876
  attributes = visit_if_map(ctx__attribute_decl)
861
- optional = !!ctx__OPTIONAL
877
+ optional = ctx__OPTIONAL && true
862
878
  type = visit_if(ctx__parameter_type)
863
879
 
864
880
  attributes.map do |attribute|
@@ -932,7 +948,7 @@ module Expressir
932
948
  ctx__actual_parameter_list = ctx.actual_parameter_list
933
949
 
934
950
  ref = visit_if(ctx__built_in_function || ctx__function_ref)
935
- parameters = visit_if(ctx__actual_parameter_list)
951
+ parameters = visit_if(ctx__actual_parameter_list, [])
936
952
 
937
953
  Model::Expressions::Call.new({
938
954
  ref: ref,
@@ -955,15 +971,24 @@ module Expressir
955
971
  parameters = visit_if_map_flatten(ctx__function_head__formal_parameter)
956
972
  return_type = visit_if(ctx__function_head__parameter_type)
957
973
  declarations = visit_if_map(ctx__algorithm_head__declaration)
958
- constants = visit_if(ctx__algorithm_head__constant_decl)
959
- variables = visit_if(ctx__algorithm_head__local_decl)
974
+ types = declarations.select{|x| x.is_a? Model::Type}
975
+ entities = declarations.select{|x| x.is_a? Model::Entity}
976
+ subtype_constraints = declarations.select{|x| x.is_a? Model::SubtypeConstraint}
977
+ functions = declarations.select{|x| x.is_a? Model::Function}
978
+ procedures = declarations.select{|x| x.is_a? Model::Procedure}
979
+ constants = visit_if(ctx__algorithm_head__constant_decl, [])
980
+ variables = visit_if(ctx__algorithm_head__local_decl, [])
960
981
  statements = visit_if_map(ctx__stmt)
961
982
 
962
983
  Model::Function.new({
963
984
  id: id,
964
985
  parameters: parameters,
965
986
  return_type: return_type,
966
- declarations: declarations,
987
+ types: types,
988
+ entities: entities,
989
+ subtype_constraints: subtype_constraints,
990
+ functions: functions,
991
+ procedures: procedures,
967
992
  constants: constants,
968
993
  variables: variables,
969
994
  statements: statements
@@ -1008,8 +1033,8 @@ module Expressir
1008
1033
 
1009
1034
  bound1 = visit_if(ctx__bound_spec__bound1)
1010
1035
  bound2 = visit_if(ctx__bound_spec__bound2)
1011
- optional = !!ctx__OPTIONAL
1012
- unique = !!ctx__UNIQUE
1036
+ optional = ctx__OPTIONAL && true
1037
+ unique = ctx__UNIQUE && true
1013
1038
  base_type = visit_if(ctx__parameter_type)
1014
1039
 
1015
1040
  Model::Types::Array.new({
@@ -1047,7 +1072,7 @@ module Expressir
1047
1072
 
1048
1073
  bound1 = visit_if(ctx__bound_spec__bound1)
1049
1074
  bound2 = visit_if(ctx__bound_spec__bound2)
1050
- unique = !!ctx__UNIQUE
1075
+ unique = ctx__UNIQUE && true
1051
1076
  base_type = visit_if(ctx__parameter_type)
1052
1077
 
1053
1078
  Model::Types::List.new({
@@ -1122,8 +1147,8 @@ module Expressir
1122
1147
  ctx__if_stmt_else_statements = ctx.if_stmt_else_statements
1123
1148
 
1124
1149
  expression = visit_if(ctx__logical_expression)
1125
- statements = visit_if(ctx__if_stmt_statements)
1126
- else_statements = visit_if(ctx__if_stmt_else_statements)
1150
+ statements = visit_if(ctx__if_stmt_statements, [])
1151
+ else_statements = visit_if(ctx__if_stmt_else_statements, [])
1127
1152
 
1128
1153
  Model::Statements::If.new({
1129
1154
  expression: expression,
@@ -1337,7 +1362,7 @@ module Expressir
1337
1362
 
1338
1363
  bound1 = visit_if(ctx__bound_spec__bound1)
1339
1364
  bound2 = visit_if(ctx__bound_spec__bound2)
1340
- unique = !!ctx__UNIQUE
1365
+ unique = ctx__UNIQUE && true
1341
1366
  base_type = visit_if(ctx__instantiable_type)
1342
1367
 
1343
1368
  Model::Types::List.new({
@@ -1553,7 +1578,7 @@ module Expressir
1553
1578
  ctx__actual_parameter_list = ctx.actual_parameter_list
1554
1579
 
1555
1580
  ref = visit_if(ctx__built_in_procedure || ctx__procedure_ref)
1556
- parameters = visit_if(ctx__actual_parameter_list)
1581
+ parameters = visit_if(ctx__actual_parameter_list, [])
1557
1582
 
1558
1583
  Model::Statements::Call.new({
1559
1584
  ref: ref,
@@ -1574,14 +1599,23 @@ module Expressir
1574
1599
  id = visit_if(ctx__procedure_head__procedure_id)
1575
1600
  parameters = visit_if_map_flatten(ctx__procedure_head__procedure_head_parameter)
1576
1601
  declarations = visit_if_map(ctx__algorithm_head__declaration)
1577
- constants = visit_if(ctx__algorithm_head__constant_decl)
1578
- variables = visit_if(ctx__algorithm_head__local_decl)
1602
+ types = declarations.select{|x| x.is_a? Model::Type}
1603
+ entities = declarations.select{|x| x.is_a? Model::Entity}
1604
+ subtype_constraints = declarations.select{|x| x.is_a? Model::SubtypeConstraint}
1605
+ functions = declarations.select{|x| x.is_a? Model::Function}
1606
+ procedures = declarations.select{|x| x.is_a? Model::Procedure}
1607
+ constants = visit_if(ctx__algorithm_head__constant_decl, [])
1608
+ variables = visit_if(ctx__algorithm_head__local_decl, [])
1579
1609
  statements = visit_if_map(ctx__stmt)
1580
1610
 
1581
1611
  Model::Procedure.new({
1582
1612
  id: id,
1583
1613
  parameters: parameters,
1584
- declarations: declarations,
1614
+ types: types,
1615
+ entities: entities,
1616
+ subtype_constraints: subtype_constraints,
1617
+ functions: functions,
1618
+ procedures: procedures,
1585
1619
  constants: constants,
1586
1620
  variables: variables,
1587
1621
  statements: statements
@@ -1807,20 +1841,16 @@ module Expressir
1807
1841
  ctx__resource_ref = ctx.resource_ref
1808
1842
  ctx__rename_id = ctx.rename_id
1809
1843
 
1810
- if ctx__resource_ref
1811
- if ctx__rename_id
1812
- ref = visit(ctx__resource_ref)
1813
- id = visit(ctx__rename_id)
1844
+ ref = visit_if(ctx__resource_ref)
1845
+ id = visit_if(ctx__rename_id)
1814
1846
 
1815
- Model::RenamedRef.new({
1816
- ref: ref,
1817
- id: id
1818
- })
1819
- else
1820
- visit(ctx__resource_ref)
1821
- end
1847
+ if id
1848
+ Model::RenamedRef.new({
1849
+ ref: ref,
1850
+ id: id
1851
+ })
1822
1852
  else
1823
- raise 'Invalid state'
1853
+ ref
1824
1854
  end
1825
1855
  end
1826
1856
 
@@ -1858,15 +1888,24 @@ module Expressir
1858
1888
  id = visit_if(ctx__rule_head__rule_id)
1859
1889
  applies_to = visit_if_map(ctx__rule_head__entity_ref)
1860
1890
  declarations = visit_if_map(ctx__algorithm_head__declaration)
1861
- constants = visit_if(ctx__algorithm_head__constant_decl)
1862
- variables = visit_if(ctx__algorithm_head__local_decl)
1891
+ types = declarations.select{|x| x.is_a? Model::Type}
1892
+ entities = declarations.select{|x| x.is_a? Model::Entity}
1893
+ subtype_constraints = declarations.select{|x| x.is_a? Model::SubtypeConstraint}
1894
+ functions = declarations.select{|x| x.is_a? Model::Function}
1895
+ procedures = declarations.select{|x| x.is_a? Model::Procedure}
1896
+ constants = visit_if(ctx__algorithm_head__constant_decl, [])
1897
+ variables = visit_if(ctx__algorithm_head__local_decl, [])
1863
1898
  statements = visit_if_map(ctx__stmt)
1864
- where = visit_if(ctx__where_clause)
1899
+ where = visit_if(ctx__where_clause, [])
1865
1900
 
1866
1901
  Model::Rule.new({
1867
1902
  id: id,
1868
1903
  applies_to: applies_to,
1869
- declarations: declarations,
1904
+ types: types,
1905
+ entities: entities,
1906
+ subtype_constraints: subtype_constraints,
1907
+ functions: functions,
1908
+ procedures: procedures,
1870
1909
  constants: constants,
1871
1910
  variables: variables,
1872
1911
  statements: statements,
@@ -1912,15 +1951,26 @@ module Expressir
1912
1951
  id = visit_if(ctx__schema_id)
1913
1952
  version = visit_if(ctx__schema_version_id)
1914
1953
  interfaces = visit_if_map(ctx__schema_body__interface_specification)
1915
- constants = visit_if(ctx__schema_body__constant_decl)
1954
+ constants = visit_if(ctx__schema_body__constant_decl, [])
1916
1955
  declarations = visit_if_map(ctx__schema_body__schema_body_declaration)
1956
+ types = declarations.select{|x| x.is_a? Model::Type}
1957
+ entities = declarations.select{|x| x.is_a? Model::Entity}
1958
+ subtype_constraints = declarations.select{|x| x.is_a? Model::SubtypeConstraint}
1959
+ functions = declarations.select{|x| x.is_a? Model::Function}
1960
+ procedures = declarations.select{|x| x.is_a? Model::Procedure}
1961
+ rules = declarations.select{|x| x.is_a? Model::Rule}
1917
1962
 
1918
1963
  Model::Schema.new({
1919
1964
  id: id,
1920
1965
  version: version,
1921
1966
  interfaces: interfaces,
1922
1967
  constants: constants,
1923
- declarations: declarations
1968
+ types: types,
1969
+ entities: entities,
1970
+ subtype_constraints: subtype_constraints,
1971
+ functions: functions,
1972
+ procedures: procedures,
1973
+ rules: rules
1924
1974
  })
1925
1975
  end
1926
1976
 
@@ -1960,11 +2010,11 @@ module Expressir
1960
2010
  ctx__select_extension__type_ref = ctx.select_extension&.type_ref
1961
2011
  ctx__select_extension__select_list = ctx__select_extension&.select_list
1962
2012
 
1963
- extensible = !!ctx__EXTENSIBLE
1964
- generic_entity = !!ctx__GENERIC_ENTITY
1965
- items = visit_if(ctx__select_list)
2013
+ extensible = ctx__EXTENSIBLE && true
2014
+ generic_entity = ctx__GENERIC_ENTITY && true
2015
+ items = visit_if(ctx__select_list, [])
1966
2016
  extension_type = visit_if(ctx__select_extension__type_ref)
1967
- extension_items = visit_if(ctx__select_extension__select_list)
2017
+ extension_items = visit_if(ctx__select_extension__select_list, [])
1968
2018
 
1969
2019
  Model::Types::Select.new({
1970
2020
  extensible: extensible,
@@ -2097,7 +2147,7 @@ module Expressir
2097
2147
  ctx__width_spec__FIXED = ctx__width_spec&.FIXED
2098
2148
 
2099
2149
  width = visit_if(ctx__width_spec__width)
2100
- fixed = !!ctx__width_spec__FIXED
2150
+ fixed = ctx__width_spec__FIXED && true
2101
2151
 
2102
2152
  Model::Types::String.new({
2103
2153
  width: width,
@@ -2130,7 +2180,7 @@ module Expressir
2130
2180
 
2131
2181
  id = visit_if(ctx__subtype_constraint_head__subtype_constraint_id)
2132
2182
  applies_to = visit_if(ctx__subtype_constraint_head__entity_ref)
2133
- abstract = !!ctx__subtype_constraint_body__abstract_supertype
2183
+ abstract = ctx__subtype_constraint_body__abstract_supertype && true
2134
2184
  total_over = visit_if(ctx__subtype_constraint_body__total_over)
2135
2185
  supertype_expression = visit_if(ctx__subtype_constraint_body__supertype_expression)
2136
2186
 
@@ -2266,7 +2316,7 @@ module Expressir
2266
2316
 
2267
2317
  id = visit_if(ctx__type_id)
2268
2318
  type = visit_if(ctx__underlying_type)
2269
- where = visit_if(ctx__where_clause)
2319
+ where = visit_if(ctx__where_clause, [])
2270
2320
 
2271
2321
  Model::Type.new({
2272
2322
  id: id,