expressir 2.4.54 → 2.4.56
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/ext/expressir_core/Cargo.toml +1 -1
- data/ext/expressir_core/src/lib.rs +72 -0
- data/lib/expressir/express/checker.rb +35 -0
- data/lib/expressir/express/core.rb +40 -0
- data/lib/expressir/express/formatter.rb +25 -0
- data/lib/expressir/express/parser.rb +2 -2
- data/lib/expressir/model/exp_file.rb +8 -0
- data/lib/expressir/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a538e044b224fb0f69703d44d79f683d256113c419a13016de659ef971cde5ca
|
|
4
|
+
data.tar.gz: 3c0fd091a74ed3808cf337cafd146b01f65c4f796f46dd9d61f59cfefa9ad195
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 43d186c80eab324cd0130b9cd517ce62961e842c289a157a9db14b9a2594d2261562fc9ff711049c0df3fa8c2e064c7ef14ae673eb8f215d9fa1c6063b40aaae
|
|
7
|
+
data.tar.gz: 64c8eb4f46c972b4dcaa8c93614e3a9e126c58bb842c11295f8ff8fa0bccef2ae48b9f0db33236af022435bed8fb24348d2ba28dcea18242af19cb7c60d5c408
|
|
@@ -13,7 +13,7 @@ magnus = { version = "0.9" }
|
|
|
13
13
|
# Pinned core release (M1, TODO.parity-ee/19): the ext never floats
|
|
14
14
|
# main — bump the tag per expressir release, alongside the validation
|
|
15
15
|
# run that pins it.
|
|
16
|
-
expressir-rs = { git = "https://github.com/lutaml/expressir-rs", tag = "v0.1.
|
|
16
|
+
expressir-rs = { git = "https://github.com/lutaml/expressir-rs", tag = "v0.1.25" }
|
|
17
17
|
serde_json = "1.0"
|
|
18
18
|
|
|
19
19
|
|
|
@@ -581,12 +581,84 @@ fn model_object_attached(ruby: &Ruby, source: String, path: String) -> Result<ma
|
|
|
581
581
|
value_to_ruby(ruby, &mut cache, &wire)
|
|
582
582
|
}
|
|
583
583
|
|
|
584
|
+
/// `format_model_hash(wire_json, no_remarks)`: the SourceFormatter
|
|
585
|
+
/// over a wire (issue #22). `wire_json` is the model-hash JSON of one
|
|
586
|
+
/// file; the rendered EXPRESS text comes back as a string.
|
|
587
|
+
fn format_model_hash(ruby: &Ruby, wire_json: String, no_remarks: bool) -> Result<String, Error> {
|
|
588
|
+
let wire: Wire = serde_json::from_str(&wire_json)
|
|
589
|
+
.map_err(|e| Error::new(ruby.exception_arg_error(), format!("wire: {e}")))?;
|
|
590
|
+
Ok(expressir_rs::formatter::format(&wire, no_remarks))
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/// `check_model_hash(wire_json, dialect)`: the semantic checks over a
|
|
594
|
+
/// wire (issue #21). `wire_json` is the model-hash JSON of one file;
|
|
595
|
+
/// findings come back as hashes with id/severity/schema/message in the
|
|
596
|
+
/// checker's canonical order.
|
|
597
|
+
fn check_model_hash(ruby: &Ruby, wire_json: String, dialect: Option<String>) -> Result<magnus::Value, Error> {
|
|
598
|
+
let mut wire: Wire = serde_json::from_str(&wire_json)
|
|
599
|
+
.map_err(|e| Error::new(ruby.exception_arg_error(), format!("wire: {e}")))?;
|
|
600
|
+
let notes = expressir_rs::checker::check(&mut wire, dialect.as_deref());
|
|
601
|
+
let array = ruby.ary_new_capa(notes.len());
|
|
602
|
+
for note in ¬es {
|
|
603
|
+
let hash = ruby.hash_new();
|
|
604
|
+
hash.aset(ruby.sym_new("id"), ruby_str(ruby, ¬e.id))?;
|
|
605
|
+
hash.aset(ruby.sym_new("severity"), ruby_str(ruby, note.severity))?;
|
|
606
|
+
match ¬e.schema {
|
|
607
|
+
Some(schema) => hash.aset(ruby.sym_new("schema"), ruby_str(ruby, schema))?,
|
|
608
|
+
None => hash.aset(ruby.sym_new("schema"), ruby.qnil().as_value())?,
|
|
609
|
+
}
|
|
610
|
+
hash.aset(ruby.sym_new("message"), ruby_str(ruby, ¬e.message))?;
|
|
611
|
+
array.push(hash)?;
|
|
612
|
+
}
|
|
613
|
+
Ok(array.as_value())
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/// `parse_to_model_attached_with_wire(source, path)`: the attached
|
|
617
|
+
/// model AND the attached wire JSON it came from. The wire lets the
|
|
618
|
+
/// Ruby tier keep a lossless handle for the Rust formatter (issue
|
|
619
|
+
/// #22) — a `to_hash` round trip would drop empty collections.
|
|
620
|
+
fn parse_to_model_attached_with_wire(
|
|
621
|
+
ruby: &Ruby,
|
|
622
|
+
source: String,
|
|
623
|
+
path: String,
|
|
624
|
+
) -> Result<magnus::Value, Error> {
|
|
625
|
+
let tree = ParsedTree::parse(&source).map_err(|e| {
|
|
626
|
+
Error::new(
|
|
627
|
+
ruby.exception_runtime_error(),
|
|
628
|
+
format!("expressir-core: parse error: {e:?}"),
|
|
629
|
+
)
|
|
630
|
+
})?;
|
|
631
|
+
let mut wire = tree.to_model_json(&path).map_err(|e| parse_error(ruby, e))?;
|
|
632
|
+
expressir_rs::attach::attach_tagged_remarks(&mut wire, &source);
|
|
633
|
+
expressir_rs::attach::attach_untagged_remarks(&mut wire, &source);
|
|
634
|
+
let mut cache = ClassCache::default();
|
|
635
|
+
let mut hydrate_wire = wire.clone();
|
|
636
|
+
strip_end_offsets(&mut hydrate_wire);
|
|
637
|
+
let model = value_to_ruby(ruby, &mut cache, &hydrate_wire)?;
|
|
638
|
+
let wire_json = serde_json::to_string(&wire).map_err(|e| {
|
|
639
|
+
Error::new(
|
|
640
|
+
ruby.exception_runtime_error(),
|
|
641
|
+
format!("wire encode {path}: {e}"),
|
|
642
|
+
)
|
|
643
|
+
})?;
|
|
644
|
+
let pair = RArray::with_capacity(2);
|
|
645
|
+
pair.push(model)?;
|
|
646
|
+
pair.push(ruby.str_new(&wire_json))?;
|
|
647
|
+
Ok(pair.as_value())
|
|
648
|
+
}
|
|
649
|
+
|
|
584
650
|
#[magnus::init]
|
|
585
651
|
fn init(ruby: &Ruby) -> Result<(), Error> {
|
|
586
652
|
let module = ruby.define_module("Expressir")?.define_module("Core")?;
|
|
587
653
|
module.define_singleton_method("parse_to_model_hash", function!(model_json, 2))?;
|
|
654
|
+
module.define_singleton_method("check_model_hash", function!(check_model_hash, 2))?;
|
|
655
|
+
module.define_singleton_method("format_model_hash", function!(format_model_hash, 2))?;
|
|
588
656
|
module.define_singleton_method("parse_to_model", function!(model_object, 2))?;
|
|
589
657
|
module.define_singleton_method("parse_to_model_attached", function!(model_object_attached, 2))?;
|
|
658
|
+
module.define_singleton_method(
|
|
659
|
+
"parse_to_model_attached_with_wire",
|
|
660
|
+
function!(parse_to_model_attached_with_wire, 2),
|
|
661
|
+
)?;
|
|
590
662
|
module.define_singleton_method("scan_remarks", function!(scan_remarks, 1))?;
|
|
591
663
|
module.define_singleton_method("write_set", function!(set_write, 3))?;
|
|
592
664
|
let batch_class = module.define_class("BatchStream", ruby.class_object())?;
|
|
@@ -47,12 +47,47 @@ module Expressir
|
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
+
# Runs the checks. When the native extension exposes the core
|
|
51
|
+
# checker (issue #21), each file's model wire is checked in Rust;
|
|
52
|
+
# the findings are identical to this class's Ruby walk (gated by
|
|
53
|
+
# the checker parity suites). The Ruby walk stays as the
|
|
54
|
+
# fallback for non-native environments.
|
|
50
55
|
def check
|
|
56
|
+
return check_via_core if core_check_available?
|
|
57
|
+
|
|
51
58
|
@notes = []
|
|
52
59
|
@repository.schemas.compact.each { |schema| check_schema(schema) }
|
|
53
60
|
self
|
|
54
61
|
end
|
|
55
62
|
|
|
63
|
+
def core_check_available?
|
|
64
|
+
Expressir::Express::Core::NATIVE_AVAILABLE &&
|
|
65
|
+
Expressir::Express::Core.respond_to?(:check_model_hash)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def check_via_core
|
|
69
|
+
# The Ruby Checker sees the whole repository (cross-file
|
|
70
|
+
# interfaces, self-schema defining schemas), so the wire keeps
|
|
71
|
+
# the repository shape when the model has one.
|
|
72
|
+
wire =
|
|
73
|
+
if @repository.respond_to?(:files)
|
|
74
|
+
{
|
|
75
|
+
"_class" => "Expressir::Model::Repository",
|
|
76
|
+
"files" => @repository.files.compact.map(&:to_hash),
|
|
77
|
+
}
|
|
78
|
+
else
|
|
79
|
+
@repository.to_hash
|
|
80
|
+
end
|
|
81
|
+
@notes = Expressir::Express::Core.check_model_hash(wire, @dialect)
|
|
82
|
+
.map do |note|
|
|
83
|
+
Note.new(
|
|
84
|
+
id: note[:id].to_sym, severity: note[:severity].to_sym,
|
|
85
|
+
schema: note[:schema], message: note[:message]
|
|
86
|
+
)
|
|
87
|
+
end
|
|
88
|
+
self
|
|
89
|
+
end
|
|
90
|
+
|
|
56
91
|
def errors
|
|
57
92
|
notes.select { |n| n.severity == :error }
|
|
58
93
|
end
|
|
@@ -48,6 +48,21 @@ module Expressir
|
|
|
48
48
|
::Expressir::Core.parse_to_model_attached(source, path)
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
+
# Like parse_to_model_attached, but also returns the attached
|
|
52
|
+
# wire JSON string ([model, wire_json]) so the file retains a
|
|
53
|
+
# lossless handle for the Rust formatter (issue #22).
|
|
54
|
+
def self.parse_to_model_attached_with_wire(source, path)
|
|
55
|
+
unless NATIVE_AVAILABLE &&
|
|
56
|
+
::Expressir::Core.respond_to?(:parse_to_model_attached_with_wire)
|
|
57
|
+
raise NotImplementedError, "core wire retention unavailable"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
model, wire_json = ::Expressir::Core.parse_to_model_attached_with_wire(source, path)
|
|
61
|
+
model.wire_parents
|
|
62
|
+
model.core_wire = wire_json
|
|
63
|
+
model
|
|
64
|
+
end
|
|
65
|
+
|
|
51
66
|
# Scan remarks (issue #20): an Array of Hashes mirroring
|
|
52
67
|
# RemarkScanner::Remark's fields (position, end_position, line,
|
|
53
68
|
# text, tag, format), straight from the Rust scanner.
|
|
@@ -55,6 +70,31 @@ module Expressir
|
|
|
55
70
|
::Expressir::Core.scan_remarks(source)
|
|
56
71
|
end
|
|
57
72
|
|
|
73
|
+
# SourceFormatter (issue #22): the rendered EXPRESS text for one
|
|
74
|
+
# file's model-hash wire, straight from the Rust formatter.
|
|
75
|
+
def self.format_model_hash(wire, no_remarks: false)
|
|
76
|
+
raise NotImplementedError, "the native extension is unavailable" unless NATIVE_AVAILABLE
|
|
77
|
+
|
|
78
|
+
::Expressir::Core.format_model_hash(JSON.generate(wire), no_remarks)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Semantic checks (issue #21): the Checker's findings over one
|
|
82
|
+
# file's model-hash wire, as an Array of Hashes with
|
|
83
|
+
# id/severity/schema/message in the checker's canonical order.
|
|
84
|
+
# `dialect` is nil or a Dialect value; the 1994 edition is
|
|
85
|
+
# translated to the short form the core expects.
|
|
86
|
+
def self.check_model_hash(wire, dialect = nil)
|
|
87
|
+
raise NotImplementedError, "the native extension is unavailable" unless NATIVE_AVAILABLE
|
|
88
|
+
|
|
89
|
+
wire_json = JSON.generate(wire)
|
|
90
|
+
core_dialect = case dialect
|
|
91
|
+
when nil then nil
|
|
92
|
+
when Dialect::EDITION_1994, "10303-11:1994" then "1994"
|
|
93
|
+
else dialect.to_s
|
|
94
|
+
end
|
|
95
|
+
::Expressir::Core.check_model_hash(wire_json, core_dialect)
|
|
96
|
+
end
|
|
97
|
+
|
|
58
98
|
# Parse EXPRESS source into the hydrated model directly: the
|
|
59
99
|
# extension walks the wire definition once and constructs every
|
|
60
100
|
# node through Serializable.instantiate (lutaml-model's fast
|
|
@@ -73,8 +73,18 @@ module Expressir
|
|
|
73
73
|
new.format(node)
|
|
74
74
|
end
|
|
75
75
|
|
|
76
|
+
# When the native extension exposes the core formatter (issue
|
|
77
|
+
# #22), an ExpFile parsed on the core lane renders in Rust over
|
|
78
|
+
# its RETAINED wire — a to_hash round trip would drop empty
|
|
79
|
+
# collections and lose paren-less-function semantics. The base
|
|
80
|
+
# class only: subclasses (PrettyFormatter) keep the Ruby walk,
|
|
81
|
+
# which stays as the fallback everywhere else.
|
|
76
82
|
def format(node)
|
|
77
83
|
return "" if node.nil?
|
|
84
|
+
if node.is_a?(Model::ExpFile) && node.core_wire.is_a?(String) &&
|
|
85
|
+
base_formatter? && core_format_available?
|
|
86
|
+
return format_via_core(node)
|
|
87
|
+
end
|
|
78
88
|
|
|
79
89
|
handler = self.class.format_registry[node.class]
|
|
80
90
|
unless handler
|
|
@@ -85,6 +95,21 @@ module Expressir
|
|
|
85
95
|
place_remarks(send(handler, node), node)
|
|
86
96
|
end
|
|
87
97
|
|
|
98
|
+
def base_formatter?
|
|
99
|
+
instance_of?(Expressir::Express::Formatter)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def core_format_available?
|
|
103
|
+
Expressir::Express::Core::NATIVE_AVAILABLE &&
|
|
104
|
+
Expressir::Express::Core.respond_to?(:format_model_hash)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def format_via_core(file)
|
|
108
|
+
Expressir::Express::Core.format_model_hash(
|
|
109
|
+
JSON.parse(file.core_wire), no_remarks: @no_remarks
|
|
110
|
+
)
|
|
111
|
+
end
|
|
112
|
+
|
|
88
113
|
private
|
|
89
114
|
|
|
90
115
|
# Puts a node's remarks back around its formatted text. Each placement
|
|
@@ -211,9 +211,9 @@ module Expressir
|
|
|
211
211
|
remarks_attached = false
|
|
212
212
|
exp_file =
|
|
213
213
|
begin
|
|
214
|
-
if Core.respond_to?(:
|
|
214
|
+
if Core.respond_to?(:parse_to_model_attached_with_wire)
|
|
215
215
|
remarks_attached = true
|
|
216
|
-
Core.
|
|
216
|
+
Core.parse_to_model_attached_with_wire(source, schema_file)
|
|
217
217
|
.tap(&:wire_parents)
|
|
218
218
|
else
|
|
219
219
|
Core.parse_to_model(source, schema_file).tap(&:wire_parents)
|
|
@@ -27,6 +27,14 @@ module Expressir
|
|
|
27
27
|
map "schemas", to: :schemas
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
+
# The model-hash wire this file was hydrated from, retained by
|
|
31
|
+
# the core parse lane (issue #22): the Rust formatter renders
|
|
32
|
+
# THIS wire, whose nil-vs-empty collections are exactly as the
|
|
33
|
+
# core emitted them (a `to_hash` round trip would drop empty
|
|
34
|
+
# collections and lose paren-less-function semantics). Not a
|
|
35
|
+
# lutaml attribute — it never serializes.
|
|
36
|
+
attr_accessor :core_wire
|
|
37
|
+
|
|
30
38
|
# Returns the file path as the identifier
|
|
31
39
|
# @return [String, nil] The file path or nil
|
|
32
40
|
def id
|
data/lib/expressir/version.rb
CHANGED