expressir 0.2.10-arm64-darwin → 0.2.15-arm64-darwin

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/exe/format +27 -0
  3. data/expressir.gemspec +1 -0
  4. data/lib/expressir/express_exp/2.4/express_parser.bundle +0 -0
  5. data/lib/expressir/express_exp/2.5/express_parser.bundle +0 -0
  6. data/lib/expressir/express_exp/2.6/express_parser.bundle +0 -0
  7. data/lib/expressir/express_exp/2.7/express_parser.bundle +0 -0
  8. data/lib/expressir/express_exp/3.0/express_parser.bundle +0 -0
  9. data/lib/expressir/express_exp/formatter.rb +90 -100
  10. data/lib/expressir/express_exp/hyperlink_formatter.rb +29 -0
  11. data/lib/expressir/express_exp/parser.rb +7 -1
  12. data/lib/expressir/express_exp/schema_head_formatter.rb +14 -0
  13. data/lib/expressir/express_exp/visitor.rb +68 -80
  14. data/lib/expressir/model.rb +2 -2
  15. data/lib/expressir/model/attribute.rb +2 -0
  16. data/lib/expressir/model/constant.rb +2 -0
  17. data/lib/expressir/model/entity.rb +3 -2
  18. data/lib/expressir/model/enumeration_item.rb +2 -0
  19. data/lib/expressir/model/expressions/aggregate_initializer.rb +2 -0
  20. data/lib/expressir/model/expressions/aggregate_item.rb +2 -0
  21. data/lib/expressir/model/expressions/attribute_reference.rb +2 -0
  22. data/lib/expressir/model/expressions/binary_expression.rb +2 -0
  23. data/lib/expressir/model/expressions/call.rb +2 -0
  24. data/lib/expressir/model/expressions/entity_constructor.rb +2 -0
  25. data/lib/expressir/model/expressions/group_reference.rb +2 -0
  26. data/lib/expressir/model/expressions/index_reference.rb +2 -0
  27. data/lib/expressir/model/expressions/interval.rb +2 -0
  28. data/lib/expressir/model/expressions/query_expression.rb +2 -1
  29. data/lib/expressir/model/expressions/simple_reference.rb +2 -0
  30. data/lib/expressir/model/expressions/unary_expression.rb +2 -0
  31. data/lib/expressir/model/function.rb +3 -8
  32. data/lib/expressir/model/identifier.rb +0 -1
  33. data/lib/expressir/model/informal_proposition.rb +2 -0
  34. data/lib/expressir/model/interface.rb +2 -0
  35. data/lib/expressir/model/{renamed_ref.rb → interface_item.rb} +4 -2
  36. data/lib/expressir/model/interfaced_item.rb +23 -0
  37. data/lib/expressir/model/literals/binary.rb +2 -0
  38. data/lib/expressir/model/literals/integer.rb +2 -0
  39. data/lib/expressir/model/literals/logical.rb +2 -0
  40. data/lib/expressir/model/literals/real.rb +2 -0
  41. data/lib/expressir/model/literals/string.rb +2 -0
  42. data/lib/expressir/model/model_element.rb +85 -12
  43. data/lib/expressir/model/parameter.rb +2 -0
  44. data/lib/expressir/model/procedure.rb +3 -8
  45. data/lib/expressir/model/repository.rb +2 -2
  46. data/lib/expressir/model/rule.rb +4 -9
  47. data/lib/expressir/model/schema.rb +45 -9
  48. data/lib/expressir/model/statements/alias.rb +2 -1
  49. data/lib/expressir/model/statements/assignment.rb +2 -0
  50. data/lib/expressir/model/statements/call.rb +2 -0
  51. data/lib/expressir/model/statements/case.rb +2 -0
  52. data/lib/expressir/model/statements/case_action.rb +2 -0
  53. data/lib/expressir/model/statements/compound.rb +2 -0
  54. data/lib/expressir/model/statements/if.rb +2 -0
  55. data/lib/expressir/model/statements/repeat.rb +2 -1
  56. data/lib/expressir/model/statements/return.rb +2 -0
  57. data/lib/expressir/model/subtype_constraint.rb +2 -1
  58. data/lib/expressir/model/type.rb +3 -6
  59. data/lib/expressir/model/types/aggregate.rb +2 -0
  60. data/lib/expressir/model/types/array.rb +2 -0
  61. data/lib/expressir/model/types/bag.rb +2 -0
  62. data/lib/expressir/model/types/binary.rb +2 -0
  63. data/lib/expressir/model/types/enumeration.rb +2 -0
  64. data/lib/expressir/model/types/generic.rb +2 -0
  65. data/lib/expressir/model/types/generic_entity.rb +2 -0
  66. data/lib/expressir/model/types/list.rb +2 -0
  67. data/lib/expressir/model/types/real.rb +2 -0
  68. data/lib/expressir/model/types/select.rb +2 -0
  69. data/lib/expressir/model/types/set.rb +2 -0
  70. data/lib/expressir/model/types/string.rb +2 -0
  71. data/lib/expressir/model/unique.rb +2 -0
  72. data/lib/expressir/model/variable.rb +2 -0
  73. data/lib/expressir/model/where.rb +2 -0
  74. data/lib/expressir/version.rb +1 -1
  75. data/original/examples/syntax/hyperlink.exp +23 -0
  76. data/original/examples/syntax/hyperlink_formatted.exp +51 -0
  77. data/original/examples/syntax/syntax.exp +18 -18
  78. data/original/examples/syntax/syntax_formatted.exp +32 -24
  79. data/spec/expressir/express_exp/{format_remark_spec.rb → formatter/remark_spec.rb} +2 -2
  80. data/spec/expressir/express_exp/{format_syntax_spec.rb → formatter/syntax_spec.rb} +2 -2
  81. data/spec/expressir/express_exp/hyperlink_formatter_spec.rb +24 -0
  82. data/spec/expressir/express_exp/{head_source_spec.rb → parser/head_source_spec.rb} +1 -1
  83. data/spec/expressir/express_exp/{parse_multiple_spec.rb → parser/multiple_spec.rb} +6 -1
  84. data/spec/expressir/express_exp/{parse_remark_spec.rb → parser/remark_spec.rb} +2 -2
  85. data/spec/expressir/express_exp/{source_spec.rb → parser/source_spec.rb} +1 -1
  86. data/spec/expressir/express_exp/{parse_syntax_spec.rb → parser/syntax_spec.rb} +98 -60
  87. data/spec/expressir/express_exp/schema_head_formatter_spec.rb +36 -0
  88. data/spec/expressir/model/{scope_spec.rb → model_element/find_spec.rb} +7 -2
  89. data/spec/expressir/model/model_element/hash_spec.rb +66 -0
  90. metadata +34 -14
  91. data/lib/expressir/model/scope.rb +0 -63
  92. data/spec/expressir/express_exp/ap233_spec.rb +0 -22
  93. data/spec/expressir/model/model_element_spec.rb +0 -59
@@ -6,6 +6,8 @@ module Expressir
6
6
 
7
7
  def initialize(options = {})
8
8
  @id = options[:id]
9
+
10
+ super
9
11
  end
10
12
  end
11
13
  end
@@ -12,6 +12,8 @@ module Expressir
12
12
  def initialize(options = {})
13
13
  @operator = options[:operator]
14
14
  @operand = options[:operand]
15
+
16
+ super
15
17
  end
16
18
  end
17
19
  end
@@ -1,7 +1,6 @@
1
1
  module Expressir
2
2
  module Model
3
3
  class Function < ModelElement
4
- include Scope
5
4
  include Identifier
6
5
 
7
6
  attr_accessor :parameters
@@ -30,19 +29,15 @@ module Expressir
30
29
  @constants = options.fetch(:constants, [])
31
30
  @variables = options.fetch(:variables, [])
32
31
  @statements = options.fetch(:statements, [])
32
+
33
+ super
33
34
  end
34
35
 
35
36
  def children
36
37
  items = []
37
38
  items.push(*@parameters)
38
39
  items.push(*@types)
39
- items.push(*@types.flat_map do |x|
40
- if x.type.instance_of? Expressir::Model::Types::Enumeration
41
- x.type.items
42
- else
43
- []
44
- end
45
- end)
40
+ items.push(*@types.flat_map{|x| x.type.is_a?(Types::Enumeration) ? x.type.items : []})
46
41
  items.push(*@entities)
47
42
  items.push(*@subtype_constraints)
48
43
  items.push(*@functions)
@@ -2,7 +2,6 @@ module Expressir
2
2
  module Model
3
3
  module Identifier
4
4
  attr_accessor :id
5
- attr_accessor :parent
6
5
  attr_accessor :remarks
7
6
  attr_accessor :source
8
7
  end
@@ -7,6 +7,8 @@ module Expressir
7
7
  @id = options[:id]
8
8
  @remarks = options.fetch(:remarks, [])
9
9
  @source = options[:source]
10
+
11
+ super
10
12
  end
11
13
  end
12
14
  end
@@ -12,6 +12,8 @@ module Expressir
12
12
  @kind = options[:kind]
13
13
  @schema = options[:schema]
14
14
  @items = options.fetch(:items, [])
15
+
16
+ super
15
17
  end
16
18
  end
17
19
  end
@@ -1,12 +1,14 @@
1
1
  module Expressir
2
2
  module Model
3
- class RenamedRef < ModelElement
3
+ class InterfaceItem < ModelElement
4
4
  attr_accessor :ref
5
5
  attr_accessor :id
6
6
 
7
7
  def initialize(options = {})
8
- @ref = options[:ref]
8
+ @ref = options[:ref]
9
9
  @id = options[:id]
10
+
11
+ super
10
12
  end
11
13
  end
12
14
  end
@@ -0,0 +1,23 @@
1
+ module Expressir
2
+ module Model
3
+ class InterfacedItem < ModelElement
4
+ include Identifier
5
+
6
+ attr_accessor :base_item
7
+
8
+ def initialize(options = {})
9
+ @id = options[:id]
10
+ @remarks = options.fetch(:remarks, [])
11
+ @source = options[:source]
12
+
13
+ @base_item = options[:base_item]
14
+
15
+ super
16
+ end
17
+
18
+ def path
19
+ base_item.path
20
+ end
21
+ end
22
+ end
23
+ end
@@ -6,6 +6,8 @@ module Expressir
6
6
 
7
7
  def initialize(options = {})
8
8
  @value = options[:value]
9
+
10
+ super
9
11
  end
10
12
  end
11
13
  end
@@ -6,6 +6,8 @@ module Expressir
6
6
 
7
7
  def initialize(options = {})
8
8
  @value = options[:value]
9
+
10
+ super
9
11
  end
10
12
  end
11
13
  end
@@ -10,6 +10,8 @@ module Expressir
10
10
 
11
11
  def initialize(options = {})
12
12
  @value = options[:value]
13
+
14
+ super
13
15
  end
14
16
  end
15
17
  end
@@ -6,6 +6,8 @@ module Expressir
6
6
 
7
7
  def initialize(options = {})
8
8
  @value = options[:value]
9
+
10
+ super
9
11
  end
10
12
  end
11
13
  end
@@ -8,6 +8,8 @@ module Expressir
8
8
  def initialize(options = {})
9
9
  @value = options[:value]
10
10
  @encoded = options[:encoded]
11
+
12
+ super
11
13
  end
12
14
  end
13
15
  end
@@ -1,16 +1,92 @@
1
1
  module Expressir
2
2
  module Model
3
3
  class ModelElement
4
- CLASS_KEY = '_class'
4
+ CLASS_KEY = '_class'
5
+ SOURCE_KEY = 'source'
6
+
7
+ attr_accessor :parent
8
+
9
+ def initialize(options = {})
10
+ attach_parent_to_children
11
+ end
12
+
13
+ def path
14
+ return id if is_a? Statements::Alias or is_a? Statements::Repeat or is_a? Expressions::QueryExpression
15
+
16
+ current_node = self
17
+ path_parts = []
18
+ loop do
19
+ if current_node.class.method_defined? :id
20
+ path_parts << current_node.id
21
+ end
22
+
23
+ current_node = current_node.parent
24
+ break unless current_node
25
+ end
26
+
27
+ path_parts.reverse.join(".")
28
+ end
29
+
30
+ def attach_parent_to_children
31
+ instance_variables.select{|x| x != :@parent}.each do |variable|
32
+ value = instance_variable_get(variable)
33
+
34
+ if value.is_a? Array
35
+ value.each do |value|
36
+ if value.is_a? ModelElement
37
+ value.parent = self
38
+ end
39
+ end
40
+ elsif value.is_a? ModelElement
41
+ value.parent = self
42
+ end
43
+ end
44
+ end
45
+
46
+ def find(path)
47
+ return self if path.empty?
48
+
49
+ path_parts = path.downcase.split(/\./).map do |current_path|
50
+ _, _, current_path = current_path.rpartition(":") # ignore prefix
51
+ current_path
52
+ end
53
+
54
+ current_scope = self
55
+ target_node = nil
56
+ loop do
57
+ # find in current scope
58
+ current_node = current_scope
59
+ path_parts.each do |current_path|
60
+ current_node = current_node.children.find{|x| x.id and x.id.downcase == current_path}
61
+ break unless current_node
62
+ end
63
+ target_node = current_node
64
+ break if target_node
65
+
66
+ # retry search in parent scope
67
+ current_scope = current_scope.parent
68
+ break unless current_scope
69
+ end
70
+
71
+ target_node
72
+ end
73
+
74
+ def children
75
+ []
76
+ end
5
77
 
6
78
  def to_hash(options = {})
7
79
  skip_empty = options[:skip_empty]
80
+ formatter = options[:formatter]
81
+
82
+ hash = {}
83
+ hash[CLASS_KEY] = self.class.name
8
84
 
9
- instance_variables.select{|x| x != :@parent}.each_with_object({ CLASS_KEY => self.class.name }) do |variable, result|
85
+ instance_variables.select{|x| x != :@parent}.each_with_object(hash) do |variable, result|
10
86
  key = variable.to_s.sub(/^@/, '')
11
87
  value = instance_variable_get(variable)
12
88
 
13
- # skip default values (nil, empty array)
89
+ # skip empty values (nil, empty array)
14
90
  if !skip_empty or !(value.nil? or (value.is_a? Array and value.count == 0))
15
91
  result[key] = if value.is_a? Array
16
92
  value.map do |value|
@@ -27,6 +103,12 @@ module Expressir
27
103
  end
28
104
  end
29
105
  end
106
+
107
+ if formatter
108
+ hash[SOURCE_KEY] = formatter.format(self)
109
+ end
110
+
111
+ hash
30
112
  end
31
113
 
32
114
  def self.from_hash(hash)
@@ -51,15 +133,6 @@ module Expressir
51
133
 
52
134
  node = Object.const_get(node_class).new(node_options)
53
135
 
54
- # attach parent
55
- if node.class.method_defined? :children
56
- node.children.each do |child_node|
57
- if child_node.class.method_defined? :parent and !child_node.parent
58
- child_node.parent = node
59
- end
60
- end
61
- end
62
-
63
136
  node
64
137
  end
65
138
  end
@@ -13,6 +13,8 @@ module Expressir
13
13
 
14
14
  @var = options[:var]
15
15
  @type = options[:type]
16
+
17
+ super
16
18
  end
17
19
  end
18
20
  end
@@ -1,7 +1,6 @@
1
1
  module Expressir
2
2
  module Model
3
3
  class Procedure < ModelElement
4
- include Scope
5
4
  include Identifier
6
5
 
7
6
  attr_accessor :parameters
@@ -28,19 +27,15 @@ module Expressir
28
27
  @constants = options.fetch(:constants, [])
29
28
  @variables = options.fetch(:variables, [])
30
29
  @statements = options.fetch(:statements, [])
30
+
31
+ super
31
32
  end
32
33
 
33
34
  def children
34
35
  items = []
35
36
  items.push(*@parameters)
36
37
  items.push(*@types)
37
- items.push(*@types.flat_map do |x|
38
- if x.type.instance_of? Expressir::Model::Types::Enumeration
39
- x.type.items
40
- else
41
- []
42
- end
43
- end)
38
+ items.push(*@types.flat_map{|x| x.type.is_a?(Types::Enumeration) ? x.type.items : []})
44
39
  items.push(*@entities)
45
40
  items.push(*@subtype_constraints)
46
41
  items.push(*@functions)
@@ -1,12 +1,12 @@
1
1
  module Expressir
2
2
  module Model
3
3
  class Repository < ModelElement
4
- include Scope
5
-
6
4
  attr_accessor :schemas
7
5
 
8
6
  def initialize(options = {})
9
7
  @schemas = options.fetch(:schemas, [])
8
+
9
+ super
10
10
  end
11
11
 
12
12
  def children
@@ -1,7 +1,6 @@
1
1
  module Expressir
2
2
  module Model
3
3
  class Rule < ModelElement
4
- include Scope
5
4
  include Identifier
6
5
 
7
6
  attr_accessor :applies_to
@@ -21,7 +20,7 @@ module Expressir
21
20
  @remarks = options.fetch(:remarks, [])
22
21
  @source = options[:source]
23
22
 
24
- @applies_to = options[:applies_to]
23
+ @applies_to = options.fetch(:applies_to, [])
25
24
  @types = options.fetch(:types, [])
26
25
  @entities = options.fetch(:entities, [])
27
26
  @subtype_constraints = options.fetch(:subtype_constraints, [])
@@ -32,18 +31,14 @@ module Expressir
32
31
  @statements = options.fetch(:statements, [])
33
32
  @where = options.fetch(:where, [])
34
33
  @informal_propositions = options.fetch(:informal_propositions, [])
34
+
35
+ super
35
36
  end
36
37
 
37
38
  def children
38
39
  items = []
39
40
  items.push(*@types)
40
- items.push(*@types.flat_map do |x|
41
- if x.type.instance_of? Expressir::Model::Types::Enumeration
42
- x.type.items
43
- else
44
- []
45
- end
46
- end)
41
+ items.push(*@types.flat_map{|x| x.type.is_a?(Types::Enumeration) ? x.type.items : []})
47
42
  items.push(*@entities)
48
43
  items.push(*@subtype_constraints)
49
44
  items.push(*@functions)
@@ -1,7 +1,8 @@
1
1
  module Expressir
2
2
  module Model
3
3
  class Schema < ModelElement
4
- include Scope
4
+ attr_accessor :file
5
+
5
6
  include Identifier
6
7
 
7
8
  attr_accessor :head_source
@@ -17,6 +18,8 @@ module Expressir
17
18
  attr_accessor :rules
18
19
 
19
20
  def initialize(options = {})
21
+ @file = options[:file]
22
+
20
23
  @id = options[:id]
21
24
  @remarks = options.fetch(:remarks, [])
22
25
  @source = options[:source]
@@ -31,19 +34,52 @@ module Expressir
31
34
  @functions = options.fetch(:functions, [])
32
35
  @procedures = options.fetch(:procedures, [])
33
36
  @rules = options.fetch(:rules, [])
37
+
38
+ super
34
39
  end
35
40
 
36
- def children
41
+ def children(skip_references = false)
37
42
  items = []
43
+ unless skip_references
44
+ items.push(*@interfaces.flat_map do |interface|
45
+ schema_id = interface.schema.id.downcase
46
+ schema = parent.schemas.find{|x| x.id.downcase == schema_id}
47
+ if schema
48
+ schema_children = schema.children(true) # prevent infinite recursion
49
+ if interface.items.length > 0
50
+ interface.items.map do |item|
51
+ ref_id = item.ref.id.downcase
52
+ id = item.id || ref_id
53
+ base_item = schema_children.find{|x| x.id and x.id.downcase == ref_id}
54
+
55
+ interfaced_item = InterfacedItem.new({
56
+ id: id
57
+ })
58
+ interfaced_item.base_item = base_item # skip overriding parent
59
+ interfaced_item.parent = self
60
+ interfaced_item
61
+ end
62
+ else
63
+ schema_children.map do |item|
64
+ id = item.id
65
+ base_item = item
66
+
67
+ interfaced_item = InterfacedItem.new({
68
+ id: id
69
+ })
70
+ interfaced_item.base_item = base_item # skip overriding parent
71
+ interfaced_item.parent = self
72
+ interfaced_item
73
+ end
74
+ end
75
+ else
76
+ []
77
+ end
78
+ end)
79
+ end
38
80
  items.push(*@constants)
39
81
  items.push(*@types)
40
- items.push(*@types.flat_map do |x|
41
- if x.type.instance_of? Expressir::Model::Types::Enumeration
42
- x.type.items
43
- else
44
- []
45
- end
46
- end)
82
+ items.push(*@types.flat_map{|x| x.type.is_a?(Types::Enumeration) ? x.type.items : []})
47
83
  items.push(*@entities)
48
84
  items.push(*@subtype_constraints)
49
85
  items.push(*@functions)