expressir 2.5.2-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/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 +18 -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 +2 -124
- data/lib/expressir/commands/compare_arm_mim.rb +52 -0
- data/lib/expressir/commands/flatten.rb +2 -1
- data/lib/expressir/commands.rb +2 -0
- data/lib/expressir/express/cleanup_parens.rb +144 -0
- data/lib/expressir/express/shtolo.rb +83 -6
- data/lib/expressir/express.rb +1 -0
- data/lib/expressir/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bb922a24915f00adb6ee6c719591c069384fe2216ddd4ab96830b793f0ede0f5
|
|
4
|
+
data.tar.gz: 3f48e0ac74b1f7438bdf112f98a0f3a79d26d22a5cb04e8cb4a65ae513fe4722
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bb88835059e061090d55828fd43b3ef9fd2270d21fcdf35143f14bbc30c9c8caf4ea716128d15ee9a05e367bf28411c4e74fcccebacce470d66139abcaf32ffc
|
|
7
|
+
data.tar.gz: b9f05e45f7b8e327674de43ecb490b949ca00368807f62c6661226b463296fccfbd684f9ceba2b3e6b429107071ae9214b16ea2382092e2e3b4fe5cc5b83d13b
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/lib/expressir/cli.rb
CHANGED
|
@@ -70,6 +70,9 @@ module Expressir
|
|
|
70
70
|
method_option :stepmod, type: :string,
|
|
71
71
|
desc: "STEPmod checkout root — explicit opt-in to directory-" \
|
|
72
72
|
"convention resolution as the fallback"
|
|
73
|
+
method_option :typeof, type: :boolean, default: false,
|
|
74
|
+
desc: "Prepend a TYPEOF comment to every entity (the " \
|
|
75
|
+
"supertype chain plus admitting SELECT types)"
|
|
73
76
|
def flatten(path, _thor_options = nil)
|
|
74
77
|
Expressir::Commands::Flatten.new(options).run(path)
|
|
75
78
|
end
|
|
@@ -129,6 +132,13 @@ module Expressir
|
|
|
129
132
|
Expressir::Commands::ExportOwl.new(options).run(path)
|
|
130
133
|
end
|
|
131
134
|
|
|
135
|
+
desc "cleanup-parens PATH", "Minimize redundant parentheses in where rules; write the paren-clean EXPRESS"
|
|
136
|
+
option :output, type: :string, aliases: "-o",
|
|
137
|
+
desc: "Output path (defaults to <path>-paren-clean.exp beside PATH)"
|
|
138
|
+
def cleanup_parens(path)
|
|
139
|
+
Expressir::Commands::CleanupParens.new(options).run(path)
|
|
140
|
+
end
|
|
141
|
+
|
|
132
142
|
desc "compare BASE REVISED", "Compare two EXPRESS files; write the schema.changes interchange report"
|
|
133
143
|
option :output, type: :string, aliases: "-o",
|
|
134
144
|
desc: "Report path (defaults to stdout)"
|
|
@@ -145,6 +155,14 @@ module Expressir
|
|
|
145
155
|
Expressir::Commands::Patch.new(options).run(base_path, patch_path)
|
|
146
156
|
end
|
|
147
157
|
|
|
158
|
+
desc "compare-arm-mim BASE_ARM REV_ARM BASE_MIM REV_MIM", "Compare the arm/mim pairs; write the module.xml-shaped changes document"
|
|
159
|
+
option :output, type: :string, aliases: "-o",
|
|
160
|
+
desc: "Document path (defaults to stdout)"
|
|
161
|
+
def compare_arm_mim(base_arm, revised_arm, base_mim, revised_mim)
|
|
162
|
+
Expressir::Commands::CompareArmMim.new(options)
|
|
163
|
+
.run(base_arm, revised_arm, base_mim, revised_mim)
|
|
164
|
+
end
|
|
165
|
+
|
|
148
166
|
desc "doctor DIR", "Assess a workspace for expressir readiness"
|
|
149
167
|
option :emit_manifest, type: :string, desc: "Write a starter schema manifest listing the ready schemas"
|
|
150
168
|
def doctor(path)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Expressir
|
|
4
|
+
module Commands
|
|
5
|
+
# `expressir cleanup-parens` (eengine `--cleanup_parens` parity):
|
|
6
|
+
# minimize redundant parentheses in the entity where rules and
|
|
7
|
+
# write the schema back out (`<name>-paren-clean.exp`).
|
|
8
|
+
class CleanupParens < Base
|
|
9
|
+
def run(path)
|
|
10
|
+
repository = Expressir::Express::Parser.from_file(path,
|
|
11
|
+
skip_references: true)
|
|
12
|
+
repository.schemas.each { |schema| Expressir::Express::CleanupParens.call(schema) }
|
|
13
|
+
|
|
14
|
+
formatter = Expressir::Express::PrettyFormatter.new
|
|
15
|
+
output = +"-- -*- Mode: EXPRESS; Base: 10 -*-\n\n"
|
|
16
|
+
output << "(* Paren-cleaned by Expressir #{Expressir::VERSION} *)\n\n"
|
|
17
|
+
output << formatter.format(repository)
|
|
18
|
+
|
|
19
|
+
destination = options[:output] || path.sub(/\.exp\z/i, "-paren-clean.exp")
|
|
20
|
+
File.write(destination, output)
|
|
21
|
+
say "paren-clean schema written to #{destination}"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Expressir
|
|
4
|
+
module Commands
|
|
5
|
+
class Compare
|
|
6
|
+
# The schema.delta collection both compare commands share:
|
|
7
|
+
# the schema-changes report (additions/modifications/deletions)
|
|
8
|
+
# over one base/revised pair.
|
|
9
|
+
module ReportBuilding
|
|
10
|
+
KINDS = {
|
|
11
|
+
constants: "CONSTANT",
|
|
12
|
+
types: "TYPE",
|
|
13
|
+
entities: "ENTITY",
|
|
14
|
+
subtype_constraints: "SUBTYPE_CONSTRAINT",
|
|
15
|
+
functions: "FUNCTION",
|
|
16
|
+
rules: "RULE",
|
|
17
|
+
procedures: "PROCEDURE",
|
|
18
|
+
}.freeze
|
|
19
|
+
|
|
20
|
+
def build_report(base_repo, revised_repo)
|
|
21
|
+
sections = { additions: [], deletions: [], modifications: [] }
|
|
22
|
+
base = index_schemas(base_repo)
|
|
23
|
+
revised = index_schemas(revised_repo)
|
|
24
|
+
|
|
25
|
+
(base.keys | revised.keys).each do |schema_id|
|
|
26
|
+
base_schema = base[schema_id]
|
|
27
|
+
revised_schema = revised[schema_id]
|
|
28
|
+
if base_schema.nil?
|
|
29
|
+
collect_whole_schema(revised_schema, :added, sections)
|
|
30
|
+
elsif revised_schema.nil?
|
|
31
|
+
collect_whole_schema(base_schema, :removed, sections)
|
|
32
|
+
else
|
|
33
|
+
collect_deltas(base_schema, revised_schema, sections)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
Expressir::Eengine::CompareReport.new(
|
|
38
|
+
additions: Expressir::Eengine::ChangesSection
|
|
39
|
+
.new(modified_objects: sections[:additions]),
|
|
40
|
+
deletions: Expressir::Eengine::ChangesSection
|
|
41
|
+
.new(modified_objects: sections[:deletions]),
|
|
42
|
+
modifications: Expressir::Eengine::ChangesSection
|
|
43
|
+
.new(modified_objects: sections[:modifications]),
|
|
44
|
+
)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def report_pair(base_path, revised_path)
|
|
48
|
+
base_repo = Expressir::Express::Parser.from_file(base_path)
|
|
49
|
+
revised_repo = Expressir::Express::Parser.from_file(revised_path)
|
|
50
|
+
build_report(base_repo, revised_repo)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def object_node(doc, obj)
|
|
54
|
+
node = doc.create_element("modified.object")
|
|
55
|
+
attrs = { "type" => obj.type, "name" => obj.name }
|
|
56
|
+
attrs["interfaced.items"] = obj.interfaced_items if obj.interfaced_items
|
|
57
|
+
attrs["classif"] = obj.classif if obj.classif
|
|
58
|
+
node.set_attributes(attrs)
|
|
59
|
+
if obj.description
|
|
60
|
+
desc = doc.create_element("description")
|
|
61
|
+
desc.content = obj.description
|
|
62
|
+
node.add_child(desc)
|
|
63
|
+
end
|
|
64
|
+
node
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
private
|
|
68
|
+
|
|
69
|
+
def index_schemas(repo)
|
|
70
|
+
Array(repo.schemas).to_h { |schema| [schema.id&.safe_downcase, schema] }
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def collect_whole_schema(schema, operation, sections)
|
|
74
|
+
section = section_for(operation)
|
|
75
|
+
Expressir::Express::SchemaCompare::COLLECTIONS.each do |collection|
|
|
76
|
+
Array(schema.send(collection)).each do |decl|
|
|
77
|
+
next unless decl.respond_to?(:id) && decl.id
|
|
78
|
+
|
|
79
|
+
sections[section] << Expressir::Eengine::ModifiedObject.new(
|
|
80
|
+
type: KINDS[collection], name: decl.id,
|
|
81
|
+
)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def collect_deltas(base_schema, revised_schema, sections)
|
|
87
|
+
Expressir::Express::SchemaCompare::COLLECTIONS.each do |collection|
|
|
88
|
+
deltas = Expressir::Express::SchemaCompare
|
|
89
|
+
.collection_deltas(base_schema, revised_schema, collection)
|
|
90
|
+
Expressir::Express::ChangeClassification.apply(deltas, base_schema)
|
|
91
|
+
deltas.each do |delta|
|
|
92
|
+
# an attribute-level delta modifies its entity: it lands
|
|
93
|
+
# in modifications whatever the op
|
|
94
|
+
section = if delta.path.split(".").size > 2
|
|
95
|
+
:modifications
|
|
96
|
+
else
|
|
97
|
+
section_for(delta.op)
|
|
98
|
+
end
|
|
99
|
+
sections[section] << object_for(delta, collection)
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def object_for(delta, collection)
|
|
105
|
+
kind = KINDS[collection]
|
|
106
|
+
segments = delta.path.split(".")
|
|
107
|
+
name = segments[1]
|
|
108
|
+
object = if segments.size > 2
|
|
109
|
+
# attribute-level delta: the qualified path is the name
|
|
110
|
+
Expressir::Eengine::ModifiedObject.new(
|
|
111
|
+
type: kind, name: delta.path,
|
|
112
|
+
description: "attribute #{delta.op}"
|
|
113
|
+
)
|
|
114
|
+
else
|
|
115
|
+
Expressir::Eengine::ModifiedObject.new(type: kind, name: name)
|
|
116
|
+
end
|
|
117
|
+
object.classif = delta.classification&.value
|
|
118
|
+
object
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def section_for(operation)
|
|
122
|
+
case operation
|
|
123
|
+
when :added then :additions
|
|
124
|
+
when :removed then :deletions
|
|
125
|
+
else :modifications
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
@@ -7,15 +7,8 @@ module Expressir
|
|
|
7
7
|
# the `changes` importer reads, so comparison data flows both ways
|
|
8
8
|
# across toolchains.
|
|
9
9
|
class Compare < Base
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
types: "TYPE",
|
|
13
|
-
entities: "ENTITY",
|
|
14
|
-
subtype_constraints: "SUBTYPE_CONSTRAINT",
|
|
15
|
-
functions: "FUNCTION",
|
|
16
|
-
rules: "RULE",
|
|
17
|
-
procedures: "PROCEDURE",
|
|
18
|
-
}.freeze
|
|
10
|
+
autoload :ReportBuilding, "#{__dir__}/compare/report_building"
|
|
11
|
+
include ReportBuilding
|
|
19
12
|
|
|
20
13
|
def run(base_path, revised_path)
|
|
21
14
|
base_repo = Expressir::Express::Parser.from_file(base_path)
|
|
@@ -117,121 +110,6 @@ module Expressir
|
|
|
117
110
|
end
|
|
118
111
|
node
|
|
119
112
|
end
|
|
120
|
-
|
|
121
|
-
def object_node(doc, obj)
|
|
122
|
-
node = doc.create_element("modified.object")
|
|
123
|
-
attrs = { "type" => obj.type, "name" => obj.name }
|
|
124
|
-
attrs["interfaced.items"] = obj.interfaced_items if obj.interfaced_items
|
|
125
|
-
attrs["classif"] = obj.classif if obj.classif
|
|
126
|
-
node.set_attributes(attrs)
|
|
127
|
-
if obj.description
|
|
128
|
-
desc = doc.create_element("description")
|
|
129
|
-
desc.content = obj.description
|
|
130
|
-
node.add_child(desc)
|
|
131
|
-
end
|
|
132
|
-
node
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
def build_report(base_repo, revised_repo)
|
|
136
|
-
sections = { additions: [], deletions: [], modifications: [] }
|
|
137
|
-
base = index_schemas(base_repo)
|
|
138
|
-
revised = index_schemas(revised_repo)
|
|
139
|
-
|
|
140
|
-
(base.keys | revised.keys).each do |schema_id|
|
|
141
|
-
base_schema = base[schema_id]
|
|
142
|
-
revised_schema = revised[schema_id]
|
|
143
|
-
if base_schema.nil?
|
|
144
|
-
collect_whole_schema(revised_schema, :added, sections)
|
|
145
|
-
elsif revised_schema.nil?
|
|
146
|
-
collect_whole_schema(base_schema, :removed, sections)
|
|
147
|
-
else
|
|
148
|
-
collect_deltas(base_schema, revised_schema, sections)
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
Expressir::Eengine::CompareReport.new(
|
|
153
|
-
additions: Expressir::Eengine::ChangesSection
|
|
154
|
-
.new(modified_objects: sections[:additions]),
|
|
155
|
-
deletions: Expressir::Eengine::ChangesSection
|
|
156
|
-
.new(modified_objects: sections[:deletions]),
|
|
157
|
-
modifications: Expressir::Eengine::ChangesSection
|
|
158
|
-
.new(modified_objects: sections[:modifications]),
|
|
159
|
-
)
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
def index_schemas(repo)
|
|
163
|
-
Array(repo.schemas).to_h do |schema|
|
|
164
|
-
[schema.id&.safe_downcase, schema]
|
|
165
|
-
end
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
def collect_whole_schema(schema, operation, sections)
|
|
169
|
-
section = section_for(operation)
|
|
170
|
-
Expressir::Express::SchemaCompare::COLLECTIONS.each do |collection|
|
|
171
|
-
Array(schema.send(collection)).each do |decl|
|
|
172
|
-
next unless decl.respond_to?(:id) && decl.id
|
|
173
|
-
|
|
174
|
-
sections[section] << Expressir::Eengine::ModifiedObject.new(
|
|
175
|
-
type: KINDS[collection], name: decl.id,
|
|
176
|
-
)
|
|
177
|
-
end
|
|
178
|
-
end
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
def collect_deltas(base_schema, revised_schema, sections)
|
|
182
|
-
Expressir::Express::SchemaCompare::COLLECTIONS.each do |collection|
|
|
183
|
-
deltas = Expressir::Express::SchemaCompare
|
|
184
|
-
.collection_deltas(base_schema, revised_schema, collection)
|
|
185
|
-
Expressir::Express::ChangeClassification.apply(deltas, base_schema)
|
|
186
|
-
deltas.each do |delta|
|
|
187
|
-
# an attribute-level delta modifies its entity: it lands
|
|
188
|
-
# in modifications whatever the op
|
|
189
|
-
section = if delta.path.split(".").size > 2
|
|
190
|
-
:modifications
|
|
191
|
-
else
|
|
192
|
-
section_for(delta.op)
|
|
193
|
-
end
|
|
194
|
-
sections[section] << object_for(delta, collection)
|
|
195
|
-
end
|
|
196
|
-
end
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
def object_for(delta, collection)
|
|
200
|
-
kind = KINDS[collection]
|
|
201
|
-
name = delta.path.split(".").last
|
|
202
|
-
object = if delta.path.split(".").size > 2
|
|
203
|
-
# attribute-level delta: the qualified path is the name
|
|
204
|
-
Expressir::Eengine::ModifiedObject.new(
|
|
205
|
-
type: kind, name: delta.path,
|
|
206
|
-
description: "attribute #{delta.op}"
|
|
207
|
-
)
|
|
208
|
-
else
|
|
209
|
-
Expressir::Eengine::ModifiedObject.new(type: kind, name: name)
|
|
210
|
-
end
|
|
211
|
-
object.classif = delta.classification&.value
|
|
212
|
-
object
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
def section_for(operation)
|
|
216
|
-
case operation
|
|
217
|
-
when :added then :additions
|
|
218
|
-
when :removed then :deletions
|
|
219
|
-
else :modifications
|
|
220
|
-
end
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
def kind_of(declaration)
|
|
224
|
-
case declaration
|
|
225
|
-
when Model::Declarations::Entity then "ENTITY"
|
|
226
|
-
when Model::Declarations::Type then "TYPE"
|
|
227
|
-
when Model::Declarations::Function then "FUNCTION"
|
|
228
|
-
when Model::Declarations::Rule then "RULE"
|
|
229
|
-
when Model::Declarations::SubtypeConstraint then "SUBTYPE_CONSTRAINT"
|
|
230
|
-
when Model::Declarations::Constant then "CONSTANT"
|
|
231
|
-
when Model::Declarations::Procedure then "PROCEDURE"
|
|
232
|
-
else declaration.class.name.split("::").last.upcase
|
|
233
|
-
end
|
|
234
|
-
end
|
|
235
113
|
end
|
|
236
114
|
end
|
|
237
115
|
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Expressir
|
|
4
|
+
module Commands
|
|
5
|
+
# `expressir compare-arm-mim` (eengine module-compare parity): the
|
|
6
|
+
# arm.exp and mim.exp pairs compare independently and land in one
|
|
7
|
+
# module.xml-shaped `<changes>` document — `<arm.changes>` /
|
|
8
|
+
# `<mim.changes>` with additions/modifications/deletions sections
|
|
9
|
+
# holding the eengine fragment vocabulary (`<modified.object>` and
|
|
10
|
+
# `<description>`).
|
|
11
|
+
class CompareArmMim < Base
|
|
12
|
+
include Compare::ReportBuilding
|
|
13
|
+
|
|
14
|
+
PREFIXES = %w[arm mim].freeze
|
|
15
|
+
SECTIONS = %w[additions modifications deletions].freeze
|
|
16
|
+
|
|
17
|
+
def run(base_arm_path, revised_arm_path, base_mim_path, revised_mim_path)
|
|
18
|
+
arm = report_pair(base_arm_path, revised_arm_path)
|
|
19
|
+
mim = report_pair(base_mim_path, revised_mim_path)
|
|
20
|
+
xml = serialize(arm, mim)
|
|
21
|
+
if options[:output]
|
|
22
|
+
File.write(options[:output], xml)
|
|
23
|
+
say "changes document written to #{options[:output]}"
|
|
24
|
+
else
|
|
25
|
+
$stdout.write(xml)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Emitted through Moxml directly — same reason as
|
|
30
|
+
# Compare#serialize (lutaml-model's leptris serializer
|
|
31
|
+
# mis-parses dotted element names).
|
|
32
|
+
def serialize(arm, mim)
|
|
33
|
+
ctx = Moxml::Context.new
|
|
34
|
+
doc = ctx.create_document
|
|
35
|
+
root = doc.create_element("changes")
|
|
36
|
+
doc.add_child(root)
|
|
37
|
+
PREFIXES.each do |prefix|
|
|
38
|
+
report = prefix == "arm" ? arm : mim
|
|
39
|
+
SECTIONS.each do |section|
|
|
40
|
+
changes = report.public_send(section)
|
|
41
|
+
node = doc.create_element("#{prefix}.#{section}")
|
|
42
|
+
Array(changes&.modified_objects).each do |obj|
|
|
43
|
+
node.add_child(object_node(doc, obj))
|
|
44
|
+
end
|
|
45
|
+
root.add_child(node)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
doc.to_xml
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -14,7 +14,8 @@ module Expressir
|
|
|
14
14
|
extenders = options[:extenders] == "none" ? :none : :all
|
|
15
15
|
flat = Expressir::Express::Shtolo.new(root, repository,
|
|
16
16
|
longform_name: longform_name,
|
|
17
|
-
extenders: extenders
|
|
17
|
+
extenders: extenders,
|
|
18
|
+
typeof: options[:typeof]).flatten.schema
|
|
18
19
|
text = Expressir::Express::Formatter.format(flat)
|
|
19
20
|
|
|
20
21
|
if options[:output]
|
data/lib/expressir/commands.rb
CHANGED
|
@@ -5,6 +5,7 @@ module Expressir
|
|
|
5
5
|
autoload :Benchmark, "#{__dir__}/commands/benchmark"
|
|
6
6
|
autoload :BenchmarkCache, "#{__dir__}/commands/benchmark_cache"
|
|
7
7
|
autoload :Check, "#{__dir__}/commands/check"
|
|
8
|
+
autoload :CleanupParens, "#{__dir__}/commands/cleanup_parens"
|
|
8
9
|
autoload :Clean, "#{__dir__}/commands/clean"
|
|
9
10
|
autoload :Coverage, "#{__dir__}/commands/coverage"
|
|
10
11
|
autoload :Expand, "#{__dir__}/commands/expand"
|
|
@@ -25,6 +26,7 @@ module Expressir
|
|
|
25
26
|
autoload :Version, "#{__dir__}/commands/version_command"
|
|
26
27
|
autoload :Package, "#{__dir__}/commands/package"
|
|
27
28
|
autoload :Compare, "#{__dir__}/commands/compare"
|
|
29
|
+
autoload :CompareArmMim, "#{__dir__}/commands/compare_arm_mim"
|
|
28
30
|
autoload :Doctor, "#{__dir__}/commands/doctor"
|
|
29
31
|
autoload :Patch, "#{__dir__}/commands/patch"
|
|
30
32
|
autoload :Population, "#{__dir__}/commands/population"
|
|
@@ -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
|
|
@@ -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"
|
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.3
|
|
5
5
|
platform: arm-linux
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-12-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -502,7 +502,10 @@ files:
|
|
|
502
502
|
- lib/expressir/commands/changes_validate.rb
|
|
503
503
|
- lib/expressir/commands/check.rb
|
|
504
504
|
- lib/expressir/commands/clean.rb
|
|
505
|
+
- lib/expressir/commands/cleanup_parens.rb
|
|
505
506
|
- lib/expressir/commands/compare.rb
|
|
507
|
+
- lib/expressir/commands/compare/report_building.rb
|
|
508
|
+
- lib/expressir/commands/compare_arm_mim.rb
|
|
506
509
|
- lib/expressir/commands/coverage.rb
|
|
507
510
|
- lib/expressir/commands/doctor.rb
|
|
508
511
|
- lib/expressir/commands/expand.rb
|
|
@@ -591,6 +594,7 @@ files:
|
|
|
591
594
|
- lib/expressir/express/cache.rb
|
|
592
595
|
- lib/expressir/express/change_classification.rb
|
|
593
596
|
- lib/expressir/express/checker.rb
|
|
597
|
+
- lib/expressir/express/cleanup_parens.rb
|
|
594
598
|
- lib/expressir/express/concatenator.rb
|
|
595
599
|
- lib/expressir/express/core.rb
|
|
596
600
|
- lib/expressir/express/dialect.rb
|