expressir 2.5.1-x86_64-linux → 2.5.2-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.
- 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 +9 -0
- data/lib/expressir/commands/compare.rb +60 -0
- data/lib/expressir/commands/patch.rb +33 -0
- data/lib/expressir/commands.rb +1 -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.rb +6 -0
- data/lib/expressir/version.rb +1 -1
- metadata +9 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f73353d7fce5a1fbfa3cf423f09cac670b0e1e7e884da0423232f89e4ca21c6a
|
|
4
|
+
data.tar.gz: 1778c74818c55a22808f8120df8576a92eda101f59aa8a0a729c119660d092d9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f1e0e265743e2bcdb2da79e857446deba55f23f030ae5be02fe14c29cd294e99569aa6ce09704fef8e59e65e5083a34783d9b30e9fcf3f3ea7b5cc74c114dc18
|
|
7
|
+
data.tar.gz: 4c5a29da241f209dbd1b8741ae9c25ce9fd0ce7a4a8d571ed7e9453d5ede67537f4b1230cbee516148adb910ab727bed2e9d6fc7c2b29b61899799cb67effefd
|
data/ENGINE-COMPAT.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
-
"engine_commit": "
|
|
2
|
+
"engine_commit": "fc875c03a8a4310e162a9ec2ad6734384c9d2ca5",
|
|
3
3
|
"rubygems": "2.5.0",
|
|
4
|
-
"ext": "v0.1.
|
|
4
|
+
"ext": "v0.1.68",
|
|
5
5
|
"crates": "1.5.1",
|
|
6
6
|
"npm": null,
|
|
7
7
|
"pypi": null,
|
|
8
|
-
"released_at": "2026-11-
|
|
8
|
+
"released_at": "2026-11-30T10:49:52Z",
|
|
9
9
|
"_comment": "expressir#618 \u2014 the engine-compat manifest, mirroring parsanol-rs#423. Maps the expressir gem train to the expressir-rs ext tag and its engine commit; the null fields fill as the crates/npm/pypi tiers land (expressir#619/#622/#621). tools/check_engine_compat.rb verifies the pairings in CI; every release train updates this file."
|
|
10
10
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/lib/expressir/cli.rb
CHANGED
|
@@ -132,10 +132,19 @@ module Expressir
|
|
|
132
132
|
desc "compare BASE REVISED", "Compare two EXPRESS files; write the schema.changes interchange report"
|
|
133
133
|
option :output, type: :string, aliases: "-o",
|
|
134
134
|
desc: "Report path (defaults to stdout)"
|
|
135
|
+
option :patch, type: :string,
|
|
136
|
+
desc: "Also write a PATCH_SCHEMA derived from the diff to PATH"
|
|
135
137
|
def compare(base_path, revised_path)
|
|
136
138
|
Expressir::Commands::Compare.new(options).run(base_path, revised_path)
|
|
137
139
|
end
|
|
138
140
|
|
|
141
|
+
desc "patch BASE PATCH", "Apply an eengine-style patch schema to BASE; write the patched EXPRESS"
|
|
142
|
+
option :output, type: :string, aliases: "-o",
|
|
143
|
+
desc: "Output path (defaults to <base>-patched.exp beside BASE)"
|
|
144
|
+
def patch(base_path, patch_path)
|
|
145
|
+
Expressir::Commands::Patch.new(options).run(base_path, patch_path)
|
|
146
|
+
end
|
|
147
|
+
|
|
139
148
|
desc "doctor DIR", "Assess a workspace for expressir readiness"
|
|
140
149
|
option :emit_manifest, type: :string, desc: "Write a starter schema manifest listing the ready schemas"
|
|
141
150
|
def doctor(path)
|
|
@@ -28,6 +28,66 @@ module Expressir
|
|
|
28
28
|
else
|
|
29
29
|
$stdout.write(xml)
|
|
30
30
|
end
|
|
31
|
+
return unless options[:patch]
|
|
32
|
+
|
|
33
|
+
patch_text = generate_patch(base_repo, revised_repo)
|
|
34
|
+
File.write(options[:patch], patch_text)
|
|
35
|
+
say "patch written to #{options[:patch]}"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# The PATCH_SCHEMA derived from the diff (the compare→patch
|
|
39
|
+
# loop): deletions become DELETE commands; modified and added
|
|
40
|
+
# declarations re-emit the revised declaration, which the patch
|
|
41
|
+
# applier treats as replace-or-add. One PATCH_SCHEMA per
|
|
42
|
+
# touched schema (each patch targets one schema, like eengine).
|
|
43
|
+
def generate_patch(base_repo, revised_repo)
|
|
44
|
+
base = index_schemas(base_repo)
|
|
45
|
+
revised = index_schemas(revised_repo)
|
|
46
|
+
out = "(* Patch generated by Expressir #{Expressir::VERSION} *)\n\n"
|
|
47
|
+
(base.keys | revised.keys).each do |schema_id|
|
|
48
|
+
base_schema = base[schema_id]
|
|
49
|
+
revised_schema = revised[schema_id]
|
|
50
|
+
if base_schema.nil?
|
|
51
|
+
out << "(* schema #{schema_id} added wholesale; no patch target *)\n\n"
|
|
52
|
+
next
|
|
53
|
+
end
|
|
54
|
+
next out << "(* schema #{schema_id} removed wholesale *)\n\n" if revised_schema.nil?
|
|
55
|
+
|
|
56
|
+
items = patch_items(base_schema, revised_schema)
|
|
57
|
+
next if items.empty?
|
|
58
|
+
|
|
59
|
+
out << "PATCH_SCHEMA #{schema_id}_patch TARGET #{schema_id};\n"
|
|
60
|
+
items.each { |item| out << item }
|
|
61
|
+
out << "END_PATCH_SCHEMA;\n\n"
|
|
62
|
+
end
|
|
63
|
+
out
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def patch_items(base_schema, revised_schema)
|
|
67
|
+
items = []
|
|
68
|
+
replaced = {}
|
|
69
|
+
Expressir::Express::SchemaCompare::COLLECTIONS.each do |collection|
|
|
70
|
+
kind = KINDS[collection]
|
|
71
|
+
deltas = Expressir::Express::SchemaCompare
|
|
72
|
+
.collection_deltas(base_schema, revised_schema, collection)
|
|
73
|
+
Expressir::Express::ChangeClassification.apply(deltas, base_schema)
|
|
74
|
+
deltas.each do |delta|
|
|
75
|
+
segments = delta.path.split(".")
|
|
76
|
+
# attribute-level deltas ride the owning entity's replace
|
|
77
|
+
name = segments[1]
|
|
78
|
+
if delta.op == :removed && segments.size == 2
|
|
79
|
+
items << " DELETE #{kind} #{segments.last};\n"
|
|
80
|
+
next
|
|
81
|
+
end
|
|
82
|
+
next if segments.size > 2 && replaced[[kind, name]]
|
|
83
|
+
|
|
84
|
+
replaced[[kind, name]] = true
|
|
85
|
+
revised_decl = Array(revised_schema.send(collection))
|
|
86
|
+
.find { |d| d.respond_to?(:id) && d.id&.casecmp(name)&.zero? }
|
|
87
|
+
items << " #{revised_decl.format}\n" if revised_decl
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
items
|
|
31
91
|
end
|
|
32
92
|
|
|
33
93
|
# Emitted through Moxml directly: lutaml-model's leptris-backed
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Expressir
|
|
4
|
+
module Commands
|
|
5
|
+
# `expressir patch` (eengine `--patch` parity): apply a patch
|
|
6
|
+
# schema (DELETE / RENAME / replace-or-add declarations) to a
|
|
7
|
+
# base EXPRESS file and write the patched schema pretty-printed
|
|
8
|
+
# with the Expressir patch banner.
|
|
9
|
+
class Patch < Base
|
|
10
|
+
def run(base_path, patch_path)
|
|
11
|
+
# Name matching only — the applier never dereferences, and
|
|
12
|
+
# eengine's own renames leave reference targets untouched.
|
|
13
|
+
repository = Expressir::Express::Parser.from_file(base_path,
|
|
14
|
+
skip_references: true)
|
|
15
|
+
patch_text = File.read(patch_path)
|
|
16
|
+
schema = Expressir::Express::PatchSchema.apply(repository, patch_text)
|
|
17
|
+
|
|
18
|
+
formatter = Expressir::Express::PrettyFormatter.new
|
|
19
|
+
output = +"-- -*- Mode: Express; Base: 10 -*-\n\n"
|
|
20
|
+
output << "(* Schema Patched by Expressir #{Expressir::VERSION}\n"
|
|
21
|
+
output << " patch: #{patch_path}\n"
|
|
22
|
+
output << "*)\n\n"
|
|
23
|
+
output << "(* File: #{base_path} *)\n"
|
|
24
|
+
output << "(* Schema: #{schema.id} *)\n"
|
|
25
|
+
output << formatter.format(repository)
|
|
26
|
+
|
|
27
|
+
destination = options[:output] || base_path.sub(/\.exp\z/i, "-patched.exp")
|
|
28
|
+
File.write(destination, output)
|
|
29
|
+
say "patched schema written to #{destination}"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
data/lib/expressir/commands.rb
CHANGED
|
@@ -26,6 +26,7 @@ module Expressir
|
|
|
26
26
|
autoload :Package, "#{__dir__}/commands/package"
|
|
27
27
|
autoload :Compare, "#{__dir__}/commands/compare"
|
|
28
28
|
autoload :Doctor, "#{__dir__}/commands/doctor"
|
|
29
|
+
autoload :Patch, "#{__dir__}/commands/patch"
|
|
29
30
|
autoload :Population, "#{__dir__}/commands/population"
|
|
30
31
|
autoload :Receipt, "#{__dir__}/commands/receipt"
|
|
31
32
|
autoload :Manifest, "#{__dir__}/commands/manifest"
|
|
@@ -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
|
|
@@ -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
|
data/lib/expressir/express.rb
CHANGED
|
@@ -26,6 +26,11 @@ module Expressir
|
|
|
26
26
|
autoload :Grammar, "#{__dir__}/express/grammar"
|
|
27
27
|
autoload :HyperlinkFormatter, "#{__dir__}/express/hyperlink_formatter"
|
|
28
28
|
autoload :InterfaceDot, "#{__dir__}/express/interface_dot"
|
|
29
|
+
autoload :DataDot, "#{__dir__}/express/dot/data_dot"
|
|
30
|
+
autoload :DotNames, "#{__dir__}/express/dot/names"
|
|
31
|
+
autoload :PathDot, "#{__dir__}/express/dot/path_dot"
|
|
32
|
+
autoload :SchemaDot, "#{__dir__}/express/dot/schema_dot"
|
|
33
|
+
autoload :SupertypeDot, "#{__dir__}/express/dot/supertype_dot"
|
|
29
34
|
autoload :LineMap, "#{__dir__}/express/line_map"
|
|
30
35
|
autoload :Listing, "#{__dir__}/express/listing"
|
|
31
36
|
autoload :ModelVisitor, "#{__dir__}/express/model_visitor"
|
|
@@ -42,6 +47,7 @@ module Expressir
|
|
|
42
47
|
autoload :Shtolo, "#{__dir__}/express/shtolo"
|
|
43
48
|
autoload :SchemaBlockScanner, "#{__dir__}/express/schema_block_scanner"
|
|
44
49
|
autoload :SchemaHeadFormatter, "#{__dir__}/express/schema_head_formatter"
|
|
50
|
+
autoload :PatchSchema, "#{__dir__}/express/patch_schema"
|
|
45
51
|
autoload :SchemaPlainSourceFormatter,
|
|
46
52
|
"#{__dir__}/express/schema_plain_source_formatter"
|
|
47
53
|
autoload :SchemaSourceFormatter, "#{__dir__}/express/schema_source_formatter"
|
data/lib/expressir/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: expressir
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.5.
|
|
4
|
+
version: 2.5.2
|
|
5
5
|
platform: x86_64-linux
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -518,6 +518,7 @@ files:
|
|
|
518
518
|
- lib/expressir/commands/non_ascii_violation_collection.rb
|
|
519
519
|
- lib/expressir/commands/package.rb
|
|
520
520
|
- lib/expressir/commands/parity_inputs.rb
|
|
521
|
+
- lib/expressir/commands/patch.rb
|
|
521
522
|
- lib/expressir/commands/population.rb
|
|
522
523
|
- lib/expressir/commands/receipt.rb
|
|
523
524
|
- lib/expressir/commands/smrl_xml_index.rb
|
|
@@ -593,6 +594,11 @@ files:
|
|
|
593
594
|
- lib/expressir/express/concatenator.rb
|
|
594
595
|
- lib/expressir/express/core.rb
|
|
595
596
|
- lib/expressir/express/dialect.rb
|
|
597
|
+
- lib/expressir/express/dot/data_dot.rb
|
|
598
|
+
- lib/expressir/express/dot/names.rb
|
|
599
|
+
- lib/expressir/express/dot/path_dot.rb
|
|
600
|
+
- lib/expressir/express/dot/schema_dot.rb
|
|
601
|
+
- lib/expressir/express/dot/supertype_dot.rb
|
|
596
602
|
- lib/expressir/express/error.rb
|
|
597
603
|
- lib/expressir/express/expressg_exporter.rb
|
|
598
604
|
- lib/expressir/express/formatter.rb
|
|
@@ -623,6 +629,7 @@ files:
|
|
|
623
629
|
- lib/expressir/express/node_position_index.rb
|
|
624
630
|
- lib/expressir/express/parallel_files.rb
|
|
625
631
|
- lib/expressir/express/parser.rb
|
|
632
|
+
- lib/expressir/express/patch_schema.rb
|
|
626
633
|
- lib/expressir/express/pretty_formatter.rb
|
|
627
634
|
- lib/expressir/express/pretty_gate.rb
|
|
628
635
|
- lib/expressir/express/refs_overlay.rb
|