expressir 2.5.1-arm-linux → 2.5.3-arm-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.
- checksums.yaml +4 -4
- data/ENGINE-COMPAT.json +3 -3
- data/lib/expressir/3.2/expressir_core.so +0 -0
- data/lib/expressir/3.3/expressir_core.so +0 -0
- data/lib/expressir/3.4/expressir_core.so +0 -0
- data/lib/expressir/4.0/expressir_core.so +0 -0
- data/lib/expressir/cli.rb +27 -0
- data/lib/expressir/commands/cleanup_parens.rb +25 -0
- data/lib/expressir/commands/compare/report_building.rb +131 -0
- data/lib/expressir/commands/compare.rb +62 -124
- data/lib/expressir/commands/compare_arm_mim.rb +52 -0
- data/lib/expressir/commands/flatten.rb +2 -1
- data/lib/expressir/commands/patch.rb +33 -0
- data/lib/expressir/commands.rb +3 -0
- data/lib/expressir/express/cleanup_parens.rb +144 -0
- data/lib/expressir/express/core.rb +12 -0
- data/lib/expressir/express/dot/data_dot.rb +135 -0
- data/lib/expressir/express/dot/names.rb +56 -0
- data/lib/expressir/express/dot/path_dot.rb +291 -0
- data/lib/expressir/express/dot/schema_dot.rb +102 -0
- data/lib/expressir/express/dot/supertype_dot.rb +79 -0
- data/lib/expressir/express/parser.rb +7 -2
- data/lib/expressir/express/patch_schema.rb +298 -0
- data/lib/expressir/express/shtolo.rb +83 -6
- data/lib/expressir/express.rb +7 -0
- data/lib/expressir/version.rb +1 -1
- metadata +13 -2
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Expressir
|
|
4
|
+
module Express
|
|
5
|
+
# Schema-inventory GraphViz emitter — port of eeng
|
|
6
|
+
# kernel/dot-graph.lisp `:schema` graph. One node per declaration
|
|
7
|
+
# (types blue, entities red, subtype constraints/functions black,
|
|
8
|
+
# rules cyan, procedures magenta), dotted red supertype edges and
|
|
9
|
+
# solid blue SELECT-reference edges.
|
|
10
|
+
class SchemaDot
|
|
11
|
+
def initialize(schema)
|
|
12
|
+
@schema = schema
|
|
13
|
+
@by_name = (schema.entities + schema.types + schema.constants)
|
|
14
|
+
.to_h { |d| [d.id.downcase, d] }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def write(io = nil)
|
|
18
|
+
owned = io.nil?
|
|
19
|
+
io ||= +""
|
|
20
|
+
name = @schema.id.downcase
|
|
21
|
+
|
|
22
|
+
io << "// -*- Mode: Dot -*-\n\n"
|
|
23
|
+
io << "// Schema: #{name}\n"
|
|
24
|
+
io << "// Interfaces: #{Array(@schema.interfaces).length}\n"
|
|
25
|
+
io << "// Constants: #{Array(@schema.constants).length}\n"
|
|
26
|
+
io << "// Entities: #{Array(@schema.entities).length}\n"
|
|
27
|
+
io << "// Functions: #{Array(@schema.functions).length}\n"
|
|
28
|
+
io << "// Procedures: #{Array(@schema.procedures).length}\n"
|
|
29
|
+
io << "// Rules: #{Array(@schema.rules).length}\n"
|
|
30
|
+
io << "// Subtype_Constraint: #{Array(@schema.subtype_constraints).length}\n"
|
|
31
|
+
io << "// Type: #{Array(@schema.types).length}\n"
|
|
32
|
+
io << "\n"
|
|
33
|
+
io << "digraph #{name} {\n"
|
|
34
|
+
io << " rankdir=LR;\n\n"
|
|
35
|
+
|
|
36
|
+
declaration_groups.each do |decls, color|
|
|
37
|
+
next if decls.empty?
|
|
38
|
+
|
|
39
|
+
io << "//\n// #{group_heading(decls.first)}\n//\n"
|
|
40
|
+
io << "node [shape=rectangle,color=#{color}];\n"
|
|
41
|
+
decls.each do |decl|
|
|
42
|
+
io << "#{DotNames.name_for(decl)} [label=\"#{DotNames.label_for(decl)}\"]\n"
|
|
43
|
+
end
|
|
44
|
+
io << "\n"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
io << "//\n// SUPERTYPE Edges\n//\n"
|
|
48
|
+
io << "edge [color=red,label=\"subtype\",style=dotted];\n"
|
|
49
|
+
Array(@schema.entities).each do |entity|
|
|
50
|
+
Array(entity.subtype_of).each do |ref|
|
|
51
|
+
sup = ref.is_a?(Model::References::SimpleReference) ? ref.id : ref.to_s
|
|
52
|
+
io << "e_#{sup.downcase} -> e_#{entity.id.downcase};\n"
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
io << "\n"
|
|
56
|
+
|
|
57
|
+
io << "//\n// SELECT TYPE Reference Edges\n//\n"
|
|
58
|
+
io << "edge [color=blue,label=\"\",style=solid];\n"
|
|
59
|
+
Array(@schema.types).each do |type|
|
|
60
|
+
next unless type.underlying_type.is_a?(Model::DataTypes::Select)
|
|
61
|
+
|
|
62
|
+
Array(type.underlying_type.items).each do |item|
|
|
63
|
+
target = item.is_a?(Model::References::SimpleReference) ? item.id : item.to_s
|
|
64
|
+
node = @by_name[target.downcase]
|
|
65
|
+
target_name = node ? DotNames.name_for(node) : target.downcase
|
|
66
|
+
io << "#{DotNames.type_name(type)} -> #{target_name};\n"
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
io << "\n"
|
|
70
|
+
|
|
71
|
+
io << "}\n"
|
|
72
|
+
owned ? io : nil
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
private
|
|
76
|
+
|
|
77
|
+
# eengine's declaration grouping order: types, entities,
|
|
78
|
+
# subtype constraints, functions, rules, procedures.
|
|
79
|
+
def declaration_groups
|
|
80
|
+
[
|
|
81
|
+
[Array(@schema.types), "blue"],
|
|
82
|
+
[Array(@schema.entities), "red"],
|
|
83
|
+
[Array(@schema.subtype_constraints), "black"],
|
|
84
|
+
[Array(@schema.functions), "black"],
|
|
85
|
+
[Array(@schema.rules), "cyan"],
|
|
86
|
+
[Array(@schema.procedures), "magenta"],
|
|
87
|
+
]
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def group_heading(decl)
|
|
91
|
+
case decl
|
|
92
|
+
when Model::Declarations::Type then "TYPE"
|
|
93
|
+
when Model::Declarations::Entity then "ENTITY"
|
|
94
|
+
when Model::Declarations::SubtypeConstraint then "SUBTYPE_CONSTRAINT"
|
|
95
|
+
when Model::Declarations::Function then "FUNCTION"
|
|
96
|
+
when Model::Declarations::Rule then "RULE"
|
|
97
|
+
when Model::Declarations::Procedure then "PROCEDURE"
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Expressir
|
|
4
|
+
module Express
|
|
5
|
+
# Supertype-tree GraphViz emitter — port of eeng
|
|
6
|
+
# kernel/dot-graph.lisp `:supertype` graph: the supertree of one
|
|
7
|
+
# entity, boxed nodes clustered per schema, edges from supertype
|
|
8
|
+
# to subtype with `arrowhead=odot,penwidth=2.0`.
|
|
9
|
+
class SupertypeDot
|
|
10
|
+
def initialize(entity, repository)
|
|
11
|
+
@entity = entity
|
|
12
|
+
@entities = repository.schemas.flat_map { |s| Array(s.entities) }
|
|
13
|
+
.to_h { |e| [e.id.downcase, e] }
|
|
14
|
+
@owner_of = repository.schemas.flat_map do |schema|
|
|
15
|
+
Array(schema.entities).map { |e| [e, schema.id.downcase] }
|
|
16
|
+
end.to_h
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def write(io = nil)
|
|
20
|
+
owned = io.nil?
|
|
21
|
+
io ||= +""
|
|
22
|
+
|
|
23
|
+
edges = supertree(@entity, {})
|
|
24
|
+
ids = {}
|
|
25
|
+
count = 0
|
|
26
|
+
edges.each do |super_ent, sub_ent|
|
|
27
|
+
[super_ent, sub_ent].each do |node|
|
|
28
|
+
key = node.id.downcase
|
|
29
|
+
unless ids.key?(key)
|
|
30
|
+
count += 1
|
|
31
|
+
ids[key] = "node#{count}"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
by_schema = Hash.new { |h, k| h[k] = [] }
|
|
37
|
+
ids.each_key do |key|
|
|
38
|
+
entity = @entities[key]
|
|
39
|
+
by_schema[@owner_of[entity] || ""] << entity
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
io << "digraph #{@entity.id.downcase} {\n"
|
|
43
|
+
io << " node [shape=box];\n"
|
|
44
|
+
io << " edge [arrowhead=odot,penwidth=2.0];\n"
|
|
45
|
+
io << "\n"
|
|
46
|
+
by_schema.each do |schema_name, entities|
|
|
47
|
+
io << " subgraph cluster_#{schema_name} {\n"
|
|
48
|
+
io << " label=\"#{schema_name}\";\n"
|
|
49
|
+
entities.each do |entity|
|
|
50
|
+
io << " #{ids[entity.id.downcase]} [label=\"#{entity.id.downcase}\"];\n"
|
|
51
|
+
end
|
|
52
|
+
io << " }\n"
|
|
53
|
+
end
|
|
54
|
+
edges.each do |super_ent, sub_ent|
|
|
55
|
+
io << " #{ids[super_ent.id.downcase]} -> #{ids[sub_ent.id.downcase]};\n"
|
|
56
|
+
end
|
|
57
|
+
io << "}\n"
|
|
58
|
+
owned ? io : nil
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
private
|
|
62
|
+
|
|
63
|
+
# The edges from the entity up through every supertype, deepest
|
|
64
|
+
# chain first (eengine's supertree loop: recurse, then collect).
|
|
65
|
+
def supertree(entity, seen)
|
|
66
|
+
return [] if entity.nil? || seen.key?(entity.id.downcase)
|
|
67
|
+
|
|
68
|
+
seen[entity.id.downcase] = true
|
|
69
|
+
Array(entity.subtype_of).flat_map do |ref|
|
|
70
|
+
sup_name = ref.is_a?(Model::References::SimpleReference) ? ref.id : ref.to_s
|
|
71
|
+
sup = @entities[sup_name.downcase]
|
|
72
|
+
next [] unless sup
|
|
73
|
+
|
|
74
|
+
supertree(sup, seen) + [[sup, entity]]
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -283,8 +283,13 @@ module Expressir
|
|
|
283
283
|
def self.resolve_references!(exp_file, source_size: nil)
|
|
284
284
|
if source_size && source_size <= RESOLVE_DELEGATION_THRESHOLD &&
|
|
285
285
|
Core::NATIVE_AVAILABLE && Core.respond_to?(:resolve_model_hash)
|
|
286
|
-
|
|
287
|
-
|
|
286
|
+
begin
|
|
287
|
+
merge_base_paths!(exp_file, Core.resolve_model_hash(exp_file.to_hash))
|
|
288
|
+
return exp_file
|
|
289
|
+
rescue NotImplementedError
|
|
290
|
+
# A version-skewed local ext carries the parse binds but
|
|
291
|
+
# not this one; the Ruby visitor keeps the lane alive.
|
|
292
|
+
end
|
|
288
293
|
end
|
|
289
294
|
ResolveReferencesModelVisitor.new.visit(exp_file)
|
|
290
295
|
exp_file
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Expressir
|
|
4
|
+
module Express
|
|
5
|
+
# The eengine `--patch` applier (eengine parity):
|
|
6
|
+
# plugins/p11/top-level.lisp `patch-schema`. A patch document is a
|
|
7
|
+
# `PATCH_SCHEMA patch_id TARGET schema_id;` body (or a plain
|
|
8
|
+
# schema body) holding, in order:
|
|
9
|
+
#
|
|
10
|
+
# DELETE <kind> <name>; — remove the declaration
|
|
11
|
+
# RENAME <kind> <name> AS <new>; — rename it in place
|
|
12
|
+
# <any full declaration> — replace-or-add
|
|
13
|
+
# CONSTANT <id> : <type> := <expr>; — replace-or-add constant
|
|
14
|
+
#
|
|
15
|
+
# Names match case-insensitively and the kind must match exactly
|
|
16
|
+
# (eengine errors when a DELETE/RENAME target is missing).
|
|
17
|
+
class PatchSchema
|
|
18
|
+
KINDS = %w[CONSTANT TYPE ENTITY SUBTYPE_CONSTRAINT FUNCTION RULE
|
|
19
|
+
PROCEDURE].freeze
|
|
20
|
+
|
|
21
|
+
COLLECTIONS = {
|
|
22
|
+
"CONSTANT" => :constants,
|
|
23
|
+
"TYPE" => :types,
|
|
24
|
+
"ENTITY" => :entities,
|
|
25
|
+
"SUBTYPE_CONSTRAINT" => :subtype_constraints,
|
|
26
|
+
"FUNCTION" => :functions,
|
|
27
|
+
"RULE" => :rules,
|
|
28
|
+
"PROCEDURE" => :procedures,
|
|
29
|
+
}.freeze
|
|
30
|
+
|
|
31
|
+
END_KEYWORDS = {
|
|
32
|
+
"TYPE" => "END_TYPE",
|
|
33
|
+
"ENTITY" => "END_ENTITY",
|
|
34
|
+
"FUNCTION" => "END_FUNCTION",
|
|
35
|
+
"PROCEDURE" => "END_PROCEDURE",
|
|
36
|
+
"RULE" => "END_RULE",
|
|
37
|
+
"SUBTYPE_CONSTRAINT" => "END_SUBTYPE_CONSTRAINT",
|
|
38
|
+
}.freeze
|
|
39
|
+
|
|
40
|
+
class Error < StandardError; end
|
|
41
|
+
|
|
42
|
+
# Applies the patch text to the schema (found by the TARGET id
|
|
43
|
+
# in the repository, or the sole schema when absent). Mutates
|
|
44
|
+
# the repository's schema in place and returns it.
|
|
45
|
+
def self.apply(repository, patch_text)
|
|
46
|
+
commands = Parser.new(patch_text).parse
|
|
47
|
+
target = commands[:target]
|
|
48
|
+
schema = if target
|
|
49
|
+
repository.schemas.find { |s| s.id.casecmp(target).zero? }
|
|
50
|
+
else
|
|
51
|
+
repository.schemas.first
|
|
52
|
+
end
|
|
53
|
+
raise Error, "no schema#{" '#{target}'" if target} in the repository" unless schema
|
|
54
|
+
|
|
55
|
+
new(schema).apply(commands[:items])
|
|
56
|
+
schema
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def initialize(schema)
|
|
60
|
+
@schema = schema
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def apply(items)
|
|
64
|
+
items.each { |item| apply_item(item) }
|
|
65
|
+
@schema
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
private
|
|
69
|
+
|
|
70
|
+
def apply_item(item)
|
|
71
|
+
case item[:op]
|
|
72
|
+
when :delete
|
|
73
|
+
collection = @schema.public_send(COLLECTIONS.fetch(item[:kind]))
|
|
74
|
+
decl = find_by_name(collection, item[:name])
|
|
75
|
+
raise Error, "the #{item[:kind]} #{item[:name]} was not found" unless decl
|
|
76
|
+
|
|
77
|
+
collection.delete(decl)
|
|
78
|
+
when :rename
|
|
79
|
+
collection = @schema.public_send(COLLECTIONS.fetch(item[:kind]))
|
|
80
|
+
decl = find_by_name(collection, item[:name])
|
|
81
|
+
raise Error, "the #{item[:kind]} #{item[:name]} was not found" unless decl
|
|
82
|
+
|
|
83
|
+
decl.id = item[:new_name]
|
|
84
|
+
when :declaration
|
|
85
|
+
collection = @schema.public_send(COLLECTIONS.fetch(item[:kind]))
|
|
86
|
+
existing = find_by_name(collection, item[:decl].id)
|
|
87
|
+
collection.delete(existing) if existing
|
|
88
|
+
# eengine pushes the replacement to the front of the
|
|
89
|
+
# declarations list.
|
|
90
|
+
collection.unshift(item[:decl])
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def find_by_name(collection, name)
|
|
95
|
+
collection.find { |d| d.id.casecmp(name).zero? }
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# The patch-text scanner: string- and comment-aware; commands
|
|
99
|
+
# are one-liners, declarations capture to their END keyword.
|
|
100
|
+
class Parser
|
|
101
|
+
attr_reader :source
|
|
102
|
+
|
|
103
|
+
def initialize(source)
|
|
104
|
+
@source = source
|
|
105
|
+
@pos = 0
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def parse
|
|
109
|
+
result = { target: nil, items: [] }
|
|
110
|
+
skip_trivia
|
|
111
|
+
word = peek_word
|
|
112
|
+
if word&.casecmp("PATCH_SCHEMA")&.zero?
|
|
113
|
+
consume_word
|
|
114
|
+
consume_word # the patch id
|
|
115
|
+
skip_trivia
|
|
116
|
+
unless peek_word&.casecmp("TARGET")&.zero?
|
|
117
|
+
raise Error, "PATCH_SCHEMA expects TARGET <schema_id>;"
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
consume_word
|
|
121
|
+
result[:target] = consume_word
|
|
122
|
+
consume_semicolon
|
|
123
|
+
elsif word&.casecmp("SCHEMA")&.zero?
|
|
124
|
+
consume_word
|
|
125
|
+
consume_word # the schema id
|
|
126
|
+
consume_semicolon
|
|
127
|
+
end
|
|
128
|
+
until at_end?
|
|
129
|
+
skip_trivia
|
|
130
|
+
break if peek_word&.casecmp("END_PATCH_SCHEMA")&.zero?
|
|
131
|
+
break if peek_word&.casecmp("END_SCHEMA")&.zero?
|
|
132
|
+
|
|
133
|
+
result[:items] << parse_item
|
|
134
|
+
end
|
|
135
|
+
result
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
private
|
|
139
|
+
|
|
140
|
+
def at_end?
|
|
141
|
+
@pos >= source.length
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def skip_trivia
|
|
145
|
+
until at_end?
|
|
146
|
+
match = source[@pos..].match(/\A(?:\s+|\(\*.*?\*\))/m)
|
|
147
|
+
break unless match
|
|
148
|
+
|
|
149
|
+
@pos += match[0].length
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def peek_word
|
|
154
|
+
skip_trivia
|
|
155
|
+
(source[@pos..] || "").match(/\A[A-Za-z_][A-Za-z0-9_]*/)&.to_s
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def consume_word
|
|
159
|
+
skip_trivia
|
|
160
|
+
match = source[@pos..].match(/\A[A-Za-z_][A-Za-z0-9_]*/)
|
|
161
|
+
raise Error, "expected an identifier at offset #{@pos}" unless match
|
|
162
|
+
|
|
163
|
+
@pos += match[0].length
|
|
164
|
+
match[0]
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def consume_semicolon
|
|
168
|
+
skip_trivia
|
|
169
|
+
raise Error, "expected ';' at offset #{@pos}" unless source[@pos] == ";"
|
|
170
|
+
|
|
171
|
+
@pos += 1
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def consume_keyword(word)
|
|
175
|
+
skip_trivia
|
|
176
|
+
match = source[@pos..].match(/\A#{Regexp.escape(word)}/i)
|
|
177
|
+
raise Error, "expected #{word} at offset #{@pos}" unless match
|
|
178
|
+
|
|
179
|
+
@pos += match[0].length
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def parse_item
|
|
183
|
+
skip_trivia
|
|
184
|
+
item_start = @pos
|
|
185
|
+
word = consume_word
|
|
186
|
+
upper = word.upcase
|
|
187
|
+
if upper == "DELETE"
|
|
188
|
+
kind = consume_word.upcase
|
|
189
|
+
name = consume_word
|
|
190
|
+
consume_semicolon
|
|
191
|
+
{ op: :delete, kind: kind, name: name }
|
|
192
|
+
elsif upper == "RENAME"
|
|
193
|
+
kind = consume_word.upcase
|
|
194
|
+
name = consume_word
|
|
195
|
+
consume_keyword("AS")
|
|
196
|
+
new_name = consume_word
|
|
197
|
+
consume_semicolon
|
|
198
|
+
{ op: :rename, kind: kind, name: name, new_name: new_name }
|
|
199
|
+
elsif KINDS.include?(upper)
|
|
200
|
+
chunk = capture_declaration(upper, item_start)
|
|
201
|
+
{ op: :declaration, kind: upper, decl: parse_declaration(upper, chunk) }
|
|
202
|
+
else
|
|
203
|
+
raise Error, "unsupported patch item '#{word}'"
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
# Capture a declaration chunk from its keyword to its END
|
|
208
|
+
# keyword (or the single terminating ';' for CONSTANT),
|
|
209
|
+
# skipping strings and comments; the chunk keeps its
|
|
210
|
+
# terminator for the wrapper parse.
|
|
211
|
+
def capture_declaration(kind, from)
|
|
212
|
+
@chunk_from = from
|
|
213
|
+
if kind == "CONSTANT"
|
|
214
|
+
capture_to_semicolon(@pos)
|
|
215
|
+
else
|
|
216
|
+
capture_to_keyword(END_KEYWORDS.fetch(kind))
|
|
217
|
+
end
|
|
218
|
+
@chunk_text = source[@chunk_from...@pos]
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
def capture_to_semicolon(from)
|
|
222
|
+
cursor = from
|
|
223
|
+
depth = 0
|
|
224
|
+
while cursor < source.length
|
|
225
|
+
ch = source[cursor]
|
|
226
|
+
if ch == "'"
|
|
227
|
+
cursor = skip_string(cursor)
|
|
228
|
+
elsif ch == "(" && source[cursor + 1] == "*"
|
|
229
|
+
cursor = skip_comment(cursor)
|
|
230
|
+
else
|
|
231
|
+
depth += 1 if ch == "("
|
|
232
|
+
depth -= 1 if ch == ")"
|
|
233
|
+
if ch == ";" && depth.zero?
|
|
234
|
+
@pos = cursor + 1
|
|
235
|
+
return
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
cursor += 1
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
raise Error, "unterminated CONSTANT declaration"
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def capture_to_keyword(terminator)
|
|
245
|
+
pattern = /#{terminator}\s*;/i
|
|
246
|
+
cursor = @pos
|
|
247
|
+
while cursor < source.length
|
|
248
|
+
ch = source[cursor]
|
|
249
|
+
if ch == "'"
|
|
250
|
+
cursor = skip_string(cursor)
|
|
251
|
+
elsif ch == "(" && source[cursor + 1] == "*"
|
|
252
|
+
cursor = skip_comment(cursor)
|
|
253
|
+
elsif (match = source[cursor..].match(/\A#{pattern}/))
|
|
254
|
+
@pos = cursor + match.end(0)
|
|
255
|
+
return
|
|
256
|
+
else
|
|
257
|
+
cursor += 1
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
raise Error, "unterminated declaration (expected #{terminator};)"
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
def skip_string(from)
|
|
264
|
+
cursor = from + 1
|
|
265
|
+
while cursor < source.length
|
|
266
|
+
return cursor + 1 if source[cursor] == "'" && source[cursor + 1] != "'"
|
|
267
|
+
|
|
268
|
+
cursor += source[cursor] == "'" ? 2 : 1
|
|
269
|
+
end
|
|
270
|
+
raise Error, "unterminated string"
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
def skip_comment(from)
|
|
274
|
+
cursor = source.index("*)", from + 2)
|
|
275
|
+
raise Error, "unterminated comment" unless cursor
|
|
276
|
+
|
|
277
|
+
cursor + 2
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
# Parse the captured declaration text by wrapping it in a
|
|
281
|
+
# scratch schema and running the normal parser. A CONSTANT
|
|
282
|
+
# patch body (a lone `CONSTANT id : type := expr;`) closes
|
|
283
|
+
# with END_CONSTANT for the wrapper's grammar.
|
|
284
|
+
def parse_declaration(kind, _chunk)
|
|
285
|
+
suffix = kind == "CONSTANT" ? " END_CONSTANT;" : ""
|
|
286
|
+
wrapper = "SCHEMA __patch_scratch;\n#{@chunk_text}#{suffix}\nEND_SCHEMA;"
|
|
287
|
+
repository = Expressir::Express::Parser.from_exp(wrapper,
|
|
288
|
+
skip_references: true)
|
|
289
|
+
collection = repository.schemas.first.public_send(COLLECTIONS.fetch(kind))
|
|
290
|
+
decl = collection.first
|
|
291
|
+
raise Error, "the #{kind} declaration did not parse" unless decl
|
|
292
|
+
|
|
293
|
+
decl
|
|
294
|
+
end
|
|
295
|
+
end
|
|
296
|
+
end
|
|
297
|
+
end
|
|
298
|
+
end
|
|
@@ -42,21 +42,31 @@ module Expressir
|
|
|
42
42
|
# intermediate schema, the shape eengine's
|
|
43
43
|
# --concat_schema output corresponds to (copy
|
|
44
44
|
# pass, no prune, no 1994 rewrite).
|
|
45
|
+
# `typeof` — true prepends a `TYPEOF => (...)` remark to
|
|
46
|
+
# every longform entity: the entity plus its
|
|
47
|
+
# supertype chain and the SELECT types that
|
|
48
|
+
# admit any of them, schema-qualified (the
|
|
49
|
+
# eengine `--flat -typeof` comment).
|
|
45
50
|
def initialize(root_schema, repository, longform_name: nil,
|
|
46
|
-
extenders: :all, prune: true, stage: :longform
|
|
51
|
+
extenders: :all, prune: true, stage: :longform,
|
|
52
|
+
typeof: false)
|
|
47
53
|
@root = root_schema
|
|
48
54
|
@repository = repository
|
|
49
55
|
@longform_name = longform_name || @root.id
|
|
50
56
|
@extenders = extenders
|
|
51
57
|
@prune = prune
|
|
52
58
|
@stage = stage
|
|
59
|
+
@typeof = typeof
|
|
53
60
|
@reference_entities = [] # G.1.6 entities
|
|
54
61
|
end
|
|
55
62
|
|
|
56
63
|
def flatten
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
64
|
+
if native_available? && native_options?
|
|
65
|
+
native_flatten
|
|
66
|
+
else
|
|
67
|
+
@schema = build_longform
|
|
68
|
+
end
|
|
69
|
+
add_typeof_comments!(@schema) if @typeof
|
|
60
70
|
self
|
|
61
71
|
end
|
|
62
72
|
|
|
@@ -88,6 +98,75 @@ module Expressir
|
|
|
88
98
|
self
|
|
89
99
|
end
|
|
90
100
|
|
|
101
|
+
# The eengine `--flat -typeof` comment: one remark per entity
|
|
102
|
+
# listing the entity, its supertype chain, and every SELECT type
|
|
103
|
+
# that admits any of them — schema-qualified. Runs after either
|
|
104
|
+
# flatten lane, so both serve it.
|
|
105
|
+
def add_typeof_comments!(schema)
|
|
106
|
+
by_name = Array(schema.entities).to_h { |e| [e.id.downcase, e] }
|
|
107
|
+
selects = Array(schema.types).select do |type|
|
|
108
|
+
type.underlying_type.is_a?(Model::DataTypes::Select)
|
|
109
|
+
end
|
|
110
|
+
Array(schema.entities).each do |entity|
|
|
111
|
+
chain = supertype_chain(entity, by_name)
|
|
112
|
+
members = select_closure(chain, selects)
|
|
113
|
+
names = (chain + members).map do |decl|
|
|
114
|
+
"#{schema.id}.#{decl.id}".upcase
|
|
115
|
+
end
|
|
116
|
+
entity.remarks = ["TYPEOF => (#{names.map { |n| "'#{n}'" }.join(', ')})"]
|
|
117
|
+
end
|
|
118
|
+
schema
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
private
|
|
122
|
+
|
|
123
|
+
# The entity itself plus every supertype, topmost first.
|
|
124
|
+
def supertype_chain(entity, by_name)
|
|
125
|
+
chain = []
|
|
126
|
+
seen = {}
|
|
127
|
+
walk = lambda do |current|
|
|
128
|
+
key = current.id.downcase
|
|
129
|
+
return if seen.key?(key)
|
|
130
|
+
|
|
131
|
+
seen[key] = true
|
|
132
|
+
Array(current.subtype_of).each do |ref|
|
|
133
|
+
sup = by_name[ref.respond_to?(:id) ? ref.id.downcase : ref.to_s.downcase]
|
|
134
|
+
walk.call(sup) if sup
|
|
135
|
+
end
|
|
136
|
+
chain << current
|
|
137
|
+
end
|
|
138
|
+
walk.call(entity)
|
|
139
|
+
chain
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# The SELECT types admitting any chain member, transitively over
|
|
143
|
+
# selects-of-selects, in declaration order.
|
|
144
|
+
def select_closure(chain, selects)
|
|
145
|
+
member_names = chain.to_set { |d| d.id.downcase }
|
|
146
|
+
selected = []
|
|
147
|
+
loop do
|
|
148
|
+
grew = false
|
|
149
|
+
selects.each do |select|
|
|
150
|
+
next if selected.include?(select)
|
|
151
|
+
|
|
152
|
+
items = Array(select.underlying_type.items).map do |item|
|
|
153
|
+
item.respond_to?(:id) ? item.id.downcase : item.to_s.downcase
|
|
154
|
+
end
|
|
155
|
+
admitted = items.any? do |item|
|
|
156
|
+
member_names.include?(item) ||
|
|
157
|
+
selected.any? { |sel| sel.id.downcase == item }
|
|
158
|
+
end
|
|
159
|
+
next unless admitted
|
|
160
|
+
|
|
161
|
+
selected << select
|
|
162
|
+
member_names << select.id.downcase
|
|
163
|
+
grew = true
|
|
164
|
+
end
|
|
165
|
+
break unless grew
|
|
166
|
+
end
|
|
167
|
+
selected
|
|
168
|
+
end
|
|
169
|
+
|
|
91
170
|
def native_available?
|
|
92
171
|
Expressir::Express::Core::NATIVE_AVAILABLE &&
|
|
93
172
|
::Expressir::Core.respond_to?(:flatten_schema)
|
|
@@ -99,8 +178,6 @@ module Expressir
|
|
|
99
178
|
end
|
|
100
179
|
end
|
|
101
180
|
|
|
102
|
-
private
|
|
103
|
-
|
|
104
181
|
# ---- interface closure (same semantics as Concatenator) ----
|
|
105
182
|
|
|
106
183
|
def closure
|
data/lib/expressir/express.rb
CHANGED
|
@@ -13,6 +13,7 @@ module Expressir
|
|
|
13
13
|
autoload :AdocHyperlinkFormatter, "#{__dir__}/express/adoc_hyperlink_formatter"
|
|
14
14
|
autoload :AdocSourceFormatter, "#{__dir__}/express/adoc_source_formatter"
|
|
15
15
|
autoload :Checker, "#{__dir__}/express/checker"
|
|
16
|
+
autoload :CleanupParens, "#{__dir__}/express/cleanup_parens"
|
|
16
17
|
autoload :Concatenator, "#{__dir__}/express/concatenator"
|
|
17
18
|
autoload :Core, "#{__dir__}/express/core"
|
|
18
19
|
autoload :Dialect, "#{__dir__}/express/dialect"
|
|
@@ -26,6 +27,11 @@ module Expressir
|
|
|
26
27
|
autoload :Grammar, "#{__dir__}/express/grammar"
|
|
27
28
|
autoload :HyperlinkFormatter, "#{__dir__}/express/hyperlink_formatter"
|
|
28
29
|
autoload :InterfaceDot, "#{__dir__}/express/interface_dot"
|
|
30
|
+
autoload :DataDot, "#{__dir__}/express/dot/data_dot"
|
|
31
|
+
autoload :DotNames, "#{__dir__}/express/dot/names"
|
|
32
|
+
autoload :PathDot, "#{__dir__}/express/dot/path_dot"
|
|
33
|
+
autoload :SchemaDot, "#{__dir__}/express/dot/schema_dot"
|
|
34
|
+
autoload :SupertypeDot, "#{__dir__}/express/dot/supertype_dot"
|
|
29
35
|
autoload :LineMap, "#{__dir__}/express/line_map"
|
|
30
36
|
autoload :Listing, "#{__dir__}/express/listing"
|
|
31
37
|
autoload :ModelVisitor, "#{__dir__}/express/model_visitor"
|
|
@@ -42,6 +48,7 @@ module Expressir
|
|
|
42
48
|
autoload :Shtolo, "#{__dir__}/express/shtolo"
|
|
43
49
|
autoload :SchemaBlockScanner, "#{__dir__}/express/schema_block_scanner"
|
|
44
50
|
autoload :SchemaHeadFormatter, "#{__dir__}/express/schema_head_formatter"
|
|
51
|
+
autoload :PatchSchema, "#{__dir__}/express/patch_schema"
|
|
45
52
|
autoload :SchemaPlainSourceFormatter,
|
|
46
53
|
"#{__dir__}/express/schema_plain_source_formatter"
|
|
47
54
|
autoload :SchemaSourceFormatter, "#{__dir__}/express/schema_source_formatter"
|