expressir 0.2.9-arm64-darwin → 0.2.14-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 (100) 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/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 +146 -105
  10. data/lib/expressir/express_exp/hyperlink_formatter.rb +25 -0
  11. data/lib/expressir/express_exp/parser.rb +2 -0
  12. data/lib/expressir/express_exp/schema_head_formatter.rb +14 -0
  13. data/lib/expressir/express_exp/visitor.rb +132 -82
  14. data/lib/expressir/model.rb +2 -1
  15. data/lib/expressir/model/attribute.rb +5 -1
  16. data/lib/expressir/model/constant.rb +5 -1
  17. data/lib/expressir/model/entity.rb +13 -22
  18. data/lib/expressir/model/enumeration_item.rb +5 -1
  19. data/lib/expressir/model/expressions/aggregate_initializer.rb +4 -2
  20. data/lib/expressir/model/expressions/aggregate_item.rb +3 -1
  21. data/lib/expressir/model/expressions/attribute_reference.rb +3 -1
  22. data/lib/expressir/model/expressions/binary_expression.rb +3 -1
  23. data/lib/expressir/model/expressions/call.rb +4 -2
  24. data/lib/expressir/model/expressions/entity_constructor.rb +4 -2
  25. data/lib/expressir/model/expressions/group_reference.rb +3 -1
  26. data/lib/expressir/model/expressions/index_reference.rb +3 -1
  27. data/lib/expressir/model/expressions/interval.rb +3 -1
  28. data/lib/expressir/model/expressions/query_expression.rb +5 -2
  29. data/lib/expressir/model/expressions/simple_reference.rb +3 -1
  30. data/lib/expressir/model/expressions/unary_expression.rb +3 -1
  31. data/lib/expressir/model/function.rb +28 -39
  32. data/lib/expressir/model/identifier.rb +1 -3
  33. data/lib/expressir/model/informal_proposition.rb +5 -1
  34. data/lib/expressir/model/interface.rb +4 -2
  35. data/lib/expressir/model/literals/binary.rb +3 -1
  36. data/lib/expressir/model/literals/integer.rb +3 -1
  37. data/lib/expressir/model/literals/logical.rb +3 -1
  38. data/lib/expressir/model/literals/real.rb +3 -1
  39. data/lib/expressir/model/literals/string.rb +3 -1
  40. data/lib/expressir/model/model_element.rb +140 -0
  41. data/lib/expressir/model/parameter.rb +5 -1
  42. data/lib/expressir/model/procedure.rb +29 -40
  43. data/lib/expressir/model/renamed_ref.rb +3 -1
  44. data/lib/expressir/model/repository.rb +5 -5
  45. data/lib/expressir/model/rule.rb +32 -43
  46. data/lib/expressir/model/schema.rb +48 -48
  47. data/lib/expressir/model/statements/alias.rb +6 -3
  48. data/lib/expressir/model/statements/assignment.rb +3 -1
  49. data/lib/expressir/model/statements/call.rb +4 -2
  50. data/lib/expressir/model/statements/case.rb +4 -2
  51. data/lib/expressir/model/statements/case_action.rb +4 -2
  52. data/lib/expressir/model/statements/compound.rb +4 -2
  53. data/lib/expressir/model/statements/escape.rb +1 -1
  54. data/lib/expressir/model/statements/if.rb +5 -3
  55. data/lib/expressir/model/statements/null.rb +1 -1
  56. data/lib/expressir/model/statements/repeat.rb +6 -3
  57. data/lib/expressir/model/statements/return.rb +3 -1
  58. data/lib/expressir/model/statements/skip.rb +1 -1
  59. data/lib/expressir/model/subtype_constraint.rb +5 -2
  60. data/lib/expressir/model/type.rb +10 -11
  61. data/lib/expressir/model/types/aggregate.rb +5 -1
  62. data/lib/expressir/model/types/array.rb +3 -1
  63. data/lib/expressir/model/types/bag.rb +3 -1
  64. data/lib/expressir/model/types/binary.rb +3 -1
  65. data/lib/expressir/model/types/boolean.rb +1 -1
  66. data/lib/expressir/model/types/enumeration.rb +5 -3
  67. data/lib/expressir/model/types/generic.rb +5 -1
  68. data/lib/expressir/model/types/generic_entity.rb +5 -1
  69. data/lib/expressir/model/types/integer.rb +1 -1
  70. data/lib/expressir/model/types/list.rb +3 -1
  71. data/lib/expressir/model/types/logical.rb +1 -1
  72. data/lib/expressir/model/types/number.rb +1 -1
  73. data/lib/expressir/model/types/real.rb +3 -1
  74. data/lib/expressir/model/types/select.rb +5 -3
  75. data/lib/expressir/model/types/set.rb +3 -1
  76. data/lib/expressir/model/types/string.rb +3 -1
  77. data/lib/expressir/model/unique.rb +6 -2
  78. data/lib/expressir/model/variable.rb +5 -1
  79. data/lib/expressir/model/where.rb +5 -1
  80. data/lib/expressir/version.rb +1 -1
  81. data/original/examples/syntax/hyperlink.exp +8 -0
  82. data/original/examples/syntax/hyperlink_formatted.exp +19 -0
  83. data/original/examples/syntax/remark_formatted.exp +0 -5
  84. data/original/examples/syntax/simple.exp +3 -0
  85. data/original/examples/syntax/syntax.exp +197 -189
  86. data/original/examples/syntax/syntax_formatted.exp +362 -800
  87. data/spec/expressir/express_exp/{format_remark_spec.rb → formatter/remark_spec.rb} +2 -2
  88. data/spec/expressir/express_exp/{format_syntax_spec.rb → formatter/syntax_spec.rb} +2 -2
  89. data/spec/expressir/express_exp/hyperlink_formatter_spec.rb +24 -0
  90. data/spec/expressir/express_exp/{head_source_spec.rb → parser/head_source_spec.rb} +2 -5
  91. data/spec/expressir/express_exp/{parse_multiple_spec.rb → parser/multiple_spec.rb} +6 -1
  92. data/spec/expressir/express_exp/{parse_remark_spec.rb → parser/remark_spec.rb} +5 -5
  93. data/spec/expressir/express_exp/{source_spec.rb → parser/source_spec.rb} +2 -5
  94. data/spec/expressir/express_exp/{parse_syntax_spec.rb → parser/syntax_spec.rb} +1619 -1582
  95. data/spec/expressir/express_exp/schema_head_formatter_spec.rb +36 -0
  96. data/spec/expressir/model/{find_spec.rb → model_element/find_spec.rb} +7 -2
  97. data/spec/expressir/model/model_element/hash_spec.rb +66 -0
  98. metadata +34 -12
  99. data/lib/expressir/model/scope.rb +0 -66
  100. data/spec/expressir/express_exp/ap233_spec.rb +0 -22
@@ -1,10 +1,14 @@
1
1
  module Expressir
2
2
  module Model
3
- class InformalProposition
3
+ class InformalProposition < ModelElement
4
4
  include Identifier
5
5
 
6
6
  def initialize(options = {})
7
7
  @id = options[:id]
8
+ @remarks = options.fetch(:remarks, [])
9
+ @source = options[:source]
10
+
11
+ super
8
12
  end
9
13
  end
10
14
  end
@@ -1,6 +1,6 @@
1
1
  module Expressir
2
2
  module Model
3
- class Interface
3
+ class Interface < ModelElement
4
4
  USE = :USE
5
5
  REFERENCE = :REFERENCE
6
6
 
@@ -11,7 +11,9 @@ module Expressir
11
11
  def initialize(options = {})
12
12
  @kind = options[:kind]
13
13
  @schema = options[:schema]
14
- @items = options[:items]
14
+ @items = options.fetch(:items, [])
15
+
16
+ super
15
17
  end
16
18
  end
17
19
  end
@@ -1,11 +1,13 @@
1
1
  module Expressir
2
2
  module Model
3
3
  module Literals
4
- class Binary
4
+ class Binary < ModelElement
5
5
  attr_accessor :value
6
6
 
7
7
  def initialize(options = {})
8
8
  @value = options[:value]
9
+
10
+ super
9
11
  end
10
12
  end
11
13
  end
@@ -1,11 +1,13 @@
1
1
  module Expressir
2
2
  module Model
3
3
  module Literals
4
- class Integer
4
+ class Integer < ModelElement
5
5
  attr_accessor :value
6
6
 
7
7
  def initialize(options = {})
8
8
  @value = options[:value]
9
+
10
+ super
9
11
  end
10
12
  end
11
13
  end
@@ -1,7 +1,7 @@
1
1
  module Expressir
2
2
  module Model
3
3
  module Literals
4
- class Logical
4
+ class Logical < ModelElement
5
5
  TRUE = :TRUE
6
6
  FALSE = :FALSE
7
7
  UNKNOWN = :UNKNOWN
@@ -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
@@ -1,11 +1,13 @@
1
1
  module Expressir
2
2
  module Model
3
3
  module Literals
4
- class Real
4
+ class Real < ModelElement
5
5
  attr_accessor :value
6
6
 
7
7
  def initialize(options = {})
8
8
  @value = options[:value]
9
+
10
+ super
9
11
  end
10
12
  end
11
13
  end
@@ -1,13 +1,15 @@
1
1
  module Expressir
2
2
  module Model
3
3
  module Literals
4
- class String
4
+ class String < ModelElement
5
5
  attr_accessor :value
6
6
  attr_accessor :encoded
7
7
 
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
@@ -0,0 +1,140 @@
1
+ module Expressir
2
+ module Model
3
+ class ModelElement
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
77
+
78
+ def to_hash(options = {})
79
+ skip_empty = options[:skip_empty]
80
+ formatter = options[:formatter]
81
+
82
+ hash = {}
83
+ hash[CLASS_KEY] = self.class.name
84
+
85
+ instance_variables.select{|x| x != :@parent}.each_with_object(hash) do |variable, result|
86
+ key = variable.to_s.sub(/^@/, '')
87
+ value = instance_variable_get(variable)
88
+
89
+ # skip empty values (nil, empty array)
90
+ if !skip_empty or !(value.nil? or (value.is_a? Array and value.count == 0))
91
+ result[key] = if value.is_a? Array
92
+ value.map do |value|
93
+ if value.is_a? ModelElement
94
+ value.to_hash(options)
95
+ else
96
+ value
97
+ end
98
+ end
99
+ elsif value.is_a? ModelElement
100
+ value.to_hash(options)
101
+ else
102
+ value
103
+ end
104
+ end
105
+ end
106
+
107
+ if formatter
108
+ hash[SOURCE_KEY] = formatter.format(self)
109
+ end
110
+
111
+ hash
112
+ end
113
+
114
+ def self.from_hash(hash)
115
+ node_class = hash[CLASS_KEY]
116
+ node_options = hash.select{|x| x != CLASS_KEY}.each_with_object({}) do |(variable, value), result|
117
+ key = variable.to_sym
118
+
119
+ result[key] = if value.is_a? Array
120
+ value.map do |value|
121
+ if value.is_a? Hash
122
+ self.from_hash(value)
123
+ else
124
+ value
125
+ end
126
+ end
127
+ elsif value.is_a? Hash
128
+ self.from_hash(value)
129
+ else
130
+ value
131
+ end
132
+ end
133
+
134
+ node = Object.const_get(node_class).new(node_options)
135
+
136
+ node
137
+ end
138
+ end
139
+ end
140
+ end
@@ -1,6 +1,6 @@
1
1
  module Expressir
2
2
  module Model
3
- class Parameter
3
+ class Parameter < ModelElement
4
4
  include Identifier
5
5
 
6
6
  attr_accessor :var
@@ -8,9 +8,13 @@ module Expressir
8
8
 
9
9
  def initialize(options = {})
10
10
  @id = options[:id]
11
+ @remarks = options.fetch(:remarks, [])
12
+ @source = options[:source]
11
13
 
12
14
  @var = options[:var]
13
15
  @type = options[:type]
16
+
17
+ super
14
18
  end
15
19
  end
16
20
  end
@@ -1,58 +1,47 @@
1
1
  module Expressir
2
2
  module Model
3
- class Procedure
4
- include Scope
3
+ class Procedure < ModelElement
5
4
  include Identifier
6
5
 
7
6
  attr_accessor :parameters
8
- attr_accessor :declarations
7
+ attr_accessor :types
8
+ attr_accessor :entities
9
+ attr_accessor :subtype_constraints
10
+ attr_accessor :functions
11
+ attr_accessor :procedures
9
12
  attr_accessor :constants
10
13
  attr_accessor :variables
11
14
  attr_accessor :statements
12
15
 
13
16
  def initialize(options = {})
14
17
  @id = options[:id]
15
-
16
- @parameters = options[:parameters]
17
- @declarations = options[:declarations]
18
- @constants = options[:constants]
19
- @variables = options[:variables]
20
- @statements = options[:statements]
21
- end
22
-
23
- def types
24
- @declarations.select{|x| x.instance_of? Expressir::Model::Type}
25
- end
26
-
27
- def entities
28
- @declarations.select{|x| x.instance_of? Expressir::Model::Entity}
29
- end
30
-
31
- def subtype_constraints
32
- @declarations.select{|x| x.instance_of? Expressir::Model::SubtypeConstraint}
33
- end
34
-
35
- def functions
36
- @declarations.select{|x| x.instance_of? Expressir::Model::Function}
37
- end
38
-
39
- def procedures
40
- @declarations.select{|x| x.instance_of? Expressir::Model::Procedure}
18
+ @remarks = options.fetch(:remarks, [])
19
+ @source = options[:source]
20
+
21
+ @parameters = options.fetch(:parameters, [])
22
+ @types = options.fetch(:types, [])
23
+ @entities = options.fetch(:entities, [])
24
+ @subtype_constraints = options.fetch(:subtype_constraints, [])
25
+ @functions = options.fetch(:functions, [])
26
+ @procedures = options.fetch(:procedures, [])
27
+ @constants = options.fetch(:constants, [])
28
+ @variables = options.fetch(:variables, [])
29
+ @statements = options.fetch(:statements, [])
30
+
31
+ super
41
32
  end
42
33
 
43
34
  def children
44
35
  items = []
45
- items.push(*@parameters) if @parameters
46
- items.push(*@declarations.flat_map do |x|
47
- [
48
- x,
49
- *if x.instance_of? Expressir::Model::Type and x.type.instance_of? Expressir::Model::Types::Enumeration
50
- x.type.items
51
- end
52
- ]
53
- end) if @declarations
54
- items.push(*@constants) if @constants
55
- items.push(*@variables) if @variables
36
+ items.push(*@parameters)
37
+ items.push(*@types)
38
+ items.push(*@types.flat_map{|x| x.type.is_a?(Expressir::Model::Types::Enumeration) ? x.type.items : []})
39
+ items.push(*@entities)
40
+ items.push(*@subtype_constraints)
41
+ items.push(*@functions)
42
+ items.push(*@procedures)
43
+ items.push(*@constants)
44
+ items.push(*@variables)
56
45
  items
57
46
  end
58
47
  end
@@ -1,12 +1,14 @@
1
1
  module Expressir
2
2
  module Model
3
- class RenamedRef
3
+ class RenamedRef < ModelElement
4
4
  attr_accessor :ref
5
5
  attr_accessor :id
6
6
 
7
7
  def initialize(options = {})
8
8
  @ref = options[:ref]
9
9
  @id = options[:id]
10
+
11
+ super
10
12
  end
11
13
  end
12
14
  end
@@ -1,17 +1,17 @@
1
1
  module Expressir
2
2
  module Model
3
- class Repository
4
- include Scope
5
-
3
+ class Repository < ModelElement
6
4
  attr_accessor :schemas
7
5
 
8
6
  def initialize(options = {})
9
- @schemas = options[:schemas]
7
+ @schemas = options.fetch(:schemas, [])
8
+
9
+ super
10
10
  end
11
11
 
12
12
  def children
13
13
  items = []
14
- items.push(*@schemas) if @schemas
14
+ items.push(*@schemas)
15
15
  items
16
16
  end
17
17
  end
@@ -1,11 +1,14 @@
1
1
  module Expressir
2
2
  module Model
3
- class Rule
4
- include Scope
3
+ class Rule < ModelElement
5
4
  include Identifier
6
5
 
7
6
  attr_accessor :applies_to
8
- attr_accessor :declarations
7
+ attr_accessor :types
8
+ attr_accessor :entities
9
+ attr_accessor :subtype_constraints
10
+ attr_accessor :functions
11
+ attr_accessor :procedures
9
12
  attr_accessor :constants
10
13
  attr_accessor :variables
11
14
  attr_accessor :statements
@@ -14,50 +17,36 @@ module Expressir
14
17
 
15
18
  def initialize(options = {})
16
19
  @id = options[:id]
17
-
18
- @applies_to = options[:applies_to]
19
- @declarations = options[:declarations]
20
- @constants = options[:constants]
21
- @variables = options[:variables]
22
- @statements = options[:statements]
23
- @where = options[:where]
24
- @informal_propositions = options[:informal_propositions]
25
- end
26
-
27
- def types
28
- @declarations.select{|x| x.instance_of? Expressir::Model::Type}
29
- end
30
-
31
- def entities
32
- @declarations.select{|x| x.instance_of? Expressir::Model::Entity}
33
- end
34
-
35
- def subtype_constraints
36
- @declarations.select{|x| x.instance_of? Expressir::Model::SubtypeConstraint}
37
- end
38
-
39
- def functions
40
- @declarations.select{|x| x.instance_of? Expressir::Model::Function}
41
- end
42
-
43
- def procedures
44
- @declarations.select{|x| x.instance_of? Expressir::Model::Procedure}
20
+ @remarks = options.fetch(:remarks, [])
21
+ @source = options[:source]
22
+
23
+ @applies_to = options.fetch(:applies_to, [])
24
+ @types = options.fetch(:types, [])
25
+ @entities = options.fetch(:entities, [])
26
+ @subtype_constraints = options.fetch(:subtype_constraints, [])
27
+ @functions = options.fetch(:functions, [])
28
+ @procedures = options.fetch(:procedures, [])
29
+ @constants = options.fetch(:constants, [])
30
+ @variables = options.fetch(:variables, [])
31
+ @statements = options.fetch(:statements, [])
32
+ @where = options.fetch(:where, [])
33
+ @informal_propositions = options.fetch(:informal_propositions, [])
34
+
35
+ super
45
36
  end
46
37
 
47
38
  def children
48
39
  items = []
49
- items.push(*@declarations.flat_map do |x|
50
- [
51
- x,
52
- *if x.instance_of? Expressir::Model::Type and x.type.instance_of? Expressir::Model::Types::Enumeration
53
- x.type.items
54
- end
55
- ]
56
- end) if @declarations
57
- items.push(*@constants) if @constants
58
- items.push(*@variables) if @variables
59
- items.push(*@where) if @where
60
- items.push(*@informal_propositions) if @informal_propositions
40
+ items.push(*@types)
41
+ items.push(*@types.flat_map{|x| x.type.is_a?(Expressir::Model::Types::Enumeration) ? x.type.items : []})
42
+ items.push(*@entities)
43
+ items.push(*@subtype_constraints)
44
+ items.push(*@functions)
45
+ items.push(*@procedures)
46
+ items.push(*@constants)
47
+ items.push(*@variables)
48
+ items.push(*@where)
49
+ items.push(*@informal_propositions)
61
50
  items
62
51
  end
63
52
  end