expressir 0.2.16-x86-mingw32 → 0.2.24-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) 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 +66 -12
  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 +185 -135
  13. data/lib/expressir/express_exp/parser.rb +33 -29
  14. data/lib/expressir/express_exp/schema_head_formatter.rb +1 -4
  15. data/lib/expressir/express_exp/visitor.rb +29 -23
  16. data/lib/expressir/model.rb +3 -1
  17. data/lib/expressir/model/attribute.rb +12 -5
  18. data/lib/expressir/model/cache.rb +13 -0
  19. data/lib/expressir/model/constant.rb +9 -2
  20. data/lib/expressir/model/entity.rb +15 -13
  21. data/lib/expressir/model/enumeration_item.rb +7 -0
  22. data/lib/expressir/model/expressions/aggregate_initializer.rb +1 -1
  23. data/lib/expressir/model/expressions/aggregate_item.rb +2 -2
  24. data/lib/expressir/model/expressions/attribute_reference.rb +2 -2
  25. data/lib/expressir/model/expressions/binary_expression.rb +3 -3
  26. data/lib/expressir/model/expressions/call.rb +2 -2
  27. data/lib/expressir/model/expressions/entity_constructor.rb +2 -2
  28. data/lib/expressir/model/expressions/group_reference.rb +2 -2
  29. data/lib/expressir/model/expressions/index_reference.rb +3 -3
  30. data/lib/expressir/model/expressions/interval.rb +5 -5
  31. data/lib/expressir/model/expressions/query_expression.rb +7 -5
  32. data/lib/expressir/model/expressions/simple_reference.rb +1 -1
  33. data/lib/expressir/model/expressions/unary_expression.rb +2 -2
  34. data/lib/expressir/model/function.rb +27 -21
  35. data/lib/expressir/model/identifier.rb +6 -3
  36. data/lib/expressir/model/interface.rb +3 -3
  37. data/lib/expressir/model/interface_item.rb +2 -2
  38. data/lib/expressir/model/interfaced_item.rb +11 -3
  39. data/lib/expressir/model/literals/binary.rb +1 -1
  40. data/lib/expressir/model/literals/integer.rb +1 -1
  41. data/lib/expressir/model/literals/logical.rb +1 -1
  42. data/lib/expressir/model/literals/real.rb +1 -1
  43. data/lib/expressir/model/literals/string.rb +2 -2
  44. data/lib/expressir/model/model_element.rb +54 -19
  45. data/lib/expressir/model/parameter.rb +9 -2
  46. data/lib/expressir/model/procedure.rb +26 -20
  47. data/lib/expressir/model/{informal_proposition.rb → remark_item.rb} +3 -3
  48. data/lib/expressir/model/repository.rb +4 -4
  49. data/lib/expressir/model/rule.rb +29 -23
  50. data/lib/expressir/model/schema.rb +63 -54
  51. data/lib/expressir/model/statements/alias.rb +7 -5
  52. data/lib/expressir/model/statements/assignment.rb +2 -2
  53. data/lib/expressir/model/statements/call.rb +2 -2
  54. data/lib/expressir/model/statements/case.rb +3 -3
  55. data/lib/expressir/model/statements/case_action.rb +2 -2
  56. data/lib/expressir/model/statements/compound.rb +1 -1
  57. data/lib/expressir/model/statements/if.rb +3 -3
  58. data/lib/expressir/model/statements/repeat.rb +11 -9
  59. data/lib/expressir/model/statements/return.rb +1 -1
  60. data/lib/expressir/model/subtype_constraint.rb +9 -7
  61. data/lib/expressir/model/type.rb +14 -8
  62. data/lib/expressir/model/types/aggregate.rb +8 -1
  63. data/lib/expressir/model/types/array.rb +5 -5
  64. data/lib/expressir/model/types/bag.rb +3 -3
  65. data/lib/expressir/model/types/binary.rb +2 -2
  66. data/lib/expressir/model/types/enumeration.rb +4 -4
  67. data/lib/expressir/model/types/generic.rb +7 -0
  68. data/lib/expressir/model/types/generic_entity.rb +7 -0
  69. data/lib/expressir/model/types/list.rb +4 -4
  70. data/lib/expressir/model/types/real.rb +1 -1
  71. data/lib/expressir/model/types/select.rb +5 -5
  72. data/lib/expressir/model/types/set.rb +3 -3
  73. data/lib/expressir/model/types/string.rb +2 -2
  74. data/lib/expressir/model/unique.rb +8 -1
  75. data/lib/expressir/model/variable.rb +9 -2
  76. data/lib/expressir/model/where.rb +8 -1
  77. data/lib/expressir/version.rb +1 -1
  78. data/original/examples/syntax/{hyperlink.exp → multiple.exp} +8 -8
  79. data/original/examples/syntax/multiple.yaml +184 -0
  80. data/original/examples/syntax/multiple_formatted.exp +71 -0
  81. data/original/examples/syntax/multiple_hyperlink_formatted.exp +71 -0
  82. data/original/examples/syntax/multiple_schema_head_hyperlink_formatted.exp +13 -0
  83. data/original/examples/syntax/remark.exp +52 -50
  84. data/original/examples/syntax/remark.yaml +452 -0
  85. data/original/examples/syntax/remark_formatted.exp +64 -50
  86. data/original/examples/syntax/{simple.exp → single.exp} +1 -1
  87. data/original/examples/syntax/single.yaml +9 -0
  88. data/original/examples/syntax/single_formatted.exp +6 -0
  89. data/original/examples/syntax/single_formatted.yaml +19 -0
  90. data/original/examples/syntax/syntax.exp +29 -19
  91. data/original/examples/syntax/syntax.yaml +3439 -0
  92. data/original/examples/syntax/syntax_formatted.exp +271 -131
  93. data/original/examples/syntax/syntax_schema_head_formatted.exp +18 -0
  94. data/spec/expressir/express_exp/cache_spec.rb +64 -0
  95. data/spec/expressir/express_exp/formatter_spec.rb +111 -0
  96. data/spec/expressir/express_exp/parser_spec.rb +98 -0
  97. data/spec/expressir/model/{model_element/find_spec.rb → model_element_spec.rb} +96 -10
  98. metadata +21 -17
  99. data/original/examples/syntax/hyperlink_formatted.exp +0 -51
  100. data/original/examples/syntax/source.exp +0 -16
  101. data/spec/expressir/express_exp/formatter/remark_spec.rb +0 -28
  102. data/spec/expressir/express_exp/formatter/syntax_spec.rb +0 -28
  103. data/spec/expressir/express_exp/hyperlink_formatter_spec.rb +0 -28
  104. data/spec/expressir/express_exp/parser/multiple_spec.rb +0 -37
  105. data/spec/expressir/express_exp/parser/remark_spec.rb +0 -411
  106. data/spec/expressir/express_exp/parser/source_spec.rb +0 -29
  107. data/spec/expressir/express_exp/parser/syntax_spec.rb +0 -3086
  108. data/spec/expressir/express_exp/schema_head_formatter_spec.rb +0 -40
  109. data/spec/expressir/model/model_element/hash_spec.rb +0 -66
@@ -2,9 +2,9 @@ module Expressir
2
2
  module Model
3
3
  module Expressions
4
4
  class IndexReference < ModelElement
5
- attr_accessor :ref
6
- attr_accessor :index1
7
- attr_accessor :index2
5
+ model_attr_accessor :ref
6
+ model_attr_accessor :index1
7
+ model_attr_accessor :index2
8
8
 
9
9
  def initialize(options = {})
10
10
  @ref = options[:ref]
@@ -2,11 +2,11 @@ module Expressir
2
2
  module Model
3
3
  module Expressions
4
4
  class Interval < ModelElement
5
- attr_accessor :low
6
- attr_accessor :operator1
7
- attr_accessor :item
8
- attr_accessor :operator2
9
- attr_accessor :high
5
+ model_attr_accessor :low
6
+ model_attr_accessor :operator1
7
+ model_attr_accessor :item
8
+ model_attr_accessor :operator2
9
+ model_attr_accessor :high
10
10
 
11
11
  def initialize(options = {})
12
12
  @low = options[:low]
@@ -4,12 +4,13 @@ module Expressir
4
4
  class QueryExpression < ModelElement
5
5
  include Identifier
6
6
 
7
- attr_accessor :aggregate_source
8
- attr_accessor :expression
7
+ model_attr_accessor :aggregate_source
8
+ model_attr_accessor :expression
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
  @aggregate_source = options[:aggregate_source]
@@ -19,9 +20,10 @@ module Expressir
19
20
  end
20
21
 
21
22
  def children
22
- items = []
23
- items.push(self)
24
- items
23
+ [
24
+ self,
25
+ *remark_items
26
+ ]
25
27
  end
26
28
  end
27
29
  end
@@ -2,7 +2,7 @@ module Expressir
2
2
  module Model
3
3
  module Expressions
4
4
  class SimpleReference < ModelElement
5
- attr_accessor :id
5
+ model_attr_accessor :id
6
6
 
7
7
  def initialize(options = {})
8
8
  @id = options[:id]
@@ -6,8 +6,8 @@ module Expressir
6
6
  NOT = :NOT
7
7
  PLUS = :PLUS
8
8
 
9
- attr_accessor :operator
10
- attr_accessor :operand
9
+ model_attr_accessor :operator
10
+ model_attr_accessor :operand
11
11
 
12
12
  def initialize(options = {})
13
13
  @operator = options[:operator]
@@ -3,20 +3,21 @@ module Expressir
3
3
  class Function < ModelElement
4
4
  include Identifier
5
5
 
6
- attr_accessor :parameters
7
- attr_accessor :return_type
8
- attr_accessor :types
9
- attr_accessor :entities
10
- attr_accessor :subtype_constraints
11
- attr_accessor :functions
12
- attr_accessor :procedures
13
- attr_accessor :constants
14
- attr_accessor :variables
15
- attr_accessor :statements
6
+ model_attr_accessor :parameters
7
+ model_attr_accessor :return_type
8
+ model_attr_accessor :types
9
+ model_attr_accessor :entities
10
+ model_attr_accessor :subtype_constraints
11
+ model_attr_accessor :functions
12
+ model_attr_accessor :procedures
13
+ model_attr_accessor :constants
14
+ model_attr_accessor :variables
15
+ model_attr_accessor :statements
16
16
 
17
17
  def initialize(options = {})
18
18
  @id = options[:id]
19
19
  @remarks = options.fetch(:remarks, [])
20
+ @remark_items = options.fetch(:remark_items, [])
20
21
  @source = options[:source]
21
22
 
22
23
  @parameters = options.fetch(:parameters, [])
@@ -33,18 +34,23 @@ module Expressir
33
34
  super
34
35
  end
35
36
 
37
+ def enumeration_items
38
+ types.flat_map{|x| x.enumeration_items}
39
+ end
40
+
36
41
  def children
37
- items = []
38
- items.push(*@parameters)
39
- items.push(*@types)
40
- items.push(*@types.flat_map{|x| x.type.is_a?(Types::Enumeration) ? x.type.items : []})
41
- items.push(*@entities)
42
- items.push(*@subtype_constraints)
43
- items.push(*@functions)
44
- items.push(*@procedures)
45
- items.push(*@constants)
46
- items.push(*@variables)
47
- items
42
+ [
43
+ *parameters,
44
+ *types,
45
+ *enumeration_items,
46
+ *entities,
47
+ *subtype_constraints,
48
+ *functions,
49
+ *procedures,
50
+ *constants,
51
+ *variables,
52
+ *remark_items
53
+ ]
48
54
  end
49
55
  end
50
56
  end
@@ -1,9 +1,12 @@
1
1
  module Expressir
2
2
  module Model
3
3
  module Identifier
4
- attr_accessor :id
5
- attr_accessor :remarks
6
- attr_accessor :source
4
+ def self.included(mod)
5
+ mod.model_attr_accessor :id
6
+ mod.model_attr_accessor :remarks
7
+ mod.model_attr_accessor :remark_items
8
+ mod.model_attr_accessor :source
9
+ end
7
10
  end
8
11
  end
9
12
  end
@@ -4,9 +4,9 @@ module Expressir
4
4
  USE = :USE
5
5
  REFERENCE = :REFERENCE
6
6
 
7
- attr_accessor :kind
8
- attr_accessor :schema
9
- attr_accessor :items
7
+ model_attr_accessor :kind
8
+ model_attr_accessor :schema
9
+ model_attr_accessor :items
10
10
 
11
11
  def initialize(options = {})
12
12
  @kind = options[:kind]
@@ -1,8 +1,8 @@
1
1
  module Expressir
2
2
  module Model
3
3
  class InterfaceItem < ModelElement
4
- attr_accessor :ref
5
- attr_accessor :id
4
+ model_attr_accessor :ref
5
+ model_attr_accessor :id
6
6
 
7
7
  def initialize(options = {})
8
8
  @ref = options[:ref]
@@ -1,14 +1,16 @@
1
1
  module Expressir
2
2
  module Model
3
3
  class InterfacedItem < ModelElement
4
- include Identifier
4
+ model_attr_accessor :id
5
+ model_attr_accessor :remarks
6
+ model_attr_accessor :remark_items
5
7
 
6
- attr_accessor :base_item
8
+ model_attr_accessor :base_item
7
9
 
8
10
  def initialize(options = {})
9
11
  @id = options[:id]
10
12
  @remarks = options.fetch(:remarks, [])
11
- @source = options[:source]
13
+ @remark_items = options.fetch(:remark_items, [])
12
14
 
13
15
  @base_item = options[:base_item]
14
16
 
@@ -18,6 +20,12 @@ module Expressir
18
20
  def path
19
21
  base_item.path
20
22
  end
23
+
24
+ def children
25
+ [
26
+ *remark_items
27
+ ]
28
+ end
21
29
  end
22
30
  end
23
31
  end
@@ -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
@@ -28,8 +31,8 @@ module Expressir
28
31
  end
29
32
 
30
33
  def attach_parent_to_children
31
- instance_variables.select{|x| x != :@parent}.each do |variable|
32
- value = instance_variable_get(variable)
34
+ self.class.model_attrs.each do |variable|
35
+ value = self.send(variable)
33
36
 
34
37
  if value.is_a? Array
35
38
  value.each do |value|
@@ -57,7 +60,7 @@ module Expressir
57
60
  # find in current scope
58
61
  current_node = current_scope
59
62
  path_parts.each do |current_path|
60
- current_node = current_node.children.find{|x| x.id and x.id.downcase == current_path}
63
+ current_node = current_node.children_by_id[current_path]
61
64
  break unless current_node
62
65
  end
63
66
  target_node = current_node
@@ -75,20 +78,29 @@ module Expressir
75
78
  []
76
79
  end
77
80
 
81
+ def children_by_id
82
+ @children_by_id ||= children.select{|x| x.id}.map{|x| [x.id.downcase, x]}.to_h
83
+ end
84
+
85
+ def reset_children_by_id
86
+ @children_by_id = nil
87
+ end
88
+
78
89
  def to_hash(options = {})
79
- skip_empty = options[:skip_empty]
90
+ root_path = options[:root_path]
80
91
  formatter = options[:formatter]
92
+ include_empty = options[:include_empty] || !options[:skip_empty] # TODO: remove skip_empty
81
93
 
82
94
  hash = {}
83
95
  hash[CLASS_KEY] = self.class.name
84
96
 
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)
97
+ self.class.model_attrs.each do |variable|
98
+ value = self.send(variable)
99
+ empty = value.nil? || (value.is_a?(Array) && value.count == 0)
88
100
 
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
101
+ # skip empty values
102
+ if !empty or include_empty
103
+ hash[variable.to_s] = if value.is_a? Array
92
104
  value.map do |value|
93
105
  if value.is_a? ModelElement
94
106
  value.to_hash(options)
@@ -104,37 +116,60 @@ module Expressir
104
116
  end
105
117
  end
106
118
 
107
- if formatter
119
+ if self.is_a? Schema and file
120
+ hash[FILE_KEY] = root_path ? Pathname.new(file).relative_path_from(root_path).to_s : file
121
+ end
122
+
123
+ if self.class.method_defined? :source and formatter
108
124
  hash[SOURCE_KEY] = formatter.format(self)
109
125
  end
110
126
 
111
127
  hash
112
128
  end
113
129
 
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
130
+ def self.from_hash(hash, options = {})
131
+ root_path = options[:root_path]
132
+
133
+ node_class = Object.const_get(hash[CLASS_KEY])
134
+ node_options = {}
118
135
 
119
- result[key] = if value.is_a? Array
136
+ node_class.model_attrs.each do |variable|
137
+ value = hash[variable.to_s]
138
+
139
+ node_options[variable] = if value.is_a? Array
120
140
  value.map do |value|
121
141
  if value.is_a? Hash
122
- self.from_hash(value)
142
+ self.from_hash(value, options)
123
143
  else
124
144
  value
125
145
  end
126
146
  end
127
147
  elsif value.is_a? Hash
128
- self.from_hash(value)
148
+ self.from_hash(value, options)
129
149
  else
130
150
  value
131
151
  end
132
152
  end
133
153
 
134
- node = Object.const_get(node_class).new(node_options)
154
+ if node_class == Schema and hash[FILE_KEY]
155
+ node_options[FILE_KEY.to_sym] = root_path ? File.expand_path("#{root_path}/#{hash[FILE_KEY]}") : hash[FILE_KEY]
156
+ end
157
+
158
+ node = node_class.new(node_options)
135
159
 
136
160
  node
137
161
  end
162
+
163
+ def self.model_attrs
164
+ @model_attrs ||= []
165
+ end
166
+
167
+ def self.model_attr_accessor(*vars)
168
+ @model_attrs ||= []
169
+ @model_attrs.concat(vars)
170
+
171
+ attr_accessor *vars
172
+ end
138
173
  end
139
174
  end
140
175
  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