expressir 0.2.7-x86-mingw32 → 0.2.12-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/release.yml +3 -4
  3. data/.gitignore +1 -1
  4. data/exe/format +16 -0
  5. data/expressir.gemspec +3 -2
  6. data/lib/expressir/express_exp/2.4/express_parser.so +0 -0
  7. data/lib/expressir/express_exp/2.5/express_parser.so +0 -0
  8. data/lib/expressir/express_exp/2.6/express_parser.so +0 -0
  9. data/lib/expressir/express_exp/2.7/express_parser.so +0 -0
  10. data/lib/expressir/express_exp/3.0/express_parser.so +0 -0
  11. data/lib/expressir/express_exp/formatter.rb +147 -110
  12. data/lib/expressir/express_exp/hyperlink_formatter.rb +25 -0
  13. data/lib/expressir/express_exp/parser.rb +14 -1
  14. data/lib/expressir/express_exp/schema_head_formatter.rb +14 -0
  15. data/lib/expressir/express_exp/visitor.rb +206 -118
  16. data/lib/expressir/model.rb +3 -1
  17. data/lib/expressir/model/attribute.rb +5 -1
  18. data/lib/expressir/model/constant.rb +5 -1
  19. data/lib/expressir/model/entity.rb +14 -20
  20. data/lib/expressir/model/enumeration_item.rb +5 -1
  21. data/lib/expressir/model/expressions/aggregate_initializer.rb +4 -2
  22. data/lib/expressir/model/expressions/aggregate_item.rb +3 -1
  23. data/lib/expressir/model/expressions/attribute_reference.rb +3 -1
  24. data/lib/expressir/model/expressions/binary_expression.rb +3 -1
  25. data/lib/expressir/model/expressions/call.rb +4 -2
  26. data/lib/expressir/model/expressions/entity_constructor.rb +4 -2
  27. data/lib/expressir/model/expressions/group_reference.rb +3 -1
  28. data/lib/expressir/model/expressions/index_reference.rb +3 -1
  29. data/lib/expressir/model/expressions/interval.rb +3 -1
  30. data/lib/expressir/model/expressions/query_expression.rb +5 -2
  31. data/lib/expressir/model/expressions/simple_reference.rb +3 -1
  32. data/lib/expressir/model/expressions/unary_expression.rb +3 -1
  33. data/lib/expressir/model/function.rb +28 -39
  34. data/lib/expressir/model/identifier.rb +0 -1
  35. data/lib/expressir/model/informal_proposition.rb +15 -0
  36. data/lib/expressir/model/interface.rb +4 -2
  37. data/lib/expressir/model/literals/binary.rb +3 -1
  38. data/lib/expressir/model/literals/integer.rb +3 -1
  39. data/lib/expressir/model/literals/logical.rb +3 -1
  40. data/lib/expressir/model/literals/real.rb +3 -1
  41. data/lib/expressir/model/literals/string.rb +3 -1
  42. data/lib/expressir/model/model_element.rb +140 -0
  43. data/lib/expressir/model/parameter.rb +5 -1
  44. data/lib/expressir/model/procedure.rb +29 -40
  45. data/lib/expressir/model/renamed_ref.rb +3 -1
  46. data/lib/expressir/model/repository.rb +5 -5
  47. data/lib/expressir/model/rule.rb +33 -41
  48. data/lib/expressir/model/schema.rb +32 -46
  49. data/lib/expressir/model/statements/alias.rb +6 -3
  50. data/lib/expressir/model/statements/assignment.rb +3 -1
  51. data/lib/expressir/model/statements/call.rb +4 -2
  52. data/lib/expressir/model/statements/case.rb +4 -2
  53. data/lib/expressir/model/statements/case_action.rb +4 -2
  54. data/lib/expressir/model/statements/compound.rb +4 -2
  55. data/lib/expressir/model/statements/escape.rb +1 -1
  56. data/lib/expressir/model/statements/if.rb +5 -3
  57. data/lib/expressir/model/statements/null.rb +1 -1
  58. data/lib/expressir/model/statements/repeat.rb +6 -3
  59. data/lib/expressir/model/statements/return.rb +3 -1
  60. data/lib/expressir/model/statements/skip.rb +1 -1
  61. data/lib/expressir/model/subtype_constraint.rb +5 -2
  62. data/lib/expressir/model/type.rb +11 -4
  63. data/lib/expressir/model/types/aggregate.rb +5 -1
  64. data/lib/expressir/model/types/array.rb +3 -1
  65. data/lib/expressir/model/types/bag.rb +3 -1
  66. data/lib/expressir/model/types/binary.rb +3 -1
  67. data/lib/expressir/model/types/boolean.rb +1 -1
  68. data/lib/expressir/model/types/enumeration.rb +5 -3
  69. data/lib/expressir/model/types/generic.rb +5 -1
  70. data/lib/expressir/model/types/generic_entity.rb +5 -1
  71. data/lib/expressir/model/types/integer.rb +1 -1
  72. data/lib/expressir/model/types/list.rb +3 -1
  73. data/lib/expressir/model/types/logical.rb +1 -1
  74. data/lib/expressir/model/types/number.rb +1 -1
  75. data/lib/expressir/model/types/real.rb +3 -1
  76. data/lib/expressir/model/types/select.rb +5 -3
  77. data/lib/expressir/model/types/set.rb +3 -1
  78. data/lib/expressir/model/types/string.rb +3 -1
  79. data/lib/expressir/model/unique.rb +6 -2
  80. data/lib/expressir/model/variable.rb +5 -1
  81. data/lib/expressir/model/where.rb +5 -1
  82. data/lib/expressir/version.rb +1 -1
  83. data/original/examples/syntax/hyperlink.exp +8 -0
  84. data/original/examples/syntax/hyperlink_formatted.exp +19 -0
  85. data/original/examples/syntax/remark.exp +63 -20
  86. data/original/examples/syntax/remark_formatted.exp +62 -24
  87. data/original/examples/syntax/simple.exp +3 -0
  88. data/original/examples/syntax/source.exp +16 -0
  89. data/original/examples/syntax/syntax.exp +202 -190
  90. data/original/examples/syntax/syntax_formatted.exp +370 -799
  91. data/spec/expressir/express_exp/{format_remark_spec.rb → formatter/remark_spec.rb} +2 -2
  92. data/spec/expressir/express_exp/{format_syntax_spec.rb → formatter/syntax_spec.rb} +2 -2
  93. data/spec/expressir/express_exp/hyperlink_formatter_spec.rb +24 -0
  94. data/spec/expressir/express_exp/parser/head_source_spec.rb +38 -0
  95. data/spec/expressir/express_exp/parser/multiple_spec.rb +32 -0
  96. data/spec/expressir/express_exp/{parse_remark_spec.rb → parser/remark_spec.rb} +120 -55
  97. data/spec/expressir/express_exp/parser/source_spec.rb +29 -0
  98. data/spec/expressir/express_exp/parser/syntax_spec.rb +3080 -0
  99. data/spec/expressir/express_exp/schema_head_formatter_spec.rb +36 -0
  100. data/spec/expressir/model/{find_spec.rb → model_element/find_spec.rb} +26 -8
  101. data/spec/expressir/model/model_element/hash_spec.rb +66 -0
  102. metadata +38 -11
  103. data/lib/expressir/model/scope.rb +0 -17
  104. data/spec/expressir/express_exp/ap233_spec.rb +0 -22
  105. data/spec/expressir/express_exp/parse_syntax_spec.rb +0 -3003
@@ -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
@@ -9,7 +9,7 @@ require 'expressir/express_exp/visitor'
9
9
  module Expressir
10
10
  module ExpressExp
11
11
  class Parser
12
- def self.from_exp(file)
12
+ def self.from_file(file)
13
13
  input = File.read(file)
14
14
 
15
15
  =begin
@@ -36,6 +36,19 @@ module Expressir
36
36
 
37
37
  repo
38
38
  end
39
+
40
+ def self.from_files(files)
41
+ schemas = files.map{|file| self.from_file(file).schemas}.flatten
42
+
43
+ Model::Repository.new({
44
+ schemas: schemas
45
+ })
46
+ end
47
+
48
+ # deprecated
49
+ def self.from_exp(file)
50
+ self.from_file(file)
51
+ end
39
52
  end
40
53
  end
41
54
  end
@@ -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
@@ -5,10 +5,8 @@ rescue LoadError
5
5
  require_relative "express_parser"
6
6
  end
7
7
  require "expressir/model"
8
+ require "set"
8
9
 
9
- # static shorthands are unwrapped
10
- # - entity attributes, function/procedure parameters, local variables
11
- #
12
10
  # reference type is not recognized
13
11
  # see note in A.1.5 Interpreted identifiers
14
12
  # > It is expected that identifiers matching these syntax rules are known to an implementation.
@@ -16,7 +14,7 @@ require "expressir/model"
16
14
  # > method of gaining this information is multi-pass parsing: the first pass collects the identifiers from their
17
15
  # > declarations, so that subsequent passes are then able to distinguish a veriable_ref from a function_ref,
18
16
  # > for example.
19
- #
17
+ # - such multi-pass parsing is not implemented yet
20
18
  # - xxxRef - merged to SimpleReference
21
19
  # - entityConstructor, functionCall - merged to Call
22
20
  #
@@ -25,6 +23,13 @@ require "expressir/model"
25
23
  # > A syntactic construct such as ARRAY[1:3] OF REAL satisfies two syntactic productions —
26
24
  # > aggregation_type and general_aggregation_type. It is considered to be instantiable no matter which
27
25
  # > production it is required to satisfy in the syntax.
26
+ #
27
+ # static shorthands are unwrapped
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
28
33
 
29
34
  module Expressir
30
35
  module ExpressExp
@@ -33,99 +38,148 @@ module Expressir
33
38
 
34
39
  def initialize(tokens)
35
40
  @tokens = tokens
36
- @attached_remarks = Set.new
41
+ @attached_remark_tokens = ::Set.new
37
42
 
38
43
  super()
39
44
  end
40
45
 
41
46
  def visit(ctx)
42
- result = super(ctx)
43
- attach_source(ctx, result)
44
- attach_parent(ctx, result)
45
- attach_remarks(ctx, result)
46
- result
47
+ node = super(ctx)
48
+ attach_source(ctx, node)
49
+ attach_remarks(ctx, node)
50
+ node
47
51
  end
48
52
 
49
- def visit_if(ctx)
50
- visit(ctx) if ctx
53
+ def visit_if(ctx, default = nil)
54
+ if ctx
55
+ visit(ctx)
56
+ else
57
+ default
58
+ end
51
59
  end
52
60
 
53
61
  def visit_if_map(ctx)
54
- ctx.map{|ctx2| visit(ctx2)} if ctx
62
+ if ctx
63
+ ctx.map{|ctx2| visit(ctx2)}
64
+ else
65
+ []
66
+ end
55
67
  end
56
68
 
57
69
  def visit_if_map_flatten(ctx)
58
- ctx.map{|ctx2| visit(ctx2)}.flatten if ctx
59
- end
60
-
61
- def attach_source(ctx, node)
62
- if node.class.method_defined? :source
63
- start_index, stop_index = [ctx.start.token_index, ctx.stop.token_index]
64
- node.source = @tokens[start_index..stop_index].map{|x| x.text}.join('').force_encoding('UTF-8')
70
+ if ctx
71
+ ctx.map{|ctx2| visit(ctx2)}.flatten
72
+ else
73
+ []
65
74
  end
66
75
  end
67
76
 
68
- def attach_parent(ctx, node)
69
- if node.class.method_defined? :children
70
- node.children.each do |child_node|
71
- if child_node.class.method_defined? :parent
72
- child_node.parent = node
73
- end
74
- end
77
+ def get_tokens_source(tokens)
78
+ if tokens.last.text == '<EOF>'
79
+ tokens.pop
75
80
  end
81
+
82
+ tokens.map{|x| x.text}.join('').force_encoding('UTF-8')
76
83
  end
77
84
 
78
- def attach_remarks(ctx, node)
79
- # get remark tokens
80
- start_index, stop_index = if ctx.instance_of? ::ExpressParser::SyntaxContext
85
+ def get_tokens(ctx)
86
+ start_index, stop_index = if ctx.is_a? ::ExpressParser::SyntaxContext
81
87
  [0, @tokens.size - 1]
82
88
  else
83
89
  [ctx.start.token_index, ctx.stop.token_index]
84
90
  end
85
- # puts [start_index, stop_index, ctx.class].inspect
86
-
87
- remark_tokens = @tokens[start_index..stop_index].select{|x| x.channel == REMARK_CHANNEL}
88
- if remark_tokens
89
- remark_tokens.each do |remark_token|
90
- remark_text = remark_token.text
91
-
92
- # check if it is tagged remark
93
- match = if remark_text.start_with?('--')
94
- remark_text[2..-1].match(/^"([^"]*)"(.*)$/)
95
- elsif remark_text.start_with?('(*') and remark_text.end_with?('*)')
96
- remark_text[2..-3].match(/^"([^"]*)"(.*)$/m)
97
- end
98
- if !match
99
- next
100
- end
101
91
 
102
- # don't attach already attached tagged remark
103
- if @attached_remarks.include? remark_token
104
- next
105
- end
92
+ @tokens[start_index..stop_index]
93
+ end
106
94
 
107
- # attach tagged remark
108
- remark_tag = match[1]
109
- remark_content = match[2].strip.force_encoding('UTF-8')
95
+ def get_head_tokens(ctx)
96
+ start_index, stop_index = if ctx.is_a? ::ExpressParser::SchemaDeclContext
97
+ start_index = ctx.start.token_index
98
+ stop_index = if ctx.schema_body.interface_specification.length > 0
99
+ ctx.schema_body.interface_specification.last.stop.token_index
100
+ elsif ctx.schema_version_id
101
+ ctx.schema_version_id.stop.token_index + 1
102
+ else
103
+ ctx.schema_id.stop.token_index + 1
104
+ end
110
105
 
111
- target_node = nil
112
- current_node = node
113
- if current_node.class.method_defined? :find
114
- target_node = current_node.find(remark_tag)
115
- end
116
- while !target_node and current_node.class.method_defined? :parent and current_node.parent.class.method_defined? :find
117
- current_node = current_node.parent
118
- target_node = current_node.find(remark_tag)
119
- end
106
+ [start_index, stop_index]
107
+ end
120
108
 
121
- if target_node
122
- target_node.remarks ||= []
123
- target_node.remarks << remark_content
109
+ if start_index and stop_index
110
+ @tokens[start_index..stop_index]
111
+ end
112
+ end
124
113
 
125
- # mark remark as attached, so that it is not attached again at higher nesting level
126
- @attached_remarks << remark_token
127
- end
114
+ def attach_source(ctx, node)
115
+ if node.class.method_defined? :source
116
+ tokens = get_tokens(ctx)
117
+ node.source = get_tokens_source(tokens)
118
+ end
119
+
120
+ if node.class.method_defined? :head_source
121
+ tokens = get_head_tokens(ctx)
122
+ node.head_source = get_tokens_source(tokens)
123
+ end
124
+ end
125
+
126
+ def find_remark_target(node, path)
127
+ target_node = node.find(path)
128
+ return target_node if target_node
129
+
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
134
+
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
150
+ end
151
+
152
+ def attach_remarks(ctx, node)
153
+ remark_tokens = get_tokens(ctx).select{|x| x.channel == REMARK_CHANNEL}
154
+
155
+ # skip already attached remarks
156
+ remark_tokens = remark_tokens.select{|x| !@attached_remark_tokens.include?(x)}
157
+
158
+ # parse remarks, find remark targets
159
+ tagged_remark_tokens = remark_tokens.map do |remark_token|
160
+ _, remark_tag, remark_text = if remark_token.text.start_with?('--')
161
+ remark_token.text.match(/^--"([^"]*)"(.*)$/).to_a
162
+ else
163
+ remark_token.text.match(/^\(\*"([^"]*)"(.*)\*\)$/m).to_a
164
+ end
165
+
166
+ if remark_tag
167
+ remark_target = find_remark_target(node, remark_tag)
168
+ end
169
+ if remark_text
170
+ remark_text = remark_text.strip.force_encoding('UTF-8')
128
171
  end
172
+
173
+ [remark_token, remark_target, remark_text]
174
+ end.select{|x| x[1]}
175
+
176
+ tagged_remark_tokens.each do |remark_token, remark_target, remark_text|
177
+ # attach remark
178
+ remark_target.remarks ||= []
179
+ remark_target.remarks << remark_text
180
+
181
+ # mark remark as attached, so that it is not attached again at higher nesting level
182
+ @attached_remark_tokens << remark_token
129
183
  end
130
184
  end
131
185
 
@@ -378,8 +432,8 @@ module Expressir
378
432
 
379
433
  bound1 = visit_if(ctx__bound_spec__bound1)
380
434
  bound2 = visit_if(ctx__bound_spec__bound2)
381
- optional = !!ctx__OPTIONAL
382
- unique = !!ctx__UNIQUE
435
+ optional = ctx__OPTIONAL && true
436
+ unique = ctx__UNIQUE && true
383
437
  base_type = visit_if(ctx__instantiable_type)
384
438
 
385
439
  Model::Types::Array.new({
@@ -463,7 +517,7 @@ module Expressir
463
517
  ctx__width_spec__FIXED = ctx__width_spec&.FIXED
464
518
 
465
519
  width = visit_if(ctx__width_spec__width)
466
- fixed = !!ctx__width_spec__FIXED
520
+ fixed = ctx__width_spec__FIXED && true
467
521
 
468
522
  Model::Types::Binary.new({
469
523
  width: width,
@@ -715,16 +769,16 @@ module Expressir
715
769
  ctx__entity_body__where_clause = ctx__entity_body&.where_clause
716
770
 
717
771
  id = visit_if(ctx__entity_head__entity_id)
718
- 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
719
773
  supertype_expression = visit_if(ctx__entity_head__subsuper__supertype_constraint__abstract_supertype_declaration || ctx__entity_head__subsuper__supertype_constraint__supertype_rule)
720
- subtype_of = visit_if(ctx__entity_head__subsuper__subtype_declaration)
774
+ subtype_of = visit_if(ctx__entity_head__subsuper__subtype_declaration, [])
721
775
  attributes = [
722
776
  *visit_if_map_flatten(ctx__entity_body__explicit_attr),
723
777
  *visit_if(ctx__entity_body__derive_clause),
724
778
  *visit_if(ctx__entity_body__inverse_clause)
725
779
  ]
726
- unique = visit_if(ctx__entity_body__unique_clause)
727
- 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, [])
728
782
 
729
783
  Model::Entity.new({
730
784
  id: id,
@@ -797,10 +851,10 @@ module Expressir
797
851
  ctx__enumeration_extension__type_ref = ctx__enumeration_extension&.type_ref
798
852
  ctx__enumeration_extension__enumeration_items = ctx__enumeration_extension&.enumeration_items
799
853
 
800
- extensible = !!ctx__EXTENSIBLE
801
- items = visit_if(ctx__enumeration_items)
854
+ extensible = ctx__EXTENSIBLE && true
855
+ items = visit_if(ctx__enumeration_items, [])
802
856
  extension_type = visit_if(ctx__enumeration_extension__type_ref)
803
- extension_items = visit_if(ctx__enumeration_extension__enumeration_items)
857
+ extension_items = visit_if(ctx__enumeration_extension__enumeration_items, [])
804
858
 
805
859
  Model::Types::Enumeration.new({
806
860
  extensible: extensible,
@@ -820,7 +874,7 @@ module Expressir
820
874
  ctx__parameter_type = ctx.parameter_type
821
875
 
822
876
  attributes = visit_if_map(ctx__attribute_decl)
823
- optional = !!ctx__OPTIONAL
877
+ optional = ctx__OPTIONAL && true
824
878
  type = visit_if(ctx__parameter_type)
825
879
 
826
880
  attributes.map do |attribute|
@@ -894,7 +948,7 @@ module Expressir
894
948
  ctx__actual_parameter_list = ctx.actual_parameter_list
895
949
 
896
950
  ref = visit_if(ctx__built_in_function || ctx__function_ref)
897
- parameters = visit_if(ctx__actual_parameter_list)
951
+ parameters = visit_if(ctx__actual_parameter_list, [])
898
952
 
899
953
  Model::Expressions::Call.new({
900
954
  ref: ref,
@@ -917,15 +971,24 @@ module Expressir
917
971
  parameters = visit_if_map_flatten(ctx__function_head__formal_parameter)
918
972
  return_type = visit_if(ctx__function_head__parameter_type)
919
973
  declarations = visit_if_map(ctx__algorithm_head__declaration)
920
- constants = visit_if(ctx__algorithm_head__constant_decl)
921
- 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, [])
922
981
  statements = visit_if_map(ctx__stmt)
923
982
 
924
983
  Model::Function.new({
925
984
  id: id,
926
985
  parameters: parameters,
927
986
  return_type: return_type,
928
- declarations: declarations,
987
+ types: types,
988
+ entities: entities,
989
+ subtype_constraints: subtype_constraints,
990
+ functions: functions,
991
+ procedures: procedures,
929
992
  constants: constants,
930
993
  variables: variables,
931
994
  statements: statements
@@ -970,8 +1033,8 @@ module Expressir
970
1033
 
971
1034
  bound1 = visit_if(ctx__bound_spec__bound1)
972
1035
  bound2 = visit_if(ctx__bound_spec__bound2)
973
- optional = !!ctx__OPTIONAL
974
- unique = !!ctx__UNIQUE
1036
+ optional = ctx__OPTIONAL && true
1037
+ unique = ctx__UNIQUE && true
975
1038
  base_type = visit_if(ctx__parameter_type)
976
1039
 
977
1040
  Model::Types::Array.new({
@@ -1009,7 +1072,7 @@ module Expressir
1009
1072
 
1010
1073
  bound1 = visit_if(ctx__bound_spec__bound1)
1011
1074
  bound2 = visit_if(ctx__bound_spec__bound2)
1012
- unique = !!ctx__UNIQUE
1075
+ unique = ctx__UNIQUE && true
1013
1076
  base_type = visit_if(ctx__parameter_type)
1014
1077
 
1015
1078
  Model::Types::List.new({
@@ -1084,8 +1147,8 @@ module Expressir
1084
1147
  ctx__if_stmt_else_statements = ctx.if_stmt_else_statements
1085
1148
 
1086
1149
  expression = visit_if(ctx__logical_expression)
1087
- statements = visit_if(ctx__if_stmt_statements)
1088
- 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, [])
1089
1152
 
1090
1153
  Model::Statements::If.new({
1091
1154
  expression: expression,
@@ -1299,7 +1362,7 @@ module Expressir
1299
1362
 
1300
1363
  bound1 = visit_if(ctx__bound_spec__bound1)
1301
1364
  bound2 = visit_if(ctx__bound_spec__bound2)
1302
- unique = !!ctx__UNIQUE
1365
+ unique = ctx__UNIQUE && true
1303
1366
  base_type = visit_if(ctx__instantiable_type)
1304
1367
 
1305
1368
  Model::Types::List.new({
@@ -1515,7 +1578,7 @@ module Expressir
1515
1578
  ctx__actual_parameter_list = ctx.actual_parameter_list
1516
1579
 
1517
1580
  ref = visit_if(ctx__built_in_procedure || ctx__procedure_ref)
1518
- parameters = visit_if(ctx__actual_parameter_list)
1581
+ parameters = visit_if(ctx__actual_parameter_list, [])
1519
1582
 
1520
1583
  Model::Statements::Call.new({
1521
1584
  ref: ref,
@@ -1536,14 +1599,23 @@ module Expressir
1536
1599
  id = visit_if(ctx__procedure_head__procedure_id)
1537
1600
  parameters = visit_if_map_flatten(ctx__procedure_head__procedure_head_parameter)
1538
1601
  declarations = visit_if_map(ctx__algorithm_head__declaration)
1539
- constants = visit_if(ctx__algorithm_head__constant_decl)
1540
- 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, [])
1541
1609
  statements = visit_if_map(ctx__stmt)
1542
1610
 
1543
1611
  Model::Procedure.new({
1544
1612
  id: id,
1545
1613
  parameters: parameters,
1546
- declarations: declarations,
1614
+ types: types,
1615
+ entities: entities,
1616
+ subtype_constraints: subtype_constraints,
1617
+ functions: functions,
1618
+ procedures: procedures,
1547
1619
  constants: constants,
1548
1620
  variables: variables,
1549
1621
  statements: statements
@@ -1769,20 +1841,16 @@ module Expressir
1769
1841
  ctx__resource_ref = ctx.resource_ref
1770
1842
  ctx__rename_id = ctx.rename_id
1771
1843
 
1772
- if ctx__resource_ref
1773
- if ctx__rename_id
1774
- ref = visit(ctx__resource_ref)
1775
- id = visit(ctx__rename_id)
1844
+ ref = visit_if(ctx__resource_ref)
1845
+ id = visit_if(ctx__rename_id)
1776
1846
 
1777
- Model::RenamedRef.new({
1778
- ref: ref,
1779
- id: id
1780
- })
1781
- else
1782
- visit(ctx__resource_ref)
1783
- end
1847
+ if id
1848
+ Model::RenamedRef.new({
1849
+ ref: ref,
1850
+ id: id
1851
+ })
1784
1852
  else
1785
- raise 'Invalid state'
1853
+ ref
1786
1854
  end
1787
1855
  end
1788
1856
 
@@ -1820,15 +1888,24 @@ module Expressir
1820
1888
  id = visit_if(ctx__rule_head__rule_id)
1821
1889
  applies_to = visit_if_map(ctx__rule_head__entity_ref)
1822
1890
  declarations = visit_if_map(ctx__algorithm_head__declaration)
1823
- constants = visit_if(ctx__algorithm_head__constant_decl)
1824
- 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, [])
1825
1898
  statements = visit_if_map(ctx__stmt)
1826
- where = visit_if(ctx__where_clause)
1899
+ where = visit_if(ctx__where_clause, [])
1827
1900
 
1828
1901
  Model::Rule.new({
1829
1902
  id: id,
1830
1903
  applies_to: applies_to,
1831
- declarations: declarations,
1904
+ types: types,
1905
+ entities: entities,
1906
+ subtype_constraints: subtype_constraints,
1907
+ functions: functions,
1908
+ procedures: procedures,
1832
1909
  constants: constants,
1833
1910
  variables: variables,
1834
1911
  statements: statements,
@@ -1874,15 +1951,26 @@ module Expressir
1874
1951
  id = visit_if(ctx__schema_id)
1875
1952
  version = visit_if(ctx__schema_version_id)
1876
1953
  interfaces = visit_if_map(ctx__schema_body__interface_specification)
1877
- constants = visit_if(ctx__schema_body__constant_decl)
1954
+ constants = visit_if(ctx__schema_body__constant_decl, [])
1878
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}
1879
1962
 
1880
1963
  Model::Schema.new({
1881
1964
  id: id,
1882
1965
  version: version,
1883
1966
  interfaces: interfaces,
1884
1967
  constants: constants,
1885
- declarations: declarations
1968
+ types: types,
1969
+ entities: entities,
1970
+ subtype_constraints: subtype_constraints,
1971
+ functions: functions,
1972
+ procedures: procedures,
1973
+ rules: rules
1886
1974
  })
1887
1975
  end
1888
1976
 
@@ -1922,11 +2010,11 @@ module Expressir
1922
2010
  ctx__select_extension__type_ref = ctx.select_extension&.type_ref
1923
2011
  ctx__select_extension__select_list = ctx__select_extension&.select_list
1924
2012
 
1925
- extensible = !!ctx__EXTENSIBLE
1926
- generic_entity = !!ctx__GENERIC_ENTITY
1927
- 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, [])
1928
2016
  extension_type = visit_if(ctx__select_extension__type_ref)
1929
- extension_items = visit_if(ctx__select_extension__select_list)
2017
+ extension_items = visit_if(ctx__select_extension__select_list, [])
1930
2018
 
1931
2019
  Model::Types::Select.new({
1932
2020
  extensible: extensible,
@@ -2059,7 +2147,7 @@ module Expressir
2059
2147
  ctx__width_spec__FIXED = ctx__width_spec&.FIXED
2060
2148
 
2061
2149
  width = visit_if(ctx__width_spec__width)
2062
- fixed = !!ctx__width_spec__FIXED
2150
+ fixed = ctx__width_spec__FIXED && true
2063
2151
 
2064
2152
  Model::Types::String.new({
2065
2153
  width: width,
@@ -2092,7 +2180,7 @@ module Expressir
2092
2180
 
2093
2181
  id = visit_if(ctx__subtype_constraint_head__subtype_constraint_id)
2094
2182
  applies_to = visit_if(ctx__subtype_constraint_head__entity_ref)
2095
- abstract = !!ctx__subtype_constraint_body__abstract_supertype
2183
+ abstract = ctx__subtype_constraint_body__abstract_supertype && true
2096
2184
  total_over = visit_if(ctx__subtype_constraint_body__total_over)
2097
2185
  supertype_expression = visit_if(ctx__subtype_constraint_body__supertype_expression)
2098
2186
 
@@ -2228,7 +2316,7 @@ module Expressir
2228
2316
 
2229
2317
  id = visit_if(ctx__type_id)
2230
2318
  type = visit_if(ctx__underlying_type)
2231
- where = visit_if(ctx__where_clause)
2319
+ where = visit_if(ctx__where_clause, [])
2232
2320
 
2233
2321
  Model::Type.new({
2234
2322
  id: id,