expressir 2.4.55 → 2.4.57
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 +48 -0
- data/lib/expressir/express/core.rb +23 -0
- data/lib/expressir/express/formatter.rb +25 -0
- data/lib/expressir/express/grammar/parser.rb +20 -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: 4399f71a09e70ee8efc74ed8ab96b6f4d9dedb72c23eb04a92b7aba57181f794
|
|
4
|
+
data.tar.gz: 6f685947f250eced9f3775bb37f44cede997b1991c03db5a126a2e2c1c3dd4c8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ca081e5d422160ab4061b7b68f3e4c2692845b0e463d47d9a45dbe9c47afc0df377f0dc93b4a2e0eb80b84443514152cf8c67b4069b943650c0cbcf5c13eea75
|
|
7
|
+
data.tar.gz: 7bc334ebf691f931250ef6cba5374f248e928fea3c148b1d4d2eb0c3bcd9c7285cf64238983f93d02c6d113ec28c787892c768de4701d51aec24ba63ec74aa53
|
|
@@ -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.26" }
|
|
17
17
|
serde_json = "1.0"
|
|
18
18
|
|
|
19
19
|
|
|
@@ -581,6 +581,15 @@ 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
|
+
|
|
584
593
|
/// `check_model_hash(wire_json, dialect)`: the semantic checks over a
|
|
585
594
|
/// wire (issue #21). `wire_json` is the model-hash JSON of one file;
|
|
586
595
|
/// findings come back as hashes with id/severity/schema/message in the
|
|
@@ -604,13 +613,52 @@ fn check_model_hash(ruby: &Ruby, wire_json: String, dialect: Option<String>) ->
|
|
|
604
613
|
Ok(array.as_value())
|
|
605
614
|
}
|
|
606
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
|
+
|
|
607
650
|
#[magnus::init]
|
|
608
651
|
fn init(ruby: &Ruby) -> Result<(), Error> {
|
|
609
652
|
let module = ruby.define_module("Expressir")?.define_module("Core")?;
|
|
610
653
|
module.define_singleton_method("parse_to_model_hash", function!(model_json, 2))?;
|
|
611
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))?;
|
|
612
656
|
module.define_singleton_method("parse_to_model", function!(model_object, 2))?;
|
|
613
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
|
+
)?;
|
|
614
662
|
module.define_singleton_method("scan_remarks", function!(scan_remarks, 1))?;
|
|
615
663
|
module.define_singleton_method("write_set", function!(set_write, 3))?;
|
|
616
664
|
let batch_class = module.define_class("BatchStream", ruby.class_object())?;
|
|
@@ -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,14 @@ 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
|
+
|
|
58
81
|
# Semantic checks (issue #21): the Checker's findings over one
|
|
59
82
|
# file's model-hash wire, as an Array of Hashes with
|
|
60
83
|
# id/severity/schema/message in the checker's canonical order.
|
|
@@ -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
|
|
@@ -103,6 +103,15 @@ module Expressir
|
|
|
103
103
|
@cached_schema_grammar_json
|
|
104
104
|
end
|
|
105
105
|
|
|
106
|
+
# Lane retirement (expressir#587): EXPRESSIR_DISABLE_RUBY_PARSE
|
|
107
|
+
# turns the Ruby parse lanes (the artifact replay and the DSL
|
|
108
|
+
# evaluation) into hard failures, so the suite can prove the
|
|
109
|
+
# native lane stands alone. The lanes remain emergency
|
|
110
|
+
# fallbacks without the env.
|
|
111
|
+
def self.ruby_parse_disabled?
|
|
112
|
+
ENV["EXPRESSIR_DISABLE_RUBY_PARSE"] == "1"
|
|
113
|
+
end
|
|
114
|
+
|
|
106
115
|
# Parse using native engine with Rust-side transformation (fastest)
|
|
107
116
|
#
|
|
108
117
|
# This method provides ~17x speedup over pure Ruby parsing.
|
|
@@ -151,6 +160,10 @@ module Expressir
|
|
|
151
160
|
PARG_COMPONENTS_DIR = File.join(__dir__, "parg")
|
|
152
161
|
|
|
153
162
|
def self.parse_artifact(source)
|
|
163
|
+
if ruby_parse_disabled?
|
|
164
|
+
raise NotImplementedError,
|
|
165
|
+
"Ruby parse lanes disabled (EXPRESSIR_DISABLE_RUBY_PARSE)"
|
|
166
|
+
end
|
|
154
167
|
raise LoadError, "Edition-2 artifact not available" unless artifact_available?
|
|
155
168
|
|
|
156
169
|
@parser_mutex.synchronize do
|
|
@@ -168,8 +181,15 @@ module Expressir
|
|
|
168
181
|
# The Ruby-lane parse: the edition-2 artifact first, the DSL
|
|
169
182
|
# parser as fallback (issue #578 STEP 4).
|
|
170
183
|
def self.parse_ruby(source)
|
|
184
|
+
if ruby_parse_disabled?
|
|
185
|
+
raise NotImplementedError,
|
|
186
|
+
"Ruby parse lanes disabled (EXPRESSIR_DISABLE_RUBY_PARSE)"
|
|
187
|
+
end
|
|
188
|
+
|
|
171
189
|
parse_artifact(source)
|
|
172
190
|
rescue StandardError, NotImplementedError
|
|
191
|
+
raise if ruby_parse_disabled?
|
|
192
|
+
|
|
173
193
|
cached_parser.parse(source)
|
|
174
194
|
end
|
|
175
195
|
|
|
@@ -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