expressir 2.4.41-arm-linux → 2.4.42-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/.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/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 +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
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Expressir
|
|
4
|
+
module Commands
|
|
5
|
+
# `expressir compare` (TODO.compat/01): compare two EXPRESS files
|
|
6
|
+
# and emit the `schema.changes` interchange report — the format
|
|
7
|
+
# the `changes` importer reads, so comparison data flows both ways
|
|
8
|
+
# across toolchains.
|
|
9
|
+
class Compare < Base
|
|
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 run(base_path, revised_path)
|
|
21
|
+
base_repo = Expressir::Express::Parser.from_file(base_path)
|
|
22
|
+
revised_repo = Expressir::Express::Parser.from_file(revised_path)
|
|
23
|
+
report = build_report(base_repo, revised_repo)
|
|
24
|
+
xml = serialize(report)
|
|
25
|
+
if options[:output]
|
|
26
|
+
File.write(options[:output], xml)
|
|
27
|
+
say "report written to #{options[:output]}"
|
|
28
|
+
else
|
|
29
|
+
$stdout.write(xml)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Emitted through Moxml directly: lutaml-model's leptris-backed
|
|
34
|
+
# serializer mis-parses the interchange's dotted element names
|
|
35
|
+
# ("schema.changes") as namespace prefixes and fails the build
|
|
36
|
+
# (same upstream family as lutaml-model#997). The model layer
|
|
37
|
+
# stays lutaml-model; the XML face is Moxml.
|
|
38
|
+
def serialize(report)
|
|
39
|
+
ctx = Moxml::Context.new
|
|
40
|
+
doc = ctx.create_document
|
|
41
|
+
root = doc.create_element("schema.changes")
|
|
42
|
+
doc.add_child(root)
|
|
43
|
+
{
|
|
44
|
+
"schema.additions" => report.additions,
|
|
45
|
+
"schema.deletions" => report.deletions,
|
|
46
|
+
"schema.modifications" => report.modifications,
|
|
47
|
+
}.each do |name, section|
|
|
48
|
+
root.add_child(section_node(doc, name, section))
|
|
49
|
+
end
|
|
50
|
+
doc.to_xml
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def section_node(doc, name, section)
|
|
54
|
+
node = doc.create_element(name)
|
|
55
|
+
Array(section&.modified_objects).each do |obj|
|
|
56
|
+
node.add_child(object_node(doc, obj))
|
|
57
|
+
end
|
|
58
|
+
node
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def object_node(doc, obj)
|
|
62
|
+
node = doc.create_element("modified.object")
|
|
63
|
+
attrs = { "type" => obj.type, "name" => obj.name }
|
|
64
|
+
attrs["interfaced.items"] = obj.interfaced_items if obj.interfaced_items
|
|
65
|
+
attrs["classif"] = obj.classif if obj.classif
|
|
66
|
+
node.set_attributes(attrs)
|
|
67
|
+
if obj.description
|
|
68
|
+
desc = doc.create_element("description")
|
|
69
|
+
desc.content = obj.description
|
|
70
|
+
node.add_child(desc)
|
|
71
|
+
end
|
|
72
|
+
node
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def build_report(base_repo, revised_repo)
|
|
76
|
+
sections = { additions: [], deletions: [], modifications: [] }
|
|
77
|
+
base = index_schemas(base_repo)
|
|
78
|
+
revised = index_schemas(revised_repo)
|
|
79
|
+
|
|
80
|
+
(base.keys | revised.keys).each do |schema_id|
|
|
81
|
+
base_schema = base[schema_id]
|
|
82
|
+
revised_schema = revised[schema_id]
|
|
83
|
+
if base_schema.nil?
|
|
84
|
+
collect_whole_schema(revised_schema, :added, sections)
|
|
85
|
+
elsif revised_schema.nil?
|
|
86
|
+
collect_whole_schema(base_schema, :removed, sections)
|
|
87
|
+
else
|
|
88
|
+
collect_deltas(base_schema, revised_schema, sections)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
Expressir::Eengine::CompareReport.new(
|
|
93
|
+
additions: Expressir::Eengine::ChangesSection
|
|
94
|
+
.new(modified_objects: sections[:additions]),
|
|
95
|
+
deletions: Expressir::Eengine::ChangesSection
|
|
96
|
+
.new(modified_objects: sections[:deletions]),
|
|
97
|
+
modifications: Expressir::Eengine::ChangesSection
|
|
98
|
+
.new(modified_objects: sections[:modifications]),
|
|
99
|
+
)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def index_schemas(repo)
|
|
103
|
+
Array(repo.schemas).to_h do |schema|
|
|
104
|
+
[schema.id&.safe_downcase, schema]
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def collect_whole_schema(schema, operation, sections)
|
|
109
|
+
section = section_for(operation)
|
|
110
|
+
Expressir::Express::SchemaCompare::COLLECTIONS.each do |collection|
|
|
111
|
+
Array(schema.send(collection)).each do |decl|
|
|
112
|
+
next unless decl.respond_to?(:id) && decl.id
|
|
113
|
+
|
|
114
|
+
sections[section] << Expressir::Eengine::ModifiedObject.new(
|
|
115
|
+
type: KINDS[collection], name: decl.id,
|
|
116
|
+
)
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def collect_deltas(base_schema, revised_schema, sections)
|
|
122
|
+
Expressir::Express::SchemaCompare::COLLECTIONS.each do |collection|
|
|
123
|
+
deltas = Expressir::Express::SchemaCompare
|
|
124
|
+
.collection_deltas(base_schema, revised_schema, collection)
|
|
125
|
+
Expressir::Express::ChangeClassification.apply(deltas, base_schema)
|
|
126
|
+
deltas.each do |delta|
|
|
127
|
+
# an attribute-level delta modifies its entity: it lands
|
|
128
|
+
# in modifications whatever the op
|
|
129
|
+
section = if delta.path.split(".").size > 2
|
|
130
|
+
:modifications
|
|
131
|
+
else
|
|
132
|
+
section_for(delta.op)
|
|
133
|
+
end
|
|
134
|
+
sections[section] << object_for(delta, collection)
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def object_for(delta, collection)
|
|
140
|
+
kind = KINDS[collection]
|
|
141
|
+
name = delta.path.split(".").last
|
|
142
|
+
object = if delta.path.split(".").size > 2
|
|
143
|
+
# attribute-level delta: the qualified path is the name
|
|
144
|
+
Expressir::Eengine::ModifiedObject.new(
|
|
145
|
+
type: kind, name: delta.path,
|
|
146
|
+
description: "attribute #{delta.op}"
|
|
147
|
+
)
|
|
148
|
+
else
|
|
149
|
+
Expressir::Eengine::ModifiedObject.new(type: kind, name: name)
|
|
150
|
+
end
|
|
151
|
+
object.classif = delta.classification&.value
|
|
152
|
+
object
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def section_for(operation)
|
|
156
|
+
case operation
|
|
157
|
+
when :added then :additions
|
|
158
|
+
when :removed then :deletions
|
|
159
|
+
else :modifications
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def kind_of(declaration)
|
|
164
|
+
case declaration
|
|
165
|
+
when Model::Declarations::Entity then "ENTITY"
|
|
166
|
+
when Model::Declarations::Type then "TYPE"
|
|
167
|
+
when Model::Declarations::Function then "FUNCTION"
|
|
168
|
+
when Model::Declarations::Rule then "RULE"
|
|
169
|
+
when Model::Declarations::SubtypeConstraint then "SUBTYPE_CONSTRAINT"
|
|
170
|
+
when Model::Declarations::Constant then "CONSTANT"
|
|
171
|
+
when Model::Declarations::Procedure then "PROCEDURE"
|
|
172
|
+
else declaration.class.name.split("::").last.upcase
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Expressir
|
|
4
|
+
module Commands
|
|
5
|
+
# `expressir doctor` (TODO.compat/02): assess a workspace for
|
|
6
|
+
# expressir readiness — which schemas parse, which instance
|
|
7
|
+
# datasets load, which mapping files bind — and optionally emit a
|
|
8
|
+
# starter schema manifest for the schemas it found.
|
|
9
|
+
class Doctor < Base
|
|
10
|
+
Report = Struct.new(:schemas, :instances, :mappings, keyword_init: true)
|
|
11
|
+
|
|
12
|
+
def run(path)
|
|
13
|
+
raise Thor::Error, "#{path} is not a directory" unless File.directory?(path)
|
|
14
|
+
|
|
15
|
+
report = Report.new(schemas: [], instances: [], mappings: [])
|
|
16
|
+
Dir.glob("#{path}/**/*.exp").each { |f| probe_schema(f, report) }
|
|
17
|
+
Dir.glob("#{path}/**/*.p21").each { |f| probe_instance(f, report) }
|
|
18
|
+
Dir.glob("#{path}/**/mapping*.yaml").each { |f| probe_mapping(f, report) }
|
|
19
|
+
|
|
20
|
+
emit_manifest(path, report) if options[:emit_manifest]
|
|
21
|
+
print_report(report)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def probe_schema(file, report)
|
|
27
|
+
repo = Expressir::Express::Parser.from_file(file, skip_references: true)
|
|
28
|
+
report.schemas << { path: file, schemas: repo.schemas.size,
|
|
29
|
+
entities: repo.schemas.sum { |s| s.entities.size } }
|
|
30
|
+
rescue StandardError => e
|
|
31
|
+
report.schemas << { path: file, error: e.message[0, 160] }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def probe_instance(file, report)
|
|
35
|
+
pop = Expressir::P21::Parser.parse(File.read(file))
|
|
36
|
+
report.instances << { path: file, instances: pop.instances.size }
|
|
37
|
+
rescue StandardError => e
|
|
38
|
+
report.instances << { path: file, error: e.message[0, 160] }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def probe_mapping(file, report)
|
|
42
|
+
doc = Expressir::Mapping.load_file(file)
|
|
43
|
+
report.mappings << { path: file,
|
|
44
|
+
elements: doc.ae.size + doc.sc.size }
|
|
45
|
+
rescue StandardError => e
|
|
46
|
+
report.mappings << { path: file, error: e.message[0, 160] }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def emit_manifest(_path, report)
|
|
50
|
+
return unless options[:emit_manifest]
|
|
51
|
+
|
|
52
|
+
manifest_path = options[:emit_manifest] == true ? "manifest.yml" : options[:emit_manifest]
|
|
53
|
+
ready = report.schemas.select { |s| s[:schemas] }
|
|
54
|
+
File.write(manifest_path, {
|
|
55
|
+
"schema" => ready.first&.dig(:path) || "schema.exp",
|
|
56
|
+
"release" => "workspaces",
|
|
57
|
+
"files" => ready.map { |s| s[:path] },
|
|
58
|
+
}.to_yaml)
|
|
59
|
+
say "starter manifest written to #{manifest_path}"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def print_report(report)
|
|
63
|
+
report.schemas.each { |s| print_entry("schema", s) }
|
|
64
|
+
report.instances.each { |s| print_entry("instance", s) }
|
|
65
|
+
report.mappings.each { |s| print_entry("mapping", s) }
|
|
66
|
+
ready = report.schemas.count { |s| s[:schemas] } +
|
|
67
|
+
report.instances.count { |s| s[:instances] } +
|
|
68
|
+
report.mappings.count { |s| s[:elements] }
|
|
69
|
+
say "ready: #{ready} file(s)"
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def print_entry(kind, entry)
|
|
73
|
+
if entry[:error]
|
|
74
|
+
say "UNREADABLE #{kind} #{entry[:path]}: #{entry[:error]}"
|
|
75
|
+
else
|
|
76
|
+
say "ready #{kind} #{entry[:path]}"
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "thor"
|
|
4
|
+
|
|
5
|
+
module Expressir
|
|
6
|
+
module Commands
|
|
7
|
+
# `expressir receipt MANIFEST` (TODO.compat/04): run the three
|
|
8
|
+
# shipped validators over one workspace manifest and emit the
|
|
9
|
+
# unified receipt — deterministic canonical JSON, structured for
|
|
10
|
+
# signing. Exits 1 when the receipt reports errors.
|
|
11
|
+
class Receipt < Base
|
|
12
|
+
def run(manifest_path)
|
|
13
|
+
manifest = Expressir::Receipt::WorkspaceManifest.from_file(manifest_path)
|
|
14
|
+
receipt = Expressir::Receipt.generate(Expressir::Receipt.build(manifest))
|
|
15
|
+
if options[:output]
|
|
16
|
+
File.write(options[:output], receipt)
|
|
17
|
+
say "receipt written to #{options[:output]}"
|
|
18
|
+
else
|
|
19
|
+
$stdout.write(receipt)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
summary = JSON.parse(receipt)["summary"]
|
|
23
|
+
return if summary["valid"]
|
|
24
|
+
|
|
25
|
+
raise Thor::Error,
|
|
26
|
+
"repository receipt reports #{summary['errors']} error(s)"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -80,6 +80,13 @@ module Expressir
|
|
|
80
80
|
ValidateAscii.new(options).run(path)
|
|
81
81
|
end
|
|
82
82
|
|
|
83
|
+
desc "remarks PATH_OR_MANIFEST",
|
|
84
|
+
"Validate remark blocks: a block anchor ([[name]]) must be " \
|
|
85
|
+
"defined in a single remark scope per schema"
|
|
86
|
+
def remarks(*paths)
|
|
87
|
+
ValidateRemarks.new(options).run(paths)
|
|
88
|
+
end
|
|
89
|
+
|
|
83
90
|
desc "check *PATHS", "Run eeng check-p11 semantic checks"
|
|
84
91
|
long_desc <<~DESC
|
|
85
92
|
Walks one or more EXPRESS files (or directories of .exp) and
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
|
|
5
|
+
module Expressir
|
|
6
|
+
module Commands
|
|
7
|
+
# Source-stage remark validation. Three checks:
|
|
8
|
+
#
|
|
9
|
+
# * a block anchor ([[name]]) defined in more than one remark scope
|
|
10
|
+
# of the same schema — documents rendered from both scopes then
|
|
11
|
+
# carry duplicated anchor attributes and fail the backend's
|
|
12
|
+
# unique-ID validation;
|
|
13
|
+
# * a remark item describing a LOCAL variable of a FUNCTION that the
|
|
14
|
+
# RETURN statement references — resource documents would print it
|
|
15
|
+
# under "Argument definitions:" (metanorma/iso-10303#763); the
|
|
16
|
+
# result belongs in the body of the FUNCTION description;
|
|
17
|
+
# * [.svgmap] list items inside __expressg blocks: the named schema
|
|
18
|
+
# must exist, the ordinal belongs after the cross-reference, and
|
|
19
|
+
# the item ordinals must match the hyperlink identifiers of the
|
|
20
|
+
# diagram the block names (metanorma/iso-10303#743, #744, #745).
|
|
21
|
+
class ValidateRemarks < Base
|
|
22
|
+
BLOCK_ANCHOR = /\A[ \t]*\[\[([^\]]+)\]\][ \t]*\r?\n?\z/
|
|
23
|
+
SVG_IMAGE = /\A[ \t]*image::([^\[\]]+\.svg)\[\]/
|
|
24
|
+
SVGMAP_ITEM = /\A\*[ \t]+<<express:([^>]*)>>[ \t]*;[ \t]*(\d+)[ \t]*\r?\n?\z/
|
|
25
|
+
SVGMAP_ORDINAL_INSIDE = /\A\*[ \t]+<<express:[^>]*;\s*\d+[^>]*>>/
|
|
26
|
+
SVG_HREF = /<a href="([^"]*)"/
|
|
27
|
+
|
|
28
|
+
def run(paths)
|
|
29
|
+
if paths.size == 1 && File.extname(paths.first) == ".yaml"
|
|
30
|
+
validate_from_manifest(paths.first)
|
|
31
|
+
else
|
|
32
|
+
validate_from_paths(paths)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
def validate_from_manifest(manifest_path)
|
|
39
|
+
unless File.exist?(manifest_path)
|
|
40
|
+
raise Expressir::ManifestNotFoundError.new(manifest_path)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
manifest = Expressir::SchemaManifest.from_file(manifest_path)
|
|
44
|
+
paths = manifest.schemas.map(&:path).reject { |p| p.nil? || p.empty? }
|
|
45
|
+
if paths.empty?
|
|
46
|
+
raise Expressir::NoValidSchemaPathsError.new(
|
|
47
|
+
"No valid schema paths found in manifest",
|
|
48
|
+
)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
validate_from_paths(paths)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def validate_from_paths(paths)
|
|
55
|
+
parsed = schema_paths(paths).map do |path|
|
|
56
|
+
repository = Expressir::Express::Parser.from_file(path)
|
|
57
|
+
[path, repository.schemas]
|
|
58
|
+
end
|
|
59
|
+
schema_ids = parsed.flat_map { |_, schemas| schemas.map(&:id) }
|
|
60
|
+
.map { |id| id.to_s.downcase }
|
|
61
|
+
|
|
62
|
+
violations = []
|
|
63
|
+
parsed.each do |path, schemas|
|
|
64
|
+
schemas.each do |schema|
|
|
65
|
+
violations.concat(duplicate_anchor_violations(schema, path))
|
|
66
|
+
violations.concat(returned_local_violations(schema, path))
|
|
67
|
+
violations.concat(svgmap_violations(schema, path, schema_ids))
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
if violations.empty?
|
|
72
|
+
say "Validation passed: no duplicate remark block anchors, no " \
|
|
73
|
+
"returned-LOCAL descriptions, and no svgmap defects."
|
|
74
|
+
return
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
say "#{'*' * 20} RESULTS: REMARK VALIDATION #{'*' * 20}"
|
|
78
|
+
violations.each { |violation| say violation }
|
|
79
|
+
raise Expressir::SchemaValidationError.new(
|
|
80
|
+
"Remark validation failed: #{violations.size} violation(s)",
|
|
81
|
+
errors: violations,
|
|
82
|
+
)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def schema_paths(paths)
|
|
86
|
+
paths.flat_map do |path|
|
|
87
|
+
if File.directory?(path)
|
|
88
|
+
Dir.glob(File.join(path, "**", "*.exp"))
|
|
89
|
+
else
|
|
90
|
+
path
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def duplicate_anchor_violations(schema, path)
|
|
96
|
+
definitions = Hash.new { |hash, anchor| hash[anchor] = [] }
|
|
97
|
+
remark_scopes(schema).each do |label, remarks|
|
|
98
|
+
each_remark_line(remarks) do |line|
|
|
99
|
+
match = line.match(BLOCK_ANCHOR)
|
|
100
|
+
next unless match
|
|
101
|
+
|
|
102
|
+
definitions[match[1]] << label
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
definitions.filter_map do |anchor, labels|
|
|
107
|
+
next if labels.size == 1
|
|
108
|
+
|
|
109
|
+
"Duplicate remark block anchor `#{anchor}` defined in " \
|
|
110
|
+
"#{labels.join(', ')} | schema `#{schema.id}` | #{path}"
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def returned_local_violations(schema, path)
|
|
115
|
+
Array(schema.children)
|
|
116
|
+
.grep(Expressir::Model::Declarations::Function)
|
|
117
|
+
.flat_map do |function|
|
|
118
|
+
returned = returned_identifiers(function)
|
|
119
|
+
Array(function.variables).filter_map do |variable|
|
|
120
|
+
next unless returned.include?(variable.id.to_s.downcase)
|
|
121
|
+
next if Array(variable.remarks)
|
|
122
|
+
.map { |remark| remark.to_s.strip }.reject(&:empty?).empty?
|
|
123
|
+
|
|
124
|
+
"LOCAL variable `#{variable.id}` of FUNCTION " \
|
|
125
|
+
"`#{function.id}` is referenced in the RETURN statement " \
|
|
126
|
+
"and carries a description; describe the result in the " \
|
|
127
|
+
"body of the FUNCTION description instead | schema " \
|
|
128
|
+
"`#{schema.id}` | #{path}"
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# Identifiers referenced by any RETURN statement of the function,
|
|
134
|
+
# including returns nested in IF/CASE and other compound
|
|
135
|
+
# statements.
|
|
136
|
+
def returned_identifiers(function)
|
|
137
|
+
refs = []
|
|
138
|
+
seen = {}.compare_by_identity
|
|
139
|
+
returns = []
|
|
140
|
+
collect = lambda do |node|
|
|
141
|
+
return if node.nil? || seen.key?(node)
|
|
142
|
+
|
|
143
|
+
seen[node] = true
|
|
144
|
+
returns << node if node.is_a?(Expressir::Model::Statements::Return)
|
|
145
|
+
node.class.attributes.each_key do |attr|
|
|
146
|
+
value = begin
|
|
147
|
+
node.public_send(attr)
|
|
148
|
+
rescue StandardError
|
|
149
|
+
next
|
|
150
|
+
end
|
|
151
|
+
Array(value).each do |child|
|
|
152
|
+
collect.call(child) if child.is_a?(Expressir::Model::ModelElement)
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
Array(function.statements).each { |statement| collect.call(statement) }
|
|
157
|
+
returns.each do |ret|
|
|
158
|
+
seen_expr = {}.compare_by_identity
|
|
159
|
+
expr_walk = lambda do |node|
|
|
160
|
+
next if node.nil? || seen_expr.key?(node)
|
|
161
|
+
|
|
162
|
+
seen_expr[node] = true
|
|
163
|
+
if node.is_a?(Expressir::Model::References::SimpleReference) &&
|
|
164
|
+
node.id
|
|
165
|
+
refs << node.id.to_s.downcase
|
|
166
|
+
end
|
|
167
|
+
node.class.attributes.each_key do |attr|
|
|
168
|
+
value = begin
|
|
169
|
+
node.public_send(attr)
|
|
170
|
+
rescue StandardError
|
|
171
|
+
next
|
|
172
|
+
end
|
|
173
|
+
Array(value).each do |child|
|
|
174
|
+
expr_walk.call(child) if child.is_a?(
|
|
175
|
+
Expressir::Model::ModelElement,
|
|
176
|
+
)
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
expr_walk.call(ret.expression)
|
|
181
|
+
end
|
|
182
|
+
refs.uniq
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def svgmap_violations(schema, path, schema_ids)
|
|
186
|
+
dir = File.dirname(path)
|
|
187
|
+
blocks = svgmap_blocks(schema, schema_ids)
|
|
188
|
+
blocks.flat_map do |items|
|
|
189
|
+
violations = items[:violations]
|
|
190
|
+
violations.concat(items[:malformed].map do |line|
|
|
191
|
+
"svgmap item places the ordinal inside the cross-reference; " \
|
|
192
|
+
"write `<<express:TARGET>>; N` instead: #{line.strip} " \
|
|
193
|
+
"| schema `#{schema.id}` | #{path}"
|
|
194
|
+
end)
|
|
195
|
+
violations.concat(items[:unknown_schemas].map do |name|
|
|
196
|
+
"svgmap item names schema `#{name}`, which is not declared in " \
|
|
197
|
+
"the repository | schema `#{schema.id}` | #{path}"
|
|
198
|
+
end)
|
|
199
|
+
violations.concat(
|
|
200
|
+
ordinal_mismatches(File.join(dir, items[:svg]), items, path,
|
|
201
|
+
schema.id),
|
|
202
|
+
)
|
|
203
|
+
violations
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
def svgmap_blocks(schema, schema_ids)
|
|
208
|
+
current = nil
|
|
209
|
+
blocks = []
|
|
210
|
+
Array(schema.remark_items)
|
|
211
|
+
.select { |item| item.id == "__expressg" }
|
|
212
|
+
.each do |item|
|
|
213
|
+
each_remark_line(Array(item.remarks)) do |line|
|
|
214
|
+
image = line.match(SVG_IMAGE)
|
|
215
|
+
if image
|
|
216
|
+
current = { svg: image[1],
|
|
217
|
+
violations: [],
|
|
218
|
+
malformed: [],
|
|
219
|
+
unknown_schemas: [],
|
|
220
|
+
ordinals: [] }
|
|
221
|
+
blocks << current
|
|
222
|
+
next
|
|
223
|
+
end
|
|
224
|
+
next unless current
|
|
225
|
+
|
|
226
|
+
if line.match?(SVGMAP_ORDINAL_INSIDE)
|
|
227
|
+
current[:malformed] << line
|
|
228
|
+
next
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
item_match = line.match(SVGMAP_ITEM)
|
|
232
|
+
next unless item_match
|
|
233
|
+
|
|
234
|
+
current[:ordinals] << item_match[2]
|
|
235
|
+
name = item_match[1].to_s.sub(/\A\.+/, "").split(".").first
|
|
236
|
+
if name && !schema_ids.include?(name.downcase)
|
|
237
|
+
current[:unknown_schemas] << name
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
blocks
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def ordinal_mismatches(svg_path, items, path, schema_id)
|
|
245
|
+
return [] unless File.exist?(svg_path)
|
|
246
|
+
|
|
247
|
+
svg = File.read(svg_path)
|
|
248
|
+
# Only numeric hyperlink identifiers are svgmap keys; named
|
|
249
|
+
# hrefs mark imported-schema regions no list item claims.
|
|
250
|
+
svg_ids = svg.scan(SVG_HREF).flatten.map(&:strip)
|
|
251
|
+
.grep(/\A\d+\z/).uniq
|
|
252
|
+
ordinals = items[:ordinals].uniq
|
|
253
|
+
[].concat(
|
|
254
|
+
(ordinals - svg_ids).map do |ordinal|
|
|
255
|
+
"svgmap ordinal `#{ordinal}` has no hyperlink in " \
|
|
256
|
+
"`#{File.basename(svg_path)}` | schema `#{schema_id}` | #{path}"
|
|
257
|
+
end,
|
|
258
|
+
(svg_ids - ordinals).map do |id|
|
|
259
|
+
"svgmap hyperlink `#{id}` in `#{File.basename(svg_path)}` is " \
|
|
260
|
+
"claimed by no list item | schema `#{schema_id}` | #{path}"
|
|
261
|
+
end,
|
|
262
|
+
)
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
def each_remark_line(remarks, &block)
|
|
266
|
+
Array(remarks).each do |text|
|
|
267
|
+
next if text.nil?
|
|
268
|
+
|
|
269
|
+
source = text.is_a?(String) ? text : text.to_s
|
|
270
|
+
source.each_line(&block)
|
|
271
|
+
end
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
def remark_scopes(schema)
|
|
275
|
+
scopes = [["the untagged schema remark", Array(schema.remarks)]]
|
|
276
|
+
Array(schema.remark_items).each do |item|
|
|
277
|
+
scopes << ["remark item `#{item.id}`", Array(item.remarks)]
|
|
278
|
+
end
|
|
279
|
+
scopes
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
end
|
|
283
|
+
end
|
data/lib/expressir/commands.rb
CHANGED
|
@@ -14,6 +14,7 @@ module Expressir
|
|
|
14
14
|
autoload :ParityInputs, "#{__dir__}/commands/parity_inputs"
|
|
15
15
|
autoload :Validate, "#{__dir__}/commands/validate"
|
|
16
16
|
autoload :ValidateLoad, "#{__dir__}/commands/validate_load"
|
|
17
|
+
autoload :ValidateRemarks, "#{__dir__}/commands/validate_remarks"
|
|
17
18
|
autoload :ValidateAscii, "#{__dir__}/commands/validate_ascii"
|
|
18
19
|
autoload :NonAsciiCharacter, "#{__dir__}/commands/non_ascii_character"
|
|
19
20
|
autoload :FileViolations, "#{__dir__}/commands/file_violations"
|
|
@@ -23,7 +24,10 @@ module Expressir
|
|
|
23
24
|
autoload :ChangesImportEengine, "#{__dir__}/commands/changes_import_eengine"
|
|
24
25
|
autoload :Version, "#{__dir__}/commands/version_command"
|
|
25
26
|
autoload :Package, "#{__dir__}/commands/package"
|
|
27
|
+
autoload :Compare, "#{__dir__}/commands/compare"
|
|
28
|
+
autoload :Doctor, "#{__dir__}/commands/doctor"
|
|
26
29
|
autoload :Population, "#{__dir__}/commands/population"
|
|
30
|
+
autoload :Receipt, "#{__dir__}/commands/receipt"
|
|
27
31
|
autoload :Manifest, "#{__dir__}/commands/manifest"
|
|
28
32
|
autoload :MappingValidate, "#{__dir__}/commands/mapping_validate"
|
|
29
33
|
autoload :Xsd, "#{__dir__}/commands/xsd"
|
|
@@ -8,12 +8,18 @@ module Expressir
|
|
|
8
8
|
attribute :name, :string
|
|
9
9
|
attribute :interfaced_items, :string
|
|
10
10
|
attribute :description, :string
|
|
11
|
+
# Semantic change classification (TODO.compat/06): breaking or
|
|
12
|
+
# additive, per the subtype graph and the ISO 10303-11 Annex K
|
|
13
|
+
# deprecation policy. Optional — readers that ignore unknown
|
|
14
|
+
# attributes are unaffected.
|
|
15
|
+
attribute :classif, :string
|
|
11
16
|
|
|
12
17
|
xml do
|
|
13
18
|
element "modified.object"
|
|
14
19
|
map_attribute "type", to: :type
|
|
15
20
|
map_attribute "name", to: :name
|
|
16
21
|
map_attribute "interfaced.items", to: :interfaced_items
|
|
22
|
+
map_attribute "classif", to: :classif
|
|
17
23
|
map_element "description", to: :description
|
|
18
24
|
end
|
|
19
25
|
end
|