expressir 0.2.17-x86-mingw32 → 0.2.25-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +5 -0
  3. data/.github/workflows/release.yml +31 -3
  4. data/README.adoc +3 -3
  5. data/exe/format +45 -29
  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/cache.rb +48 -0
  12. data/lib/expressir/express_exp/formatter.rb +2 -2
  13. data/lib/expressir/express_exp/hyperlink_formatter.rb +10 -15
  14. data/lib/expressir/express_exp/model_visitor.rb +23 -0
  15. data/lib/expressir/express_exp/parser.rb +18 -3
  16. data/lib/expressir/express_exp/resolve_references_model_visitor.rb +33 -0
  17. data/lib/expressir/express_exp/visitor.rb +19 -18
  18. data/lib/expressir/model.rb +3 -1
  19. data/lib/expressir/model/attribute.rb +12 -5
  20. data/lib/expressir/model/cache.rb +13 -0
  21. data/lib/expressir/model/constant.rb +9 -2
  22. data/lib/expressir/model/entity.rb +10 -8
  23. data/lib/expressir/model/enumeration_item.rb +7 -0
  24. data/lib/expressir/model/expressions/aggregate_initializer.rb +1 -1
  25. data/lib/expressir/model/expressions/aggregate_item.rb +2 -2
  26. data/lib/expressir/model/expressions/attribute_reference.rb +2 -2
  27. data/lib/expressir/model/expressions/binary_expression.rb +3 -3
  28. data/lib/expressir/model/expressions/call.rb +2 -2
  29. data/lib/expressir/model/expressions/entity_constructor.rb +2 -2
  30. data/lib/expressir/model/expressions/group_reference.rb +2 -2
  31. data/lib/expressir/model/expressions/index_reference.rb +3 -3
  32. data/lib/expressir/model/expressions/interval.rb +5 -5
  33. data/lib/expressir/model/expressions/query_expression.rb +5 -3
  34. data/lib/expressir/model/expressions/simple_reference.rb +5 -1
  35. data/lib/expressir/model/expressions/unary_expression.rb +2 -2
  36. data/lib/expressir/model/function.rb +13 -11
  37. data/lib/expressir/model/identifier.rb +6 -3
  38. data/lib/expressir/model/interface.rb +3 -3
  39. data/lib/expressir/model/interface_item.rb +2 -2
  40. data/lib/expressir/model/interfaced_item.rb +9 -8
  41. data/lib/expressir/model/literals/binary.rb +1 -1
  42. data/lib/expressir/model/literals/integer.rb +1 -1
  43. data/lib/expressir/model/literals/logical.rb +1 -1
  44. data/lib/expressir/model/literals/real.rb +1 -1
  45. data/lib/expressir/model/literals/string.rb +2 -2
  46. data/lib/expressir/model/model_element.rb +46 -21
  47. data/lib/expressir/model/parameter.rb +9 -2
  48. data/lib/expressir/model/procedure.rb +12 -10
  49. data/lib/expressir/model/{informal_proposition.rb → remark_item.rb} +3 -6
  50. data/lib/expressir/model/repository.rb +1 -1
  51. data/lib/expressir/model/rule.rb +14 -12
  52. data/lib/expressir/model/schema.rb +13 -11
  53. data/lib/expressir/model/statements/alias.rb +5 -3
  54. data/lib/expressir/model/statements/assignment.rb +2 -2
  55. data/lib/expressir/model/statements/call.rb +2 -2
  56. data/lib/expressir/model/statements/case.rb +3 -3
  57. data/lib/expressir/model/statements/case_action.rb +2 -2
  58. data/lib/expressir/model/statements/compound.rb +1 -1
  59. data/lib/expressir/model/statements/if.rb +3 -3
  60. data/lib/expressir/model/statements/repeat.rb +9 -7
  61. data/lib/expressir/model/statements/return.rb +1 -1
  62. data/lib/expressir/model/subtype_constraint.rb +11 -4
  63. data/lib/expressir/model/type.rb +6 -4
  64. data/lib/expressir/model/types/aggregate.rb +8 -1
  65. data/lib/expressir/model/types/array.rb +5 -5
  66. data/lib/expressir/model/types/bag.rb +3 -3
  67. data/lib/expressir/model/types/binary.rb +2 -2
  68. data/lib/expressir/model/types/enumeration.rb +4 -4
  69. data/lib/expressir/model/types/generic.rb +7 -0
  70. data/lib/expressir/model/types/generic_entity.rb +7 -0
  71. data/lib/expressir/model/types/list.rb +4 -4
  72. data/lib/expressir/model/types/real.rb +1 -1
  73. data/lib/expressir/model/types/select.rb +5 -5
  74. data/lib/expressir/model/types/set.rb +3 -3
  75. data/lib/expressir/model/types/string.rb +2 -2
  76. data/lib/expressir/model/unique.rb +8 -1
  77. data/lib/expressir/model/variable.rb +9 -2
  78. data/lib/expressir/model/where.rb +8 -1
  79. data/lib/expressir/version.rb +1 -1
  80. data/original/examples/syntax/multiple.yaml +18 -0
  81. data/original/examples/syntax/remark.exp +12 -10
  82. data/original/examples/syntax/remark.yaml +24 -3
  83. data/original/examples/syntax/remark_formatted.exp +3 -1
  84. data/original/examples/syntax/single.exp +1 -0
  85. data/original/examples/syntax/single.yaml +7 -0
  86. data/original/examples/syntax/single_formatted.exp +4 -0
  87. data/original/examples/syntax/single_formatted.yaml +15 -0
  88. data/original/examples/syntax/syntax.yaml +82 -0
  89. data/original/examples/syntax/syntax_hyperlink_formatted.exp +902 -0
  90. data/spec/expressir/express_exp/cache_spec.rb +64 -0
  91. data/spec/expressir/express_exp/formatter_spec.rb +17 -0
  92. data/spec/expressir/express_exp/parser_spec.rb +9 -9
  93. data/spec/expressir/model/model_element_spec.rb +32 -29
  94. metadata +9 -3
@@ -2,7 +2,7 @@ module Expressir
2
2
  module Model
3
3
  module Literals
4
4
  class Binary < ModelElement
5
- attr_accessor :value
5
+ model_attr_accessor :value
6
6
 
7
7
  def initialize(options = {})
8
8
  @value = options[:value]
@@ -2,7 +2,7 @@ module Expressir
2
2
  module Model
3
3
  module Literals
4
4
  class Integer < ModelElement
5
- attr_accessor :value
5
+ model_attr_accessor :value
6
6
 
7
7
  def initialize(options = {})
8
8
  @value = options[:value]
@@ -6,7 +6,7 @@ module Expressir
6
6
  FALSE = :FALSE
7
7
  UNKNOWN = :UNKNOWN
8
8
 
9
- attr_accessor :value
9
+ model_attr_accessor :value
10
10
 
11
11
  def initialize(options = {})
12
12
  @value = options[:value]
@@ -2,7 +2,7 @@ module Expressir
2
2
  module Model
3
3
  module Literals
4
4
  class Real < ModelElement
5
- attr_accessor :value
5
+ model_attr_accessor :value
6
6
 
7
7
  def initialize(options = {})
8
8
  @value = options[:value]
@@ -2,8 +2,8 @@ module Expressir
2
2
  module Model
3
3
  module Literals
4
4
  class String < ModelElement
5
- attr_accessor :value
6
- attr_accessor :encoded
5
+ model_attr_accessor :value
6
+ model_attr_accessor :encoded
7
7
 
8
8
  def initialize(options = {})
9
9
  @value = options[:value]
@@ -1,7 +1,10 @@
1
+ require 'pathname'
2
+
1
3
  module Expressir
2
4
  module Model
3
5
  class ModelElement
4
6
  CLASS_KEY = '_class'
7
+ FILE_KEY = 'file'
5
8
  SOURCE_KEY = 'source'
6
9
 
7
10
  attr_accessor :parent
@@ -10,17 +13,14 @@ module Expressir
10
13
  attach_parent_to_children
11
14
  end
12
15
 
13
- def model_instance_variables
14
- instance_variables.select{|x| x != :@file && x != :@parent && x != :@children_by_id}
15
- end
16
-
17
16
  def path
18
- return id if is_a? Statements::Alias or is_a? Statements::Repeat or is_a? Expressions::QueryExpression
17
+ # this creates an implicit scope
18
+ return if is_a? Statements::Alias or is_a? Statements::Repeat or is_a? Expressions::QueryExpression
19
19
 
20
20
  current_node = self
21
21
  path_parts = []
22
22
  loop do
23
- if current_node.class.method_defined? :id
23
+ if current_node.class.method_defined? :id and !(current_node.is_a? Expressions::SimpleReference)
24
24
  path_parts << current_node.id
25
25
  end
26
26
 
@@ -28,12 +28,14 @@ module Expressir
28
28
  break unless current_node
29
29
  end
30
30
 
31
+ return if path_parts.empty?
32
+
31
33
  path_parts.reverse.join(".")
32
34
  end
33
35
 
34
36
  def attach_parent_to_children
35
- model_instance_variables.each do |variable|
36
- value = instance_variable_get(variable)
37
+ self.class.model_attrs.each do |variable|
38
+ value = self.send(variable)
37
39
 
38
40
  if value.is_a? Array
39
41
  value.each do |value|
@@ -88,20 +90,20 @@ module Expressir
88
90
  end
89
91
 
90
92
  def to_hash(options = {})
91
- include_empty = options[:include_empty] || !options[:skip_empty] # TODO: remove skip_empty
93
+ root_path = options[:root_path]
92
94
  formatter = options[:formatter]
95
+ include_empty = options[:include_empty] || !options[:skip_empty] # TODO: remove skip_empty
93
96
 
94
97
  hash = {}
95
98
  hash[CLASS_KEY] = self.class.name
96
99
 
97
- model_instance_variables.each_with_object(hash) do |variable, result|
98
- key = variable.to_s.sub(/^@/, '')
99
- value = instance_variable_get(variable)
100
+ self.class.model_attrs.each do |variable|
101
+ value = self.send(variable)
100
102
  empty = value.nil? || (value.is_a?(Array) && value.count == 0)
101
103
 
102
104
  # skip empty values
103
105
  if !empty or include_empty
104
- result[key] = if value.is_a? Array
106
+ hash[variable.to_s] = if value.is_a? Array
105
107
  value.map do |value|
106
108
  if value.is_a? ModelElement
107
109
  value.to_hash(options)
@@ -117,6 +119,10 @@ module Expressir
117
119
  end
118
120
  end
119
121
 
122
+ if self.is_a? Schema and file
123
+ hash[FILE_KEY] = root_path ? Pathname.new(file).relative_path_from(root_path).to_s : file
124
+ end
125
+
120
126
  if self.class.method_defined? :source and formatter
121
127
  hash[SOURCE_KEY] = formatter.format(self)
122
128
  end
@@ -124,30 +130,49 @@ module Expressir
124
130
  hash
125
131
  end
126
132
 
127
- def self.from_hash(hash)
128
- node_class = hash[CLASS_KEY]
129
- node_options = hash.select{|x| x != CLASS_KEY}.each_with_object({}) do |(variable, value), result|
130
- key = variable.to_sym
133
+ def self.from_hash(hash, options = {})
134
+ root_path = options[:root_path]
135
+
136
+ node_class = Object.const_get(hash[CLASS_KEY])
137
+ node_options = {}
131
138
 
132
- result[key] = if value.is_a? Array
139
+ node_class.model_attrs.each do |variable|
140
+ value = hash[variable.to_s]
141
+
142
+ node_options[variable] = if value.is_a? Array
133
143
  value.map do |value|
134
144
  if value.is_a? Hash
135
- self.from_hash(value)
145
+ self.from_hash(value, options)
136
146
  else
137
147
  value
138
148
  end
139
149
  end
140
150
  elsif value.is_a? Hash
141
- self.from_hash(value)
151
+ self.from_hash(value, options)
142
152
  else
143
153
  value
144
154
  end
145
155
  end
146
156
 
147
- node = Object.const_get(node_class).new(node_options)
157
+ if node_class == Schema and hash[FILE_KEY]
158
+ node_options[FILE_KEY.to_sym] = root_path ? File.expand_path("#{root_path}/#{hash[FILE_KEY]}") : hash[FILE_KEY]
159
+ end
160
+
161
+ node = node_class.new(node_options)
148
162
 
149
163
  node
150
164
  end
165
+
166
+ def self.model_attrs
167
+ @model_attrs ||= []
168
+ end
169
+
170
+ def self.model_attr_accessor(*vars)
171
+ @model_attrs ||= []
172
+ @model_attrs.concat(vars)
173
+
174
+ attr_accessor *vars
175
+ end
151
176
  end
152
177
  end
153
178
  end
@@ -3,12 +3,13 @@ module Expressir
3
3
  class Parameter < ModelElement
4
4
  include Identifier
5
5
 
6
- attr_accessor :var
7
- attr_accessor :type
6
+ model_attr_accessor :var
7
+ model_attr_accessor :type
8
8
 
9
9
  def initialize(options = {})
10
10
  @id = options[:id]
11
11
  @remarks = options.fetch(:remarks, [])
12
+ @remark_items = options.fetch(:remark_items, [])
12
13
  @source = options[:source]
13
14
 
14
15
  @var = options[:var]
@@ -16,6 +17,12 @@ module Expressir
16
17
 
17
18
  super
18
19
  end
20
+
21
+ def children
22
+ [
23
+ *remark_items
24
+ ]
25
+ end
19
26
  end
20
27
  end
21
28
  end
@@ -3,19 +3,20 @@ module Expressir
3
3
  class Procedure < ModelElement
4
4
  include Identifier
5
5
 
6
- attr_accessor :parameters
7
- attr_accessor :types
8
- attr_accessor :entities
9
- attr_accessor :subtype_constraints
10
- attr_accessor :functions
11
- attr_accessor :procedures
12
- attr_accessor :constants
13
- attr_accessor :variables
14
- attr_accessor :statements
6
+ model_attr_accessor :parameters
7
+ model_attr_accessor :types
8
+ model_attr_accessor :entities
9
+ model_attr_accessor :subtype_constraints
10
+ model_attr_accessor :functions
11
+ model_attr_accessor :procedures
12
+ model_attr_accessor :constants
13
+ model_attr_accessor :variables
14
+ model_attr_accessor :statements
15
15
 
16
16
  def initialize(options = {})
17
17
  @id = options[:id]
18
18
  @remarks = options.fetch(:remarks, [])
19
+ @remark_items = options.fetch(:remark_items, [])
19
20
  @source = options[:source]
20
21
 
21
22
  @parameters = options.fetch(:parameters, [])
@@ -45,7 +46,8 @@ module Expressir
45
46
  *functions,
46
47
  *procedures,
47
48
  *constants,
48
- *variables
49
+ *variables,
50
+ *remark_items
49
51
  ]
50
52
  end
51
53
  end
@@ -1,15 +1,12 @@
1
1
  module Expressir
2
2
  module Model
3
- class InformalProposition < ModelElement
4
- include Identifier
5
-
6
- undef :source
7
- undef :source=
3
+ class RemarkItem < ModelElement
4
+ model_attr_accessor :id
5
+ model_attr_accessor :remarks
8
6
 
9
7
  def initialize(options = {})
10
8
  @id = options[:id]
11
9
  @remarks = options.fetch(:remarks, [])
12
- # @source = options[:source]
13
10
 
14
11
  super
15
12
  end
@@ -1,7 +1,7 @@
1
1
  module Expressir
2
2
  module Model
3
3
  class Repository < ModelElement
4
- attr_accessor :schemas
4
+ model_attr_accessor :schemas
5
5
 
6
6
  def initialize(options = {})
7
7
  @schemas = options.fetch(:schemas, [])
@@ -3,21 +3,22 @@ module Expressir
3
3
  class Rule < ModelElement
4
4
  include Identifier
5
5
 
6
- attr_accessor :applies_to
7
- attr_accessor :types
8
- attr_accessor :entities
9
- attr_accessor :subtype_constraints
10
- attr_accessor :functions
11
- attr_accessor :procedures
12
- attr_accessor :constants
13
- attr_accessor :variables
14
- attr_accessor :statements
15
- attr_accessor :where
16
- attr_accessor :informal_propositions
6
+ model_attr_accessor :applies_to
7
+ model_attr_accessor :types
8
+ model_attr_accessor :entities
9
+ model_attr_accessor :subtype_constraints
10
+ model_attr_accessor :functions
11
+ model_attr_accessor :procedures
12
+ model_attr_accessor :constants
13
+ model_attr_accessor :variables
14
+ model_attr_accessor :statements
15
+ model_attr_accessor :where
16
+ model_attr_accessor :informal_propositions
17
17
 
18
18
  def initialize(options = {})
19
19
  @id = options[:id]
20
20
  @remarks = options.fetch(:remarks, [])
21
+ @remark_items = options.fetch(:remark_items, [])
21
22
  @source = options[:source]
22
23
 
23
24
  @applies_to = options.fetch(:applies_to, [])
@@ -50,7 +51,8 @@ module Expressir
50
51
  *constants,
51
52
  *variables,
52
53
  *where,
53
- *informal_propositions
54
+ *informal_propositions,
55
+ *remark_items
54
56
  ]
55
57
  end
56
58
  end
@@ -1,25 +1,26 @@
1
1
  module Expressir
2
2
  module Model
3
3
  class Schema < ModelElement
4
- attr_accessor :file
4
+ model_attr_accessor :file
5
5
 
6
6
  include Identifier
7
7
 
8
- attr_accessor :version
9
- attr_accessor :interfaces
10
- attr_accessor :constants
11
- attr_accessor :types
12
- attr_accessor :entities
13
- attr_accessor :subtype_constraints
14
- attr_accessor :functions
15
- attr_accessor :rules
16
- attr_accessor :procedures
8
+ model_attr_accessor :version
9
+ model_attr_accessor :interfaces
10
+ model_attr_accessor :constants
11
+ model_attr_accessor :types
12
+ model_attr_accessor :entities
13
+ model_attr_accessor :subtype_constraints
14
+ model_attr_accessor :functions
15
+ model_attr_accessor :rules
16
+ model_attr_accessor :procedures
17
17
 
18
18
  def initialize(options = {})
19
19
  @file = options[:file]
20
20
 
21
21
  @id = options[:id]
22
22
  @remarks = options.fetch(:remarks, [])
23
+ @remark_items = options.fetch(:remark_items, [])
23
24
  @source = options[:source]
24
25
 
25
26
  @version = options[:version]
@@ -81,7 +82,8 @@ module Expressir
81
82
  *subtype_constraints,
82
83
  *functions,
83
84
  *rules,
84
- *procedures
85
+ *procedures,
86
+ *remark_items
85
87
  ]
86
88
  end
87
89
 
@@ -4,12 +4,13 @@ module Expressir
4
4
  class Alias < ModelElement
5
5
  include Identifier
6
6
 
7
- attr_accessor :expression
8
- attr_accessor :statements
7
+ model_attr_accessor :expression
8
+ model_attr_accessor :statements
9
9
 
10
10
  def initialize(options = {})
11
11
  @id = options[:id]
12
12
  @remarks = options.fetch(:remarks, [])
13
+ @remark_items = options.fetch(:remark_items, [])
13
14
  @source = options[:source]
14
15
 
15
16
  @expression = options[:expression]
@@ -20,7 +21,8 @@ module Expressir
20
21
 
21
22
  def children
22
23
  [
23
- self
24
+ self,
25
+ *remark_items
24
26
  ]
25
27
  end
26
28
  end
@@ -2,8 +2,8 @@ module Expressir
2
2
  module Model
3
3
  module Statements
4
4
  class Assignment < ModelElement
5
- attr_accessor :ref
6
- attr_accessor :expression
5
+ model_attr_accessor :ref
6
+ model_attr_accessor :expression
7
7
 
8
8
  def initialize(options = {})
9
9
  @ref = options[:ref]
@@ -2,8 +2,8 @@ module Expressir
2
2
  module Model
3
3
  module Statements
4
4
  class Call < ModelElement
5
- attr_accessor :ref
6
- attr_accessor :parameters
5
+ model_attr_accessor :ref
6
+ model_attr_accessor :parameters
7
7
 
8
8
  def initialize(options = {})
9
9
  @ref = options[:ref]
@@ -2,9 +2,9 @@ module Expressir
2
2
  module Model
3
3
  module Statements
4
4
  class Case < ModelElement
5
- attr_accessor :expression
6
- attr_accessor :actions
7
- attr_accessor :otherwise_statement
5
+ model_attr_accessor :expression
6
+ model_attr_accessor :actions
7
+ model_attr_accessor :otherwise_statement
8
8
 
9
9
  def initialize(options = {})
10
10
  @expression = options[:expression]