expressir 2.4.41 → 2.4.42
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/.github/workflows/performance-release.yml +124 -0
- data/TODO.compat/00-overview.md +35 -0
- data/TODO.compat/01-interchange-cli.md +34 -0
- data/TODO.compat/02-compat-guide.md +21 -0
- data/TODO.compat/03-scoreboard.md +24 -0
- data/TODO.compat/04-unified-receipt.md +26 -0
- data/TODO.compat/05-p28-configured.md +26 -0
- data/TODO.compat/06-change-classification.md +26 -0
- data/TODO.compat/07-evaluator-matrix.md +22 -0
- data/TODO.compat/08-wasm.md +24 -0
- data/docs/_guides/compat/eval-builtin-matrix.adoc +42 -0
- data/docs/_guides/compat/index.adoc +16 -0
- data/docs/_guides/compat/interchange.adoc +79 -0
- data/docs/_guides/compat/toolchain.adoc +57 -0
- data/docs/_guides/reference/grammar-crosswalk.adoc +1 -0
- data/ext/expressir_core/Cargo.toml +1 -1
- data/lib/expressir/cli.rb +22 -0
- data/lib/expressir/commands/compare.rb +177 -0
- data/lib/expressir/commands/doctor.rb +81 -0
- data/lib/expressir/commands/receipt.rb +30 -0
- data/lib/expressir/commands/validate.rb +7 -0
- data/lib/expressir/commands/validate_remarks.rb +283 -0
- data/lib/expressir/commands.rb +4 -0
- data/lib/expressir/eengine/modified_object.rb +6 -0
- data/lib/expressir/eval/builtin_matrix.rb +83 -0
- data/lib/expressir/eval/interpreter.rb +13 -0
- data/lib/expressir/eval.rb +1 -0
- data/lib/expressir/express/builders/expression_builder.rb +4 -3
- data/lib/expressir/express/change_classification.rb +75 -0
- data/lib/expressir/express/formatters/declarations_formatter.rb +11 -10
- data/lib/expressir/express/grammar/parser.rb +15 -2
- data/lib/expressir/express/parser.rb +16 -0
- data/lib/expressir/express/schema_compare.rb +2 -1
- data/lib/expressir/express.rb +2 -0
- data/lib/expressir/p28/configuration.rb +124 -0
- data/lib/expressir/p28/xsd.rb +73 -32
- data/lib/expressir/p28.rb +1 -0
- data/lib/expressir/receipt.rb +237 -0
- data/lib/expressir/reference/grammar_crosswalk.yml +4 -0
- data/lib/expressir/scoreboard.rb +151 -0
- data/lib/expressir/version.rb +1 -1
- data/lib/expressir.rb +2 -0
- data/lib/tasks/scoreboard.rake +59 -0
- data/scoreboard-baseline.json +7 -0
- metadata +27 -2
data/lib/expressir/p28/xsd.rb
CHANGED
|
@@ -101,11 +101,16 @@ module Expressir
|
|
|
101
101
|
# @param target_namespace [String] the 7.7.2 namespace URI
|
|
102
102
|
# @param prefix [String] the preprocessor-chosen target-namespace
|
|
103
103
|
# prefix (7.7.1)
|
|
104
|
+
# @param configuration [Configuration] clause 8 directives over
|
|
105
|
+
# the default binding (naming convention, target namespace,
|
|
106
|
+
# explicit renames)
|
|
104
107
|
# @return [String] the serialized derived XML schema
|
|
105
|
-
def format(schema, target_namespace:
|
|
108
|
+
def format(schema, target_namespace: nil,
|
|
106
109
|
prefix: Uos.default_prefix(schema),
|
|
107
110
|
base_schema_location: "iso-10303-28-base.xsd",
|
|
108
|
-
inline_base: false)
|
|
111
|
+
inline_base: false, configuration: Configuration.empty)
|
|
112
|
+
target_namespace ||= configuration.target_namespace ||
|
|
113
|
+
P28.default_target_namespace(schema.id)
|
|
109
114
|
ctx = Moxml::Context.new
|
|
110
115
|
doc = ctx.create_document
|
|
111
116
|
root = doc.create_element("xs:schema")
|
|
@@ -128,13 +133,15 @@ module Expressir
|
|
|
128
133
|
root.add_child(import_node(doc, COMMON_NS, base_schema_location))
|
|
129
134
|
end
|
|
130
135
|
schema.types.to_a.each do |type|
|
|
131
|
-
node = defined_type_node(doc, schema, prefix, type, inline_base
|
|
136
|
+
node = defined_type_node(doc, schema, prefix, type, inline_base,
|
|
137
|
+
configuration)
|
|
132
138
|
root.add_child(node) if node
|
|
133
139
|
end
|
|
134
140
|
schema.entities.to_a.each do |entity|
|
|
135
141
|
root.add_child(entity_type_node(doc, schema, prefix, entity,
|
|
136
|
-
inline_base))
|
|
137
|
-
root.add_child(entity_element_node(doc, prefix, entity, inline_base
|
|
142
|
+
inline_base, configuration))
|
|
143
|
+
root.add_child(entity_element_node(doc, prefix, entity, inline_base,
|
|
144
|
+
configuration))
|
|
138
145
|
end
|
|
139
146
|
uos_node(doc, schema, prefix, inline_base).each do |node|
|
|
140
147
|
root.add_child(node)
|
|
@@ -252,17 +259,39 @@ module Expressir
|
|
|
252
259
|
node
|
|
253
260
|
end
|
|
254
261
|
|
|
255
|
-
# 7.1.2 identifier mapping
|
|
256
|
-
|
|
257
|
-
|
|
262
|
+
# 7.1.2 identifier mapping, configured per clause 8: the
|
|
263
|
+
# naming-convention (initial-upper default) then the explicit
|
|
264
|
+
# rename, looked up by kind ("types", "entities") and pair
|
|
265
|
+
# ("Entity.attr" for attributes).
|
|
266
|
+
def mapped(express_id, config = nil, kind = nil, scope: nil)
|
|
267
|
+
base = case config&.naming_convention
|
|
268
|
+
when "camel-case"
|
|
269
|
+
express_id.to_s.split("_").each_with_index.map do |part, i|
|
|
270
|
+
i.zero? ? part : part.sub(/\A./, &:upcase)
|
|
271
|
+
end.join
|
|
272
|
+
when "preserve-case"
|
|
273
|
+
express_id.to_s
|
|
274
|
+
else
|
|
275
|
+
express_id.to_s.sub(/\A./, &:upcase)
|
|
276
|
+
end
|
|
277
|
+
return base if config.nil?
|
|
278
|
+
|
|
279
|
+
renamed =
|
|
280
|
+
case kind
|
|
281
|
+
when :type then config.scopes.types[express_id.to_s]
|
|
282
|
+
when :entity then config.scopes.entities[express_id.to_s]
|
|
283
|
+
when :attribute then config.scopes.attributes[scope]
|
|
284
|
+
end
|
|
285
|
+
renamed || base
|
|
258
286
|
end
|
|
259
287
|
|
|
260
288
|
# 7.3: defined types over simple/enum/aggregates.
|
|
261
|
-
def defined_type_node(doc, schema, prefix, type, inline)
|
|
289
|
+
def defined_type_node(doc, schema, prefix, type, inline, config = nil)
|
|
262
290
|
underlying = type.underlying_type
|
|
263
291
|
case kind_of(schema, underlying)
|
|
264
292
|
when :enumeration
|
|
265
|
-
simple_type_node(doc, prefix, type.id,
|
|
293
|
+
simple_type_node(doc, prefix, mapped(type.id, config, :type),
|
|
294
|
+
"xs:string") do |restriction|
|
|
266
295
|
underlying.items.to_a.each do |item|
|
|
267
296
|
facet = doc.create_element("xs:enumeration")
|
|
268
297
|
facet.set_attributes("value" => item.id.to_s)
|
|
@@ -270,16 +299,17 @@ module Expressir
|
|
|
270
299
|
end
|
|
271
300
|
end
|
|
272
301
|
when :simple
|
|
273
|
-
simple_type_node(doc, prefix, type.id,
|
|
302
|
+
simple_type_node(doc, prefix, mapped(type.id, config, :type),
|
|
274
303
|
simple_type_name(schema, underlying, inline))
|
|
275
304
|
when :aggregate
|
|
276
|
-
list_type_node(doc, schema, prefix, type.id, underlying, inline
|
|
305
|
+
list_type_node(doc, schema, prefix, type.id, underlying, inline,
|
|
306
|
+
config)
|
|
277
307
|
end
|
|
278
308
|
end
|
|
279
309
|
|
|
280
310
|
def simple_type_node(doc, _prefix, express_id, base)
|
|
281
311
|
node = doc.create_element("xs:simpleType")
|
|
282
|
-
node.set_attributes("name" =>
|
|
312
|
+
node.set_attributes("name" => express_id.to_s)
|
|
283
313
|
restriction = doc.create_element("xs:restriction")
|
|
284
314
|
restriction.set_attributes("base" => base)
|
|
285
315
|
node.add_child(restriction)
|
|
@@ -291,28 +321,33 @@ module Expressir
|
|
|
291
321
|
|
|
292
322
|
# 7.3.2/8.2.2.3: aggregates of simple base types derive from
|
|
293
323
|
# xs:list over the base's item type.
|
|
294
|
-
def list_type_node(doc, schema, _prefix, express_id, aggregate, inline
|
|
324
|
+
def list_type_node(doc, schema, _prefix, express_id, aggregate, inline,
|
|
325
|
+
config = nil)
|
|
295
326
|
node = doc.create_element("xs:simpleType")
|
|
296
|
-
node.set_attributes("name" => mapped(express_id))
|
|
327
|
+
node.set_attributes("name" => mapped(express_id, config, :type))
|
|
297
328
|
list = doc.create_element("xs:list")
|
|
298
329
|
base = aggregate.base_type
|
|
299
|
-
list.set_attributes(
|
|
330
|
+
list.set_attributes(
|
|
331
|
+
"itemType" => simple_type_name(schema, base, inline, config),
|
|
332
|
+
)
|
|
300
333
|
node.add_child(list)
|
|
301
334
|
node
|
|
302
335
|
end
|
|
303
336
|
|
|
304
337
|
# 7.6.4: extension of exp:Entity, xs:all over the closure
|
|
305
338
|
# union, abstract per ABSTRACT SUPERTYPE.
|
|
306
|
-
def entity_type_node(doc, schema, prefix, entity, inline)
|
|
339
|
+
def entity_type_node(doc, schema, prefix, entity, inline, config = nil)
|
|
307
340
|
node = doc.create_element("xs:complexType")
|
|
308
|
-
node.set_attributes("name" => mapped(entity.id))
|
|
341
|
+
node.set_attributes("name" => mapped(entity.id, config, :entity))
|
|
309
342
|
node.set_attributes("abstract" => "true") if entity.abstract
|
|
310
343
|
content = doc.create_element("xs:complexContent")
|
|
311
344
|
extension = doc.create_element("xs:extension")
|
|
312
345
|
extension.set_attributes("base" => exp_name("Entity", inline, prefix))
|
|
313
346
|
all_node = doc.create_element("xs:all")
|
|
314
347
|
closure_attributes(entity).each do |attribute|
|
|
315
|
-
|
|
348
|
+
scope = "#{entity.id}.#{attribute.id}"
|
|
349
|
+
accessor = accessor_node(doc, schema, prefix, attribute, inline,
|
|
350
|
+
config, scope)
|
|
316
351
|
all_node.add_child(accessor) if accessor
|
|
317
352
|
end
|
|
318
353
|
extension.add_child(all_node)
|
|
@@ -323,11 +358,12 @@ module Expressir
|
|
|
323
358
|
|
|
324
359
|
# 7.6.5: the global instance element, in the exp:Entity
|
|
325
360
|
# substitution group.
|
|
326
|
-
def entity_element_node(doc, prefix, entity, inline)
|
|
361
|
+
def entity_element_node(doc, prefix, entity, inline, config = nil)
|
|
362
|
+
name = mapped(entity.id, config, :entity)
|
|
327
363
|
node = doc.create_element("xs:element")
|
|
328
364
|
node.set_attributes(
|
|
329
|
-
"name" =>
|
|
330
|
-
"type" => "#{prefix}:#{
|
|
365
|
+
"name" => name,
|
|
366
|
+
"type" => "#{prefix}:#{name}",
|
|
331
367
|
"substitutionGroup" => exp_name("Entity", inline, prefix),
|
|
332
368
|
)
|
|
333
369
|
node
|
|
@@ -336,19 +372,22 @@ module Expressir
|
|
|
336
372
|
# 7.6.3: one accessor element per mapped attribute; OPTIONAL
|
|
337
373
|
# attributes are minOccurs="0"; aggregates carry their
|
|
338
374
|
# occurrence bounds.
|
|
339
|
-
def accessor_node(doc, schema, prefix, attribute, inline
|
|
375
|
+
def accessor_node(doc, schema, prefix, attribute, inline, config = nil,
|
|
376
|
+
scope = nil)
|
|
340
377
|
type = attribute.type
|
|
341
378
|
optional = attribute.respond_to?(:optional) && attribute.optional
|
|
342
379
|
kind = kind_of(schema, type)
|
|
343
380
|
node = doc.create_element("xs:element")
|
|
344
|
-
node.set_attributes("name" => mapped(attribute.id
|
|
381
|
+
node.set_attributes("name" => mapped(attribute.id, config, :attribute,
|
|
382
|
+
scope: scope))
|
|
345
383
|
node.set_attributes("minOccurs" => "0") if optional
|
|
346
384
|
case kind
|
|
347
385
|
when :entity
|
|
348
386
|
target = entity_id_of(schema, type)
|
|
349
|
-
node.set_attributes("type" => "#{prefix}:#{mapped(target)}")
|
|
387
|
+
node.set_attributes("type" => "#{prefix}:#{mapped(target, config, :entity)}")
|
|
350
388
|
when :entity_aggregate
|
|
351
|
-
node.add_child(aggregate_content_node(doc, schema, prefix, type
|
|
389
|
+
node.add_child(aggregate_content_node(doc, schema, prefix, type,
|
|
390
|
+
config))
|
|
352
391
|
when :aggregate
|
|
353
392
|
node.add_child(inline_list_node(doc, schema, type, inline))
|
|
354
393
|
when :select
|
|
@@ -356,7 +395,8 @@ module Expressir
|
|
|
356
395
|
"SELECT accessor '#{attribute.id}' is outside the v1 " \
|
|
357
396
|
"default derivation (TODO.p28/03 boundary)"
|
|
358
397
|
else
|
|
359
|
-
node.set_attributes("type" => simple_type_name(schema, type, inline
|
|
398
|
+
node.set_attributes("type" => simple_type_name(schema, type, inline,
|
|
399
|
+
config))
|
|
360
400
|
end
|
|
361
401
|
node
|
|
362
402
|
end
|
|
@@ -375,15 +415,16 @@ module Expressir
|
|
|
375
415
|
# Aggregates of entity base: the accessor wraps unqualified
|
|
376
416
|
# component elements typed by the component entity (9.2.6.1
|
|
377
417
|
# worked example shape).
|
|
378
|
-
def aggregate_content_node(doc, schema, prefix, aggregate)
|
|
418
|
+
def aggregate_content_node(doc, schema, prefix, aggregate, config = nil)
|
|
379
419
|
base = aggregate.base_type
|
|
380
420
|
target = entity_id_of(schema, base)
|
|
421
|
+
name = mapped(target, config, :entity)
|
|
381
422
|
content = doc.create_element("xs:complexType")
|
|
382
423
|
sequence = doc.create_element("xs:sequence")
|
|
383
424
|
component = doc.create_element("xs:element")
|
|
384
425
|
component.set_attributes(
|
|
385
|
-
"name" =>
|
|
386
|
-
"type" => "#{prefix}:#{
|
|
426
|
+
"name" => name,
|
|
427
|
+
"type" => "#{prefix}:#{name}",
|
|
387
428
|
"minOccurs" => "0",
|
|
388
429
|
"maxOccurs" => "unbounded",
|
|
389
430
|
)
|
|
@@ -502,7 +543,7 @@ module Expressir
|
|
|
502
543
|
end
|
|
503
544
|
|
|
504
545
|
# 7.2.1: the XML Schema data type for a simple/defined face.
|
|
505
|
-
def simple_type_name(_schema, type, inline)
|
|
546
|
+
def simple_type_name(_schema, type, inline, config = nil)
|
|
506
547
|
case type
|
|
507
548
|
when Model::DataTypes::Boolean then "xs:boolean"
|
|
508
549
|
when Model::DataTypes::Logical then exp_name("logical", inline)
|
|
@@ -518,7 +559,7 @@ module Expressir
|
|
|
518
559
|
return "xs:string" # xs:list-derived aggregate
|
|
519
560
|
end
|
|
520
561
|
|
|
521
|
-
mapped(type_id(type)).to_s
|
|
562
|
+
mapped(type_id(type), config, :type).to_s
|
|
522
563
|
end
|
|
523
564
|
end
|
|
524
565
|
end
|
data/lib/expressir/p28.rb
CHANGED
|
@@ -5,6 +5,7 @@ module Expressir
|
|
|
5
5
|
autoload :Uos, "#{__dir__}/p28/uos"
|
|
6
6
|
autoload :Xsd, "#{__dir__}/p28/xsd"
|
|
7
7
|
autoload :Document, "#{__dir__}/p28/document"
|
|
8
|
+
autoload :Configuration, "#{__dir__}/p28/configuration"
|
|
8
9
|
|
|
9
10
|
# ISO 10303-28:2007 XML representation of EXPRESS-driven data.
|
|
10
11
|
#
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "digest"
|
|
5
|
+
|
|
6
|
+
module Expressir
|
|
7
|
+
# The unified repository receipt (TODO.compat/04): one deterministic,
|
|
8
|
+
# signing-ready canonical-JSON artifact binding the three shipped
|
|
9
|
+
# validators — schema (Checker), instance datasets (P21) and module
|
|
10
|
+
# mappings (Mapping) — with input digests, generator version and
|
|
11
|
+
# per-rule verdicts. Same manifest + same inputs → byte-identical
|
|
12
|
+
# receipt; signatures cover the canonical serialization.
|
|
13
|
+
module Receipt
|
|
14
|
+
CANONICALIZATION =
|
|
15
|
+
"canonical JSON: recursively sorted object keys, UTF-8, " \
|
|
16
|
+
"no insignificant whitespace; signatures cover these bytes"
|
|
17
|
+
|
|
18
|
+
# The workspace manifest: one file driving one receipt. Paths are
|
|
19
|
+
# resolved against the manifest's directory.
|
|
20
|
+
class WorkspaceManifest < Lutaml::Model::Serializable
|
|
21
|
+
attribute :schema_files, :string, collection: true
|
|
22
|
+
attribute :dialect, :string
|
|
23
|
+
attribute :datasets, :string, collection: true
|
|
24
|
+
attribute :mappings, :string, collection: true
|
|
25
|
+
|
|
26
|
+
key_value do
|
|
27
|
+
map "schema_files", to: :schema_files
|
|
28
|
+
map "dialect", to: :dialect
|
|
29
|
+
map "datasets", to: :datasets
|
|
30
|
+
map "mappings", to: :mappings
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
class << self
|
|
34
|
+
def from_file(path)
|
|
35
|
+
manifest = from_yaml(File.read(path))
|
|
36
|
+
manifest.base_dir = File.dirname(File.expand_path(path))
|
|
37
|
+
manifest.validate_entries!
|
|
38
|
+
manifest
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
attr_accessor :base_dir
|
|
43
|
+
|
|
44
|
+
def validate_entries!
|
|
45
|
+
return if Array(schema_files).any?
|
|
46
|
+
|
|
47
|
+
raise Expressir::ManifestValidationError,
|
|
48
|
+
"workspace manifest lists no schema_files"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def resolve(path)
|
|
52
|
+
File.expand_path(path, base_dir || ".")
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def schema_paths
|
|
56
|
+
Array(schema_files).map { |f| resolve(f) }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def dataset_paths
|
|
60
|
+
Array(datasets).map { |f| resolve(f) }
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def mapping_paths
|
|
64
|
+
Array(mappings).map { |f| resolve(f) }
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
module_function
|
|
69
|
+
|
|
70
|
+
# Canonical serialization: sort every object's keys recursively.
|
|
71
|
+
# Values are scalars, arrays and string-keyed objects only, so the
|
|
72
|
+
# sort is total and the bytes are reproducible.
|
|
73
|
+
def canonicalize(value)
|
|
74
|
+
case value
|
|
75
|
+
when Hash
|
|
76
|
+
value.sort.to_h.transform_values { |v| canonicalize(v) }
|
|
77
|
+
when Array
|
|
78
|
+
value.map { |item| canonicalize(item) }
|
|
79
|
+
else
|
|
80
|
+
value
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def generate(payload)
|
|
85
|
+
JSON.generate(canonicalize(payload))
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def digest(path)
|
|
89
|
+
Digest::SHA256.hexdigest(File.binread(path))
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# Manifest-relative, slash-normalized keys keep the receipt
|
|
93
|
+
# byte-identical across checkouts.
|
|
94
|
+
def rel_path(path, base_dir)
|
|
95
|
+
path = File.expand_path(path)
|
|
96
|
+
base = File.expand_path(base_dir)
|
|
97
|
+
rel = path.delete_prefix("#{base}/")
|
|
98
|
+
rel.start_with?("/") ? path : rel
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def schema_section(manifest)
|
|
102
|
+
files = manifest.schema_paths.sort
|
|
103
|
+
repository = Expressir::Express::Parser.from_files(files)
|
|
104
|
+
result = Expressir::Express::Checker.new(
|
|
105
|
+
repository, dialect: manifest.dialect
|
|
106
|
+
).check
|
|
107
|
+
notes = result.notes.map do |note|
|
|
108
|
+
{
|
|
109
|
+
"id" => note.id.to_s,
|
|
110
|
+
"severity" => note.severity.to_s,
|
|
111
|
+
"schema" => note.schema&.id.to_s,
|
|
112
|
+
"message" => note.message,
|
|
113
|
+
}
|
|
114
|
+
end
|
|
115
|
+
{
|
|
116
|
+
"valid" => result.valid?,
|
|
117
|
+
"notes" => notes,
|
|
118
|
+
"errors" => notes.count { |n| n["severity"] == "error" },
|
|
119
|
+
"warnings" => notes.count { |n| n["severity"] == "warning" },
|
|
120
|
+
}
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def dataset_section(manifest_path)
|
|
124
|
+
dataset = Expressir::P21::DatasetManifest.from_file(manifest_path)
|
|
125
|
+
schema = Expressir::Express::Parser.from_file(dataset.schema_path).schemas.first
|
|
126
|
+
files = dataset.file_paths.sort.map do |path|
|
|
127
|
+
population = Expressir::P21::Parser.parse(File.read(path))
|
|
128
|
+
notes = Expressir::P21::Validator.validate(
|
|
129
|
+
population, schema, short_names: dataset.short_name_map
|
|
130
|
+
)
|
|
131
|
+
{
|
|
132
|
+
"path" => File.basename(path),
|
|
133
|
+
"digest" => digest(path),
|
|
134
|
+
"notes" => notes.map do |note|
|
|
135
|
+
{
|
|
136
|
+
"id" => note.id.to_s,
|
|
137
|
+
"severity" => note.severity.to_s,
|
|
138
|
+
"instance" => note.instance,
|
|
139
|
+
"message" => note.message,
|
|
140
|
+
}
|
|
141
|
+
end,
|
|
142
|
+
}
|
|
143
|
+
end
|
|
144
|
+
{
|
|
145
|
+
"manifest" => File.basename(manifest_path),
|
|
146
|
+
"manifest_digest" => digest(manifest_path),
|
|
147
|
+
"release" => dataset.release.to_s,
|
|
148
|
+
"schema" => dataset.schema.to_s,
|
|
149
|
+
"files" => files,
|
|
150
|
+
"errors" => files.sum { |f| f["notes"].count { |n| n["severity"] == "error" } },
|
|
151
|
+
"warnings" => files.sum { |f| f["notes"].count { |n| n["severity"] == "warning" } },
|
|
152
|
+
}
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def mapping_section(manifest, manifest_path)
|
|
156
|
+
document = Expressir::Mapping.load_file(manifest_path)
|
|
157
|
+
repository = mapping_repository(manifest_path)
|
|
158
|
+
unknown = Expressir::Mapping.unknown_links(document, repository)
|
|
159
|
+
issues = mapping_refpath_issues(document, repository)
|
|
160
|
+
rules = Expressir::Mapping.rule_issues(document, repository)
|
|
161
|
+
{
|
|
162
|
+
"file" => rel_path(manifest_path, manifest.base_dir),
|
|
163
|
+
"valid" => [unknown, issues, rules].all?(&:empty?),
|
|
164
|
+
"unknown_links" => unknown.map(&:text).sort,
|
|
165
|
+
"refpath_issues" => issues.map do |location, issue|
|
|
166
|
+
"refpath #{location} [step #{issue.step}]: #{issue.message}"
|
|
167
|
+
end.sort,
|
|
168
|
+
"unknown_rules" => rules.map(&:text).sort,
|
|
169
|
+
}
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def mapping_refpath_issues(document, repository)
|
|
173
|
+
Expressir::Mapping.refpaths(document).flat_map do |location, content|
|
|
174
|
+
parsed = Expressir::Mapping::RefPath.parse(content)
|
|
175
|
+
start = Expressir::Mapping.entity_item(location)
|
|
176
|
+
parsed.parse_errors.map do |error|
|
|
177
|
+
[location, Expressir::Mapping::RefPath::Issue.new(step: nil, message: error)]
|
|
178
|
+
end + Expressir::Mapping::RefPath.validate(parsed, repository,
|
|
179
|
+
start: start)
|
|
180
|
+
.map { |issue| [location, issue] }
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
# The ARM/MIM closure next to the mapping file — the same contract
|
|
185
|
+
# as `mapping_validate`.
|
|
186
|
+
def mapping_repository(manifest_path)
|
|
187
|
+
dir = File.dirname(File.expand_path(manifest_path))
|
|
188
|
+
arm = Dir[File.join(dir, "arm.exp")].first
|
|
189
|
+
mim = Dir[File.join(dir, "mim.exp")].first
|
|
190
|
+
roots = [arm, mim].compact
|
|
191
|
+
if roots.empty?
|
|
192
|
+
raise Expressir::ManifestValidationError,
|
|
193
|
+
"no arm.exp/mim.exp next to #{manifest_path}"
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
Expressir::Express::Parser.from_files(roots)
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def build(manifest)
|
|
200
|
+
datasets = manifest.dataset_paths.sort.map { |p| dataset_section(p) }
|
|
201
|
+
mappings = manifest.mapping_paths.sort.map { |p| mapping_section(manifest, p) }
|
|
202
|
+
schema = schema_section(manifest)
|
|
203
|
+
errors = schema["errors"] +
|
|
204
|
+
datasets.sum { |d| d["errors"] } +
|
|
205
|
+
mappings.count { |m| !m["valid"] }
|
|
206
|
+
warnings = schema["warnings"] + datasets.sum { |d| d["warnings"] }
|
|
207
|
+
|
|
208
|
+
{
|
|
209
|
+
"artifact" => "expressir-receipt",
|
|
210
|
+
"format" => 1,
|
|
211
|
+
"generator" => { "expressir" => Expressir::VERSION },
|
|
212
|
+
"canonicalization" => CANONICALIZATION,
|
|
213
|
+
"inputs" => {
|
|
214
|
+
"schema_files" => manifest.schema_paths.sort.to_h do |path|
|
|
215
|
+
[rel_path(path, manifest.base_dir), digest(path)]
|
|
216
|
+
end,
|
|
217
|
+
"datasets" => datasets.map do |d|
|
|
218
|
+
{ "manifest" => d["manifest"], "manifest_digest" => d["manifest_digest"] }
|
|
219
|
+
end,
|
|
220
|
+
"mappings" => mappings.map do |m|
|
|
221
|
+
{ "file" => m["file"], "digest" => digest(File.join(manifest.base_dir, m["file"])) }
|
|
222
|
+
end,
|
|
223
|
+
},
|
|
224
|
+
"verdicts" => {
|
|
225
|
+
"schema" => schema,
|
|
226
|
+
"datasets" => datasets,
|
|
227
|
+
"mappings" => mappings,
|
|
228
|
+
},
|
|
229
|
+
"summary" => {
|
|
230
|
+
"valid" => errors.zero?,
|
|
231
|
+
"errors" => errors,
|
|
232
|
+
"warnings" => warnings,
|
|
233
|
+
},
|
|
234
|
+
}
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
end
|
|
@@ -176,6 +176,10 @@ rules:
|
|
|
176
176
|
- rule: entityHead
|
|
177
177
|
production: entity_head
|
|
178
178
|
status: aligned
|
|
179
|
+
- rule: entityHeaderTail
|
|
180
|
+
status: internal
|
|
181
|
+
note: trivia and the optional delimiter after the entity name, split
|
|
182
|
+
out of entityHead so the header tail is atomic (issue #537)
|
|
179
183
|
- rule: entityId
|
|
180
184
|
production: entity_id
|
|
181
185
|
status: aligned
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "benchmark"
|
|
4
|
+
require "json"
|
|
5
|
+
require "tmpdir"
|
|
6
|
+
require "fileutils"
|
|
7
|
+
|
|
8
|
+
module Expressir
|
|
9
|
+
# The per-command scoreboard (TODO.compat/03): interleaved CPU-time
|
|
10
|
+
# medians per measured command, published per release and gated
|
|
11
|
+
# against a committed baseline (`rake scoreboard:gate`).
|
|
12
|
+
#
|
|
13
|
+
# Lanes: the two shipped parse engines (native core, Ruby grammar)
|
|
14
|
+
# for the parse row; single-lane rows for the composite commands
|
|
15
|
+
# (compare, population validate, flatten). Optional cross-tool rows
|
|
16
|
+
# activate when a reference binary is provided via the environment.
|
|
17
|
+
module Scoreboard
|
|
18
|
+
REPS = 9
|
|
19
|
+
|
|
20
|
+
# CPU time where the platform provides it (Windows Ruby carries no
|
|
21
|
+
# CLOCK_PROCESS_CPUTIME_ID — monotonic keeps the gate usable).
|
|
22
|
+
CLOCK = if Process.const_defined?(:CLOCK_PROCESS_CPUTIME_ID)
|
|
23
|
+
Process::CLOCK_PROCESS_CPUTIME_ID
|
|
24
|
+
else
|
|
25
|
+
Process::CLOCK_MONOTONIC
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
module_function
|
|
29
|
+
|
|
30
|
+
# @return [Hash] command => { reps:, cpu: [median seconds] }
|
|
31
|
+
def run(reps: REPS, warmup: 1)
|
|
32
|
+
prepare_fixtures
|
|
33
|
+
rows = {}
|
|
34
|
+
rows["parse (native)"] = measure(warmup, reps) { native_parse }
|
|
35
|
+
rows["parse (ruby)"] = measure(warmup, reps) { ruby_parse }
|
|
36
|
+
rows["compare"] = measure(warmup, reps) { run_compare }
|
|
37
|
+
rows["validate"] = measure(warmup, reps) { run_validate }
|
|
38
|
+
rows["flatten"] = measure(warmup, reps) { run_flatten }
|
|
39
|
+
rows
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def table(rows)
|
|
43
|
+
lines = ["| Row | CPU median (s) |", "| --- | --- |"]
|
|
44
|
+
rows.each { |row, cpu| lines << "| #{row} | #{format('%.4f', cpu)} |" }
|
|
45
|
+
lines.join("\n")
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def median(values)
|
|
49
|
+
sorted = values.sort
|
|
50
|
+
mid = sorted.length / 2
|
|
51
|
+
sorted.length.odd? ? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / 2.0
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def measure(warmup, reps, &)
|
|
55
|
+
warmup.times(&)
|
|
56
|
+
cpu = []
|
|
57
|
+
reps.times do
|
|
58
|
+
t0 = Process.clock_gettime(CLOCK)
|
|
59
|
+
yield
|
|
60
|
+
cpu << (Process.clock_gettime(CLOCK) - t0)
|
|
61
|
+
end
|
|
62
|
+
median(cpu)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def prepare_fixtures
|
|
66
|
+
dir = File.join(Dir.tmpdir, "expressir-scoreboard")
|
|
67
|
+
FileUtils.mkdir_p(dir)
|
|
68
|
+
@schema_path = File.join(dir, "scoreboard.exp")
|
|
69
|
+
File.write(@schema_path, SCOREBOARD_SCHEMA)
|
|
70
|
+
@base_path = File.join(dir, "base.exp")
|
|
71
|
+
File.write(@base_path, SCOREBOARD_SCHEMA)
|
|
72
|
+
@revised_path = File.join(dir, "revised.exp")
|
|
73
|
+
File.write(@revised_path, SCOREBOARD_SCHEMA_REVISED)
|
|
74
|
+
@p21_path = File.join(dir, "scoreboard.p21")
|
|
75
|
+
File.write(@p21_path, SCOREBOARD_P21)
|
|
76
|
+
@schema_path
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def native_parse
|
|
80
|
+
Expressir::Express::Parser.from_file(@schema_path, use_native: true,
|
|
81
|
+
skip_references: true)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def ruby_parse
|
|
85
|
+
Expressir::Express::Parser.from_file(@schema_path, use_native: false,
|
|
86
|
+
skip_references: true)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def run_compare
|
|
90
|
+
base = Expressir::Express::Parser.from_exp(SCOREBOARD_SCHEMA,
|
|
91
|
+
skip_references: true).schemas.first
|
|
92
|
+
revised = Expressir::Express::Parser.from_exp(SCOREBOARD_SCHEMA_REVISED,
|
|
93
|
+
skip_references: true).schemas.first
|
|
94
|
+
Expressir::Express::SchemaCompare.compare(base, revised)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def run_validate
|
|
98
|
+
population = Expressir::P21::Parser.parse(SCOREBOARD_P21)
|
|
99
|
+
schema = Expressir::Express::Parser.from_exp(SCOREBOARD_SCHEMA,
|
|
100
|
+
skip_references: true).schemas.first
|
|
101
|
+
Expressir::P21::Validator.validate(population, schema)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def run_flatten
|
|
105
|
+
repo = Expressir::Express::Parser.from_file(@schema_path, skip_references: true)
|
|
106
|
+
schema = repo.schemas.first
|
|
107
|
+
Expressir::Express::Shtolo.new(schema, repo).flatten if schema
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
SCOREBOARD_SCHEMA = <<~EXPRESS
|
|
111
|
+
SCHEMA scoreboard;
|
|
112
|
+
ENTITY point;
|
|
113
|
+
x : REAL;
|
|
114
|
+
y : REAL;
|
|
115
|
+
END_ENTITY;
|
|
116
|
+
ENTITY colour;
|
|
117
|
+
name : STRING;
|
|
118
|
+
END_ENTITY;
|
|
119
|
+
END_SCHEMA;
|
|
120
|
+
EXPRESS
|
|
121
|
+
|
|
122
|
+
SCOREBOARD_SCHEMA_REVISED = <<~EXPRESS
|
|
123
|
+
SCHEMA scoreboard;
|
|
124
|
+
ENTITY point;
|
|
125
|
+
x : REAL;
|
|
126
|
+
y : REAL;
|
|
127
|
+
z : REAL;
|
|
128
|
+
END_ENTITY;
|
|
129
|
+
ENTITY colour;
|
|
130
|
+
name : STRING;
|
|
131
|
+
END_ENTITY;
|
|
132
|
+
ENTITY marker;
|
|
133
|
+
at : point;
|
|
134
|
+
END_ENTITY;
|
|
135
|
+
END_SCHEMA;
|
|
136
|
+
EXPRESS
|
|
137
|
+
|
|
138
|
+
SCOREBOARD_P21 = <<~P21
|
|
139
|
+
ISO-10303-21;
|
|
140
|
+
HEADER;
|
|
141
|
+
FILE_NAME('sb','2026-10-23T00:00:00',(''),(''),'','','');
|
|
142
|
+
FILE_SCHEMA(('SCOREBOARD'));
|
|
143
|
+
ENDSEC;
|
|
144
|
+
DATA;
|
|
145
|
+
#1=POINT(1.0,2.0);
|
|
146
|
+
#2=POINT(3.0,4.0);
|
|
147
|
+
ENDSEC;
|
|
148
|
+
END-ISO-10303-21;
|
|
149
|
+
P21
|
|
150
|
+
end
|
|
151
|
+
end
|
data/lib/expressir/version.rb
CHANGED
data/lib/expressir.rb
CHANGED
|
@@ -32,6 +32,7 @@ module Expressir
|
|
|
32
32
|
autoload :Mapping, "#{__dir__}/expressir/mapping"
|
|
33
33
|
autoload :P21, "#{__dir__}/expressir/p21"
|
|
34
34
|
autoload :P28, "#{__dir__}/expressir/p28"
|
|
35
|
+
autoload :Receipt, "#{__dir__}/expressir/receipt"
|
|
35
36
|
autoload :Reference, "#{__dir__}/expressir/reference"
|
|
36
37
|
|
|
37
38
|
# Error classes — autoload the same errors.rb file from each name.
|
|
@@ -71,6 +72,7 @@ module Expressir
|
|
|
71
72
|
end
|
|
72
73
|
|
|
73
74
|
autoload :Benchmark, "#{__dir__}/expressir/benchmark"
|
|
75
|
+
autoload :Scoreboard, "#{__dir__}/expressir/scoreboard"
|
|
74
76
|
autoload :Coverage, "#{__dir__}/expressir/coverage"
|
|
75
77
|
|
|
76
78
|
autoload :Express, "#{__dir__}/expressir/express"
|