expressir 0.2.8-x64-mingw32 → 0.2.13-x64-mingw32

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 (105) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/release.yml +1 -7
  3. data/exe/format +20 -0
  4. data/expressir.gemspec +3 -2
  5. data/lib/expressir/express_exp/2.4/express_parser.so +0 -0
  6. data/lib/expressir/express_exp/2.5/express_parser.so +0 -0
  7. data/lib/expressir/express_exp/2.6/express_parser.so +0 -0
  8. data/lib/expressir/express_exp/2.7/express_parser.so +0 -0
  9. data/lib/expressir/express_exp/3.0/express_parser.so +0 -0
  10. data/lib/expressir/express_exp/formatter.rb +147 -110
  11. data/lib/expressir/express_exp/hyperlink_formatter.rb +25 -0
  12. data/lib/expressir/express_exp/parser.rb +14 -1
  13. data/lib/expressir/express_exp/schema_head_formatter.rb +14 -0
  14. data/lib/expressir/express_exp/visitor.rb +197 -111
  15. data/lib/expressir/model.rb +3 -1
  16. data/lib/expressir/model/attribute.rb +5 -1
  17. data/lib/expressir/model/constant.rb +5 -1
  18. data/lib/expressir/model/entity.rb +14 -20
  19. data/lib/expressir/model/enumeration_item.rb +5 -1
  20. data/lib/expressir/model/expressions/aggregate_initializer.rb +4 -2
  21. data/lib/expressir/model/expressions/aggregate_item.rb +3 -1
  22. data/lib/expressir/model/expressions/attribute_reference.rb +3 -1
  23. data/lib/expressir/model/expressions/binary_expression.rb +3 -1
  24. data/lib/expressir/model/expressions/call.rb +4 -2
  25. data/lib/expressir/model/expressions/entity_constructor.rb +4 -2
  26. data/lib/expressir/model/expressions/group_reference.rb +3 -1
  27. data/lib/expressir/model/expressions/index_reference.rb +3 -1
  28. data/lib/expressir/model/expressions/interval.rb +3 -1
  29. data/lib/expressir/model/expressions/query_expression.rb +5 -2
  30. data/lib/expressir/model/expressions/simple_reference.rb +3 -1
  31. data/lib/expressir/model/expressions/unary_expression.rb +3 -1
  32. data/lib/expressir/model/function.rb +28 -39
  33. data/lib/expressir/model/identifier.rb +1 -3
  34. data/lib/expressir/model/informal_proposition.rb +15 -0
  35. data/lib/expressir/model/interface.rb +4 -2
  36. data/lib/expressir/model/literals/binary.rb +3 -1
  37. data/lib/expressir/model/literals/integer.rb +3 -1
  38. data/lib/expressir/model/literals/logical.rb +3 -1
  39. data/lib/expressir/model/literals/real.rb +3 -1
  40. data/lib/expressir/model/literals/string.rb +3 -1
  41. data/lib/expressir/model/model_element.rb +140 -0
  42. data/lib/expressir/model/parameter.rb +5 -1
  43. data/lib/expressir/model/procedure.rb +29 -40
  44. data/lib/expressir/model/renamed_ref.rb +3 -1
  45. data/lib/expressir/model/repository.rb +5 -5
  46. data/lib/expressir/model/rule.rb +33 -41
  47. data/lib/expressir/model/schema.rb +44 -46
  48. data/lib/expressir/model/statements/alias.rb +6 -3
  49. data/lib/expressir/model/statements/assignment.rb +3 -1
  50. data/lib/expressir/model/statements/call.rb +4 -2
  51. data/lib/expressir/model/statements/case.rb +4 -2
  52. data/lib/expressir/model/statements/case_action.rb +4 -2
  53. data/lib/expressir/model/statements/compound.rb +4 -2
  54. data/lib/expressir/model/statements/escape.rb +1 -1
  55. data/lib/expressir/model/statements/if.rb +5 -3
  56. data/lib/expressir/model/statements/null.rb +1 -1
  57. data/lib/expressir/model/statements/repeat.rb +6 -3
  58. data/lib/expressir/model/statements/return.rb +3 -1
  59. data/lib/expressir/model/statements/skip.rb +1 -1
  60. data/lib/expressir/model/subtype_constraint.rb +5 -2
  61. data/lib/expressir/model/type.rb +11 -4
  62. data/lib/expressir/model/types/aggregate.rb +5 -1
  63. data/lib/expressir/model/types/array.rb +3 -1
  64. data/lib/expressir/model/types/bag.rb +3 -1
  65. data/lib/expressir/model/types/binary.rb +3 -1
  66. data/lib/expressir/model/types/boolean.rb +1 -1
  67. data/lib/expressir/model/types/enumeration.rb +5 -3
  68. data/lib/expressir/model/types/generic.rb +5 -1
  69. data/lib/expressir/model/types/generic_entity.rb +5 -1
  70. data/lib/expressir/model/types/integer.rb +1 -1
  71. data/lib/expressir/model/types/list.rb +3 -1
  72. data/lib/expressir/model/types/logical.rb +1 -1
  73. data/lib/expressir/model/types/number.rb +1 -1
  74. data/lib/expressir/model/types/real.rb +3 -1
  75. data/lib/expressir/model/types/select.rb +5 -3
  76. data/lib/expressir/model/types/set.rb +3 -1
  77. data/lib/expressir/model/types/string.rb +3 -1
  78. data/lib/expressir/model/unique.rb +6 -2
  79. data/lib/expressir/model/variable.rb +5 -1
  80. data/lib/expressir/model/where.rb +5 -1
  81. data/lib/expressir/version.rb +1 -1
  82. data/original/examples/syntax/hyperlink.exp +8 -0
  83. data/original/examples/syntax/hyperlink_formatted.exp +19 -0
  84. data/original/examples/syntax/remark.exp +63 -20
  85. data/original/examples/syntax/remark_formatted.exp +62 -24
  86. data/original/examples/syntax/simple.exp +3 -0
  87. data/original/examples/syntax/source.exp +16 -0
  88. data/original/examples/syntax/syntax.exp +201 -190
  89. data/original/examples/syntax/syntax_formatted.exp +370 -799
  90. data/spec/expressir/express_exp/{format_remark_spec.rb → formatter/remark_spec.rb} +2 -2
  91. data/spec/expressir/express_exp/{format_syntax_spec.rb → formatter/syntax_spec.rb} +2 -2
  92. data/spec/expressir/express_exp/hyperlink_formatter_spec.rb +24 -0
  93. data/spec/expressir/express_exp/parser/head_source_spec.rb +38 -0
  94. data/spec/expressir/express_exp/parser/multiple_spec.rb +32 -0
  95. data/spec/expressir/express_exp/{parse_remark_spec.rb → parser/remark_spec.rb} +120 -55
  96. data/spec/expressir/express_exp/{source_spec.rb → parser/source_spec.rb} +3 -6
  97. data/spec/expressir/express_exp/parser/syntax_spec.rb +3080 -0
  98. data/spec/expressir/express_exp/schema_head_formatter_spec.rb +36 -0
  99. data/spec/expressir/model/{find_spec.rb → model_element/find_spec.rb} +26 -8
  100. data/spec/expressir/model/model_element/hash_spec.rb +66 -0
  101. metadata +38 -13
  102. data/lib/expressir/model/scope.rb +0 -32
  103. data/spec/expressir/express_exp/ap233_spec.rb +0 -22
  104. data/spec/expressir/express_exp/find_spec.rb +0 -28
  105. data/spec/expressir/express_exp/parse_syntax_spec.rb +0 -3003
@@ -1,11 +1,9 @@
1
1
  module Expressir
2
2
  module Model
3
3
  module Identifier
4
- attr_accessor :source
5
-
6
4
  attr_accessor :id
7
- attr_accessor :parent
8
5
  attr_accessor :remarks
6
+ attr_accessor :source
9
7
  end
10
8
  end
11
9
  end
@@ -0,0 +1,15 @@
1
+ module Expressir
2
+ module Model
3
+ class InformalProposition < ModelElement
4
+ include Identifier
5
+
6
+ def initialize(options = {})
7
+ @id = options[:id]
8
+ @remarks = options.fetch(:remarks, [])
9
+ @source = options[:source]
10
+
11
+ super
12
+ end
13
+ end
14
+ end
15
+ 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,60 +1,52 @@
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
12
15
  attr_accessor :where
16
+ attr_accessor :informal_propositions
13
17
 
14
18
  def initialize(options = {})
15
19
  @id = options[:id]
16
-
17
- @applies_to = options[:applies_to]
18
- @declarations = options[:declarations]
19
- @constants = options[:constants]
20
- @variables = options[:variables]
21
- @statements = options[:statements]
22
- @where = options[:where]
23
- end
24
-
25
- def types
26
- @declarations.select{|x| x.instance_of? Expressir::Model::Type}
27
- end
28
-
29
- def entities
30
- @declarations.select{|x| x.instance_of? Expressir::Model::Entity}
31
- end
32
-
33
- def subtype_constraints
34
- @declarations.select{|x| x.instance_of? Expressir::Model::SubtypeConstraint}
35
- end
36
-
37
- def functions
38
- @declarations.select{|x| x.instance_of? Expressir::Model::Function}
39
- end
40
-
41
- def procedures
42
- @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
43
36
  end
44
37
 
45
38
  def children
46
39
  items = []
47
- items.push(*@declarations.flat_map do |x|
48
- [
49
- x,
50
- *if x.instance_of? Expressir::Model::Type and x.type.instance_of? Expressir::Model::Types::Enumeration
51
- x.type.items
52
- end
53
- ]
54
- end) if @declarations
55
- items.push(*@constants) if @constants
56
- items.push(*@variables) if @variables
57
- items.push(*@where) if @where
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)
58
50
  items
59
51
  end
60
52
  end