expressir 2.5.1-x86_64-linux → 2.5.3-x86_64-linux

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.
@@ -0,0 +1,144 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Expressir
4
+ module Express
5
+ # The eengine `--cleanup_parens` rewrite (eengine parity):
6
+ # kernel/cleanup-parens.lisp. Scope — the where rules of each
7
+ # entity (the eengine walk touches nothing else). The parse
8
+ # collapses nested paren layers onto one `parenthesized` counter,
9
+ # and the rules below reproduce the eengine paren-node walk
10
+ # exactly:
11
+ #
12
+ # - A parenthesized expression keeps exactly ONE paren layer when
13
+ # its operator is relational (`=`, `<>`, `<`, `<=`, `>`, `>=`,
14
+ # `IN`, `==`, `:<>:`) or a boolean connective (`AND`, `ANDOR`,
15
+ # `OR`, `XOR`); every other parenthesized expression unwraps
16
+ # fully.
17
+ # - The operands of `AND` / `ANDOR` / `OR` / `XOR` keep their
18
+ # parens: a parenthesized grouping operand collapses to one
19
+ # layer (the eengine list rule preserves the operand's outer
20
+ # paren and only cleans inside it).
21
+ # - The outermost parens of a where-rule expression and of a
22
+ # `QUERY` body strip unconditionally (the eengine rule-domain
23
+ # and query rules).
24
+ class CleanupParens
25
+ KEEP_OPS = [
26
+ Model::Expressions::BinaryExpression::EQUAL,
27
+ Model::Expressions::BinaryExpression::NOT_EQUAL,
28
+ Model::Expressions::BinaryExpression::LESS_THAN,
29
+ Model::Expressions::BinaryExpression::LESS_THAN_OR_EQUAL,
30
+ Model::Expressions::BinaryExpression::GREATER_THAN,
31
+ Model::Expressions::BinaryExpression::GREATER_THAN_OR_EQUAL,
32
+ Model::Expressions::BinaryExpression::IN,
33
+ Model::Expressions::BinaryExpression::INSTANCE_EQUAL,
34
+ Model::Expressions::BinaryExpression::INSTANCE_NOT_EQUAL,
35
+ Model::Expressions::BinaryExpression::AND,
36
+ Model::Expressions::BinaryExpression::OR,
37
+ Model::Expressions::BinaryExpression::XOR,
38
+ Model::SupertypeExpressions::BinarySupertypeExpression::ANDOR,
39
+ ].freeze
40
+
41
+ GROUPING_OPS = [
42
+ Model::Expressions::BinaryExpression::AND,
43
+ Model::Expressions::BinaryExpression::OR,
44
+ Model::Expressions::BinaryExpression::XOR,
45
+ Model::SupertypeExpressions::BinarySupertypeExpression::ANDOR,
46
+ ].freeze
47
+
48
+ # Applies the rewrite to every entity where rule of the schema.
49
+ def self.call(schema)
50
+ new.call(schema)
51
+ end
52
+
53
+ def call(schema)
54
+ Array(schema.entities).each do |entity|
55
+ Array(entity.where_rules).each do |where|
56
+ where.expression = cleanup(where.expression)
57
+ minimize(where.expression)
58
+ strip_one(where.expression)
59
+ end
60
+ end
61
+ schema
62
+ end
63
+
64
+ def cleanup(node)
65
+ return node unless node.is_a?(Model::ModelElement)
66
+
67
+ case node
68
+ when Model::Expressions::BinaryExpression,
69
+ Model::SupertypeExpressions::BinarySupertypeExpression
70
+ node.operand1 = cleanup(node.operand1)
71
+ node.operand2 = cleanup(node.operand2)
72
+ if GROUPING_OPS.include?(node.operator)
73
+ collapse_grouping_operand(node.operand1)
74
+ collapse_grouping_operand(node.operand2)
75
+ else
76
+ minimize(node.operand1)
77
+ minimize(node.operand2)
78
+ end
79
+ when Model::Expressions::QueryExpression
80
+ node.aggregate_source = cleanup(node.aggregate_source)
81
+ minimize(node.aggregate_source)
82
+ node.expression = cleanup(node.expression)
83
+ minimize(node.expression)
84
+ strip_one(node.expression)
85
+ else
86
+ expression_children(node).each do |child|
87
+ cleaned = cleanup(child)
88
+ minimize(cleaned)
89
+ end
90
+ end
91
+ node
92
+ end
93
+
94
+ private
95
+
96
+ # The paren budget: keep exactly one layer for keep-ops, none
97
+ # otherwise.
98
+ def minimize(node)
99
+ return unless node.is_a?(Model::ModelElement)
100
+
101
+ node.parenthesized = if node.parenthesized.to_i.positive? && keep?(node)
102
+ 1
103
+ else
104
+ 0
105
+ end
106
+ end
107
+
108
+ # A grouping operand's outer paren stays; deeper layers collapse
109
+ # per the normal budget (eengine cleans inside the operand's
110
+ # paren node).
111
+ def collapse_grouping_operand(node)
112
+ return unless node.is_a?(Model::ModelElement)
113
+ return unless node.parenthesized.to_i.positive?
114
+
115
+ node.parenthesized = 1
116
+ end
117
+
118
+ def strip_one(node)
119
+ return unless node.is_a?(Model::ModelElement)
120
+ return unless node.parenthesized.to_i.positive?
121
+
122
+ node.parenthesized -= 1
123
+ end
124
+
125
+ def keep?(node)
126
+ (node.is_a?(Model::Expressions::BinaryExpression) ||
127
+ node.is_a?(Model::SupertypeExpressions::BinarySupertypeExpression)) &&
128
+ KEEP_OPS.include?(node.operator)
129
+ end
130
+
131
+ # Every ModelElement-valued attribute of the node — the generic
132
+ # expression descent.
133
+ def expression_children(node)
134
+ node.class.attributes.filter_map do |(attr_name, _attr)|
135
+ value = node.public_send(attr_name)
136
+ case value
137
+ when Model::ModelElement then value
138
+ when Array then value.grep(Model::ModelElement)
139
+ end
140
+ end.flatten
141
+ end
142
+ end
143
+ end
144
+ end
@@ -290,6 +290,18 @@ module Expressir
290
290
  JSON.parse(::Expressir::Core.parse_population_recovering(source))
291
291
  end
292
292
 
293
+ # The eengine-style per-instance cross-reference report
294
+ # (eengine `--xref` parity): the report text over an EXPRESS
295
+ # schema and a Part 21 population. Rust-only — the report is
296
+ # the native op's output verbatim.
297
+ def self.xref(schema_source, population_source)
298
+ unless NATIVE_AVAILABLE && ::Expressir::Core.respond_to?(:xref)
299
+ raise NotImplementedError, "core xref unavailable"
300
+ end
301
+
302
+ ::Expressir::Core.xref(schema_source, population_source)
303
+ end
304
+
293
305
  # The SHTOLO longform over a resolved repository (#636): the
294
306
  # full stage order runs in Rust over the repository's flat wire.
295
307
  # Returns the longform schema's wire JSON string.
@@ -0,0 +1,135 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Expressir
4
+ module Express
5
+ # Population GraphViz emitter — port of eeng
6
+ # kernel/dot-graph.lisp `:data` graph: entity nodes (red
7
+ # ellipses), instance nodes (magenta boxes, complex instances as
8
+ # magenta subgraph clusters), entity→instance edges (red) and
9
+ # used-in edges (blue).
10
+ class DataDot
11
+ def initialize(population, name: "population")
12
+ @population = population
13
+ @name = name.tr(" ", "-")
14
+ end
15
+
16
+ def write(io = nil)
17
+ owned = io.nil?
18
+ io ||= +""
19
+
20
+ entities = {}
21
+ @population.instances.each_value do |record|
22
+ each_keyword(record) do |keyword|
23
+ lower = keyword.downcase
24
+ entities[lower] ||= keyword
25
+ end
26
+ end
27
+
28
+ io << "// -*- Mode: Dot -*-\n\n"
29
+ io << "//\n// Stats go here\n//\n\n"
30
+ io << "digraph #{@name} {\n"
31
+ io << "//\n// ENTITY Nodes\n//\n"
32
+ entities.each do |lower, keyword|
33
+ io << "e_#{lower} [label=\"#{keyword}\",shape=ellipse,color=red];\n"
34
+ end
35
+ io << "\n"
36
+ io << "//\n// Instance Nodes\n//\n"
37
+ instance_nodes(io)
38
+ io << "\n"
39
+ io << "//\n// Edges\n//\n\n"
40
+ instance_edges(io)
41
+ io << "}\n"
42
+ owned ? io : nil
43
+ end
44
+
45
+ private
46
+
47
+ def each_keyword(record, &)
48
+ case record
49
+ when P21::ComplexRecord
50
+ record.records.each { |part| yield(part.keyword) }
51
+ when P21::Record
52
+ yield(record.keyword)
53
+ end
54
+ end
55
+
56
+ # Instance keys arrive "#id"; the dot node ids use the bare id.
57
+ def instance_nodes(io)
58
+ @population.instances.each do |key, record|
59
+ id = key.to_s.delete_prefix("#")
60
+ case record
61
+ when P21::ComplexRecord
62
+ io << "subgraph cluster_#{id} {\n"
63
+ io << " color=magenta;\n"
64
+ io << " label=\"##{id}\";\n"
65
+ record.records.each_with_index do |part, index|
66
+ io << " e#{id}p#{index + 1} [label=\"#{part.keyword}\",shape=box];\n"
67
+ end
68
+ io << "}\n"
69
+ when P21::Record
70
+ io << "i#{id} [label=\"##{id}\",shape=box,color=magenta];\n"
71
+ end
72
+ end
73
+ end
74
+
75
+ def instance_edges(io)
76
+ used_in = build_used_in
77
+ @population.instances.each do |key, record|
78
+ id = key.to_s.delete_prefix("#")
79
+ case record
80
+ when P21::ComplexRecord
81
+ record.records.each do |part|
82
+ io << "e_#{part.keyword.downcase} -> cluster_#{id} [color=red];"
83
+ end
84
+ Array(used_in[key.to_s.delete_prefix("#").to_i]).each do |user|
85
+ io << "i#{user} -> cluster_#{id} [color=blue];"
86
+ end
87
+ when P21::Record
88
+ io << "e_#{record.keyword.downcase} -> i#{id} [color=red];\n"
89
+ Array(used_in[key.to_s.delete_prefix("#").to_i]).each do |user|
90
+ io << "i#{user} -> i#{id} [arrowhead=dot,color=blue];\n"
91
+ end
92
+ io << "\n"
93
+ end
94
+ end
95
+ end
96
+
97
+ # Every instance that references the target id, in instance
98
+ # order (the runtime's pushnew: one entry per referencing
99
+ # instance).
100
+ def build_used_in
101
+ used_in = Hash.new { |h, k| h[k] = [] }
102
+ @population.instances.each do |key, record|
103
+ user = key.to_s.delete_prefix("#").to_i
104
+ collect_refs(record).each do |target|
105
+ used_in[target] << user unless used_in[target].include?(user)
106
+ end
107
+ end
108
+ used_in
109
+ end
110
+
111
+ def collect_refs(record)
112
+ refs = []
113
+ walk = lambda do |value|
114
+ case value
115
+ when Array then value.each { |v| walk.call(v) }
116
+ when P21::TypedValue then walk.call(value.value)
117
+ when String
118
+ id = value[/\A#(\d+)\z/, 1]
119
+ refs << id.to_i if id
120
+ end
121
+ end
122
+ record_params(record).each { |param| walk.call(param) }
123
+ refs
124
+ end
125
+
126
+ def record_params(record)
127
+ case record
128
+ when P21::ComplexRecord then record.records.flat_map(&:params)
129
+ when P21::Record then record.params
130
+ else []
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Expressir
4
+ module Express
5
+ # eengine dot-graph.lisp naming conventions: node ids carry a
6
+ # declaration-kind prefix (c_/e_/f_/p_/r_/sc_/t_/te_/ts_/s_),
7
+ # lowercased; type labels carry the declaration kind.
8
+ module DotNames
9
+ module_function
10
+
11
+ # The prefixed node id for a declaration.
12
+ def name_for(obj)
13
+ case obj
14
+ when Model::Declarations::Constant then "c_#{obj.id.downcase}"
15
+ when Model::Declarations::Entity then "e_#{obj.id.downcase}"
16
+ when Model::Declarations::Function then "f_#{obj.id.downcase}"
17
+ when Model::Declarations::Procedure then "p_#{obj.id.downcase}"
18
+ when Model::Declarations::Rule then "r_#{obj.id.downcase}"
19
+ when Model::Declarations::Schema then "s_#{obj.id.downcase}"
20
+ when Model::Declarations::SubtypeConstraint then "sc_#{obj.id.downcase}"
21
+ when Model::Declarations::Type then type_name(obj)
22
+ end
23
+ end
24
+
25
+ def type_name(type)
26
+ prefix = type_prefix(type)
27
+ "#{prefix}#{type.id.downcase}"
28
+ end
29
+
30
+ def type_prefix(type)
31
+ case type.underlying_type
32
+ when Model::DataTypes::Enumeration then "te_"
33
+ when Model::DataTypes::Select then "ts_"
34
+ else "t_"
35
+ end
36
+ end
37
+
38
+ # The node label for a declaration.
39
+ def label_for(obj)
40
+ case obj
41
+ when Model::Declarations::Entity then obj.id
42
+ when Model::Declarations::Type then type_label(obj)
43
+ else "#{obj.class.name.split('::').last}\\n#{name_for(obj)}"
44
+ end
45
+ end
46
+
47
+ def type_label(type)
48
+ case type.underlying_type
49
+ when Model::DataTypes::Enumeration then "TYPE ENUMERATION\\n#{type.id.downcase}"
50
+ when Model::DataTypes::Select then "TYPE SELECT\\n#{type.id.downcase}"
51
+ else "TYPE\\n#{type.id.downcase}"
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,291 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Expressir
4
+ module Express
5
+ # Entity-path GraphViz emitter — port of eeng
6
+ # kernel/dot-graph.lisp `:path` graph: consecutive entity names
7
+ # connected by attribute references (direct or through
8
+ # aggregates), supertype/subtype relations, and SELECT-type
9
+ # chains. Boxes are entities; ovals are SELECT types.
10
+ class PathDot
11
+ def initialize(schema, entity_names, repository,
12
+ sub_color: nil, super_color: nil,
13
+ attribute_color: nil, select_color: nil)
14
+ @schema = schema
15
+ @names = entity_names
16
+ @repository = repository
17
+ @sub_color = sub_color
18
+ @super_color = super_color
19
+ @attribute_color = attribute_color
20
+ @select_color = select_color
21
+
22
+ locals = (Array(schema.entities) + Array(schema.types))
23
+ globals = repository.schemas.flat_map { |s| Array(s.entities) + Array(s.types) }
24
+ @by_name = (globals + locals).to_h { |d| [d.id.downcase, d] }
25
+ @owner_of = repository.schemas.flat_map do |s|
26
+ (Array(s.entities) + Array(s.types)).map { |d| [d, s.id.downcase] }
27
+ end.to_h
28
+ end
29
+
30
+ # Returns [nodes, paths]: nodes is a list of resolved
31
+ # declarations (eengine's push order — the requested names
32
+ # reversed, discovered select types prepended), paths a list of
33
+ # [link, from, to] where link is an attribute name (String),
34
+ # :super, :sub, or :select.
35
+ def collect
36
+ nodes = []
37
+ seen = {}.compare_by_identity
38
+ @names.each do |name|
39
+ decl = @by_name[name.downcase]
40
+ next unless decl && !seen.key?(decl)
41
+
42
+ # eengine pushes each resolved declaration onto the front.
43
+ nodes.unshift(decl)
44
+ seen[decl] = true
45
+ end
46
+ edges = paths
47
+ # Attribute paths through SELECT chains pushnew the discovered
48
+ # select types into the node set (eengine's node walk).
49
+ edges.each do |link, from, to|
50
+ next unless link.is_a?(String)
51
+
52
+ nodes.unshift(from) unless seen.key?(from)
53
+ seen[from] = true
54
+ Array(to).each do |node|
55
+ next unless node.is_a?(Model::ModelElement)
56
+
57
+ unless seen.key?(node)
58
+ nodes.unshift(node)
59
+ seen[node] = true
60
+ end
61
+ end
62
+ end
63
+ [nodes, edges]
64
+ end
65
+
66
+ def write(io = nil)
67
+ owned = io.nil?
68
+ io ||= +""
69
+
70
+ nodes, edges = collect
71
+ first = nodes.first
72
+
73
+ io << "// -*- Mode: Dot -*-\n\n\n"
74
+ io << "// eengine --dot -graph path ...\n\n"
75
+ io << "// Entity:\n"
76
+ @names.each { |name| io << "// \"#{name}\"\n" }
77
+ io << "// \n\n"
78
+ io << "// Nodes:\n"
79
+ nodes.each { |node| io << "// #{node.id.downcase}\n" }
80
+ io << "// \n\n"
81
+ io << "// Paths:\n"
82
+ edges.each do |link, from, to|
83
+ io << "// #{link_label(link)} #{from.id.downcase} #{to.id.downcase}\n"
84
+ end
85
+ io << "// \n\n"
86
+
87
+ clusters = Hash.new { |h, k| h[k] = [] }
88
+ # eengine pushnews nodes into their schema bucket — prepend.
89
+ nodes.each { |node| clusters[@owner_of[node] || ""].unshift(node) }
90
+
91
+ io << "digraph #{first.id.downcase}_path {\n"
92
+ clusters.each do |schema_name, cluster_nodes|
93
+ io << " subgraph cluster_#{schema_name} {\n"
94
+ io << " style=rounded;\n"
95
+ io << " label=#{schema_name};\n"
96
+ cluster_nodes.each do |node|
97
+ case node
98
+ when Model::Declarations::Entity
99
+ io << " #{node.id.downcase} [shape=box,style=rounded];\n"
100
+ when Model::Declarations::Type
101
+ color = @select_color ? ",color=#{@select_color}" : ""
102
+ io << " #{node.id.downcase} [shape=oval#{color}];\n"
103
+ end
104
+ end
105
+ io << " }\n"
106
+ end
107
+
108
+ edges.each do |link, from, to|
109
+ f = from.id.downcase
110
+ t = to.id.downcase
111
+ case link
112
+ when :sub
113
+ color = @sub_color ? ",color=#{@sub_color}" : ""
114
+ io << "\n #{f} -> #{t} [label=\"sub\"#{color}];\n"
115
+ when :super
116
+ color = @super_color ? ",color=#{@super_color}" : ""
117
+ io << "\n #{f} -> #{t} [label=\"super\"#{color}];\n"
118
+ when :select
119
+ io << " #{f} -> #{t}\n"
120
+ else
121
+ color = @attribute_color ? ",color=#{@attribute_color}" : ""
122
+ io << "\n #{f} -> #{t} [label=\"#{link}\"#{color}];\n"
123
+ end
124
+ end
125
+ io << "}\n"
126
+ owned ? io : nil
127
+ end
128
+
129
+ private
130
+
131
+ # eengine's connect-nodes: the first relation found wins —
132
+ # direct attribute, reverse direct, aggregate element (either
133
+ # direction), supertype, subtype, then SELECT chains.
134
+ def connect(node1, node2)
135
+ attrs1 = entity_attrs(node1)
136
+ attrs2 = entity_attrs(node2)
137
+
138
+ attrs1.each do |attr|
139
+ base = plain_base_type(attr)
140
+ next unless base&.downcase == node2.id.downcase
141
+
142
+ return [[attr.id.downcase, node1, node2]]
143
+ end
144
+ attrs2.each do |attr|
145
+ base = plain_base_type(attr)
146
+ next unless base&.downcase == node1.id.downcase
147
+
148
+ return [[attr.id.downcase, node2, node1]]
149
+ end
150
+ attrs1.each do |attr|
151
+ base = aggregate_base_type(attr)
152
+ next unless base&.downcase == node2.id.downcase
153
+
154
+ return [["#{attr.id.downcase}[i]", node1, node2]]
155
+ end
156
+ attrs2.each do |attr|
157
+ base = aggregate_base_type(attr)
158
+ next unless base&.downcase == node1.id.downcase
159
+
160
+ return [["#{attr.id.downcase}[i]", node2, node1]]
161
+ end
162
+
163
+ if supers_of(node1).any? { |n| n.downcase == node2.id.downcase }
164
+ return [[:super, node1, node2]]
165
+ end
166
+ if supers_of(node2).any? { |n| n.downcase == node1.id.downcase }
167
+ return [[:sub, node1, node2]]
168
+ end
169
+
170
+ select_paths(node1, node2) + select_paths(node2, node1)
171
+ end
172
+
173
+ def supers_of(entity)
174
+ Array(entity.subtype_of).map do |ref|
175
+ ref.is_a?(Model::References::SimpleReference) ? ref.id : ref.to_s
176
+ end
177
+ end
178
+
179
+ # The Paths comment prints links the Lisp way (:super, :sub,
180
+ # :select); attribute links print bare.
181
+ def link_label(link)
182
+ link.is_a?(Symbol) ? ":#{link}" : link
183
+ end
184
+
185
+ def entity_attrs(entity)
186
+ Array(entity.attributes) + Array(entity.derived_attributes) +
187
+ Array(entity.inverse_attributes)
188
+ end
189
+
190
+ def plain_base_type(attr)
191
+ type = attr.type
192
+ type.is_a?(Model::References::SimpleReference) ? type.id : nil
193
+ end
194
+
195
+ def aggregate_base_type(attr)
196
+ type = attr.type
197
+ return unless type.respond_to?(:base_type)
198
+
199
+ base = type.base_type
200
+ base.is_a?(Model::References::SimpleReference) ? base.id : nil
201
+ end
202
+
203
+ # eengine's chase-selects: the shortest chain of SELECT types
204
+ # from an attribute's select type down to the target.
205
+ def chase_selects(target, types, seen = {}.compare_by_identity)
206
+ paths = []
207
+ types.each do |type|
208
+ next if seen.key?(type)
209
+ next unless type.is_a?(Model::Declarations::Type)
210
+
211
+ select = type.underlying_type
212
+ next unless select.is_a?(Model::DataTypes::Select)
213
+
214
+ members = Array(select.items).filter_map do |item|
215
+ item.is_a?(Model::References::SimpleReference) ? @by_name[item.id.downcase] : item
216
+ end
217
+ if members.any? { |m| m.id.downcase == target.id.downcase }
218
+ return [[:select, type, target]]
219
+ end
220
+
221
+ next_level = members.select do |m|
222
+ m.is_a?(Model::Declarations::Type) &&
223
+ m.underlying_type.is_a?(Model::DataTypes::Select)
224
+ end
225
+ chase_selects(target, next_level, seen.merge(type => true)).each do |path|
226
+ paths << [:select, type, *path.drop(1)]
227
+ end
228
+ end
229
+ paths
230
+ end
231
+
232
+ def select_paths(node1, node2)
233
+ paths = []
234
+ entity_attrs(node1).each do |attr|
235
+ attr_name = attr.id.downcase
236
+ base = select_type_of(attr)
237
+ next unless base
238
+
239
+ chase_selects(node2, [base]).each do |path|
240
+ paths << [attr_name, node1, path]
241
+ end
242
+ end
243
+ paths
244
+ end
245
+
246
+ # The attribute's referenced Type declaration when it selects.
247
+ def select_type_of(attr)
248
+ type = attr.type
249
+ base = nil
250
+ if type.is_a?(Model::References::SimpleReference)
251
+ base = type.id
252
+ elsif type.respond_to?(:base_type) &&
253
+ type.base_type.is_a?(Model::References::SimpleReference)
254
+ base = type.base_type.id
255
+ end
256
+ return nil unless base
257
+
258
+ decl = @by_name[base.downcase]
259
+ return nil unless decl.is_a?(Model::Declarations::Type)
260
+
261
+ decl if decl.underlying_type.is_a?(Model::DataTypes::Select)
262
+ end
263
+
264
+ def paths
265
+ resolved = @names.filter_map { |name| @by_name[name.downcase] }
266
+ out = []
267
+ resolved.each_cons(2) do |a, b|
268
+ found = connect(a, b)
269
+ out.concat(found)
270
+ end
271
+ expand_selects(out)
272
+ end
273
+
274
+ # Attribute paths whose third element is a (:select ...) chain
275
+ # split into the attribute edge plus :select edges per hop.
276
+ def expand_selects(paths)
277
+ out = []
278
+ paths.each do |link, from, to|
279
+ if to.is_a?(Array) && to.first == :select
280
+ chain = to.drop(1)
281
+ out << [link, from, chain.first]
282
+ chain.each_cons(2) { |a, b| out << [:select, a, b] }
283
+ else
284
+ out << [link, from, to]
285
+ end
286
+ end
287
+ out
288
+ end
289
+ end
290
+ end
291
+ end