expressir 2.4.53 → 2.4.55

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6c70f7e06244275df09b213f5917da373408b71227f54bd160634a7309d1e0d
4
- data.tar.gz: 1ae03ceaf7c7dd65313fd4ebb1f217dbd33e9c51570656e14b992d00e47eb6d0
3
+ metadata.gz: b3d75ba4d678e222bdca54971e9351c3b28ccd183624643ea23ecbdbdcc6bc59
4
+ data.tar.gz: 119ca50607135311f5b59ce7dde96af55b808856bd670c23a6afeee9c1bd17b8
5
5
  SHA512:
6
- metadata.gz: bfcf10fb86049d1bc82c997607b20d15f86534c7adee0a381ae96b5e61999af19257916a4023a2862abe6feae6efd92e5e4bf6fa6d0febf4edf8b9a813b56247
7
- data.tar.gz: 42a67e50427f0ec1922938f8a71702318aa29c0228dfc180557b4327d7f593b42613df86af372191b4d9c1eca7822d98d8a56d68ffbe045420e786efa6d8a985
6
+ metadata.gz: '09eefedf81abfb902639ceaea4d22c4cf2d6407f20fae519a2228529813b3e38261d50cd99199d6393894f5e88fa64724da5214e89f39aae985aa3303529ecbb'
7
+ data.tar.gz: 983abe96e120404dd0c519f59fd133e7d3952d884b9d9806c421bd4ddbd810ed1ba27863fd3c82cd9aeed5c7dc4824a6dc1a83d9b9089a663fedae3e7a2f3d03
@@ -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.11" }
16
+ expressir-rs = { git = "https://github.com/lutaml/expressir-rs", tag = "v0.1.24" }
17
17
  serde_json = "1.0"
18
18
 
19
19
 
@@ -78,6 +78,27 @@ fn scan_remarks(ruby: &Ruby, source: String) -> Result<magnus::Value, Error> {
78
78
  Ok(array.as_value())
79
79
  }
80
80
 
81
+ /// Removes `source_end_offset` from the wire before hydration: the
82
+ /// model layer declares no such attribute, and lutaml-model's
83
+ /// instantiate rejects unknown keys. The offsets serve the remark
84
+ /// attacher, which has already run by the time this is called.
85
+ fn strip_end_offsets(value: &mut Wire) {
86
+ match value {
87
+ Wire::Object(map) => {
88
+ map.remove("source_end_offset");
89
+ for (_key, item) in map.iter_mut() {
90
+ strip_end_offsets(item);
91
+ }
92
+ }
93
+ Wire::Array(items) => {
94
+ for item in items {
95
+ strip_end_offsets(item);
96
+ }
97
+ }
98
+ _ => {}
99
+ }
100
+ }
101
+
81
102
  /// Resolves `Expressir::Model::*` classes by their wire `_class` name,
82
103
  /// caching each lookup (the class set is closed).
83
104
  #[derive(Default)]
@@ -267,7 +288,11 @@ fn batch_next(ruby: &Ruby, stream: &BatchStream) -> Result<magnus::Value, Error>
267
288
  .expect("wires")
268
289
  .push((path.clone(), wire.clone()));
269
290
  let mut cache = stream.cache.lock().expect("class cache");
270
- let model = value_to_ruby(ruby, &mut cache, &wire)?;
291
+ // The model layer declares no source_end_offset; the wire
292
+ // carries it for the attacher only.
293
+ let mut hydrate_wire = wire.clone();
294
+ strip_end_offsets(&mut hydrate_wire);
295
+ let model = value_to_ruby(ruby, &mut cache, &hydrate_wire)?;
271
296
  triple.push(model)?;
272
297
  triple.push(ruby.qnil())?;
273
298
  }
@@ -367,6 +392,10 @@ fn set_hydrate_one(ruby: &Ruby, reader: &SetReader, wire_path: String) -> Result
367
392
  Error::new(ruby.exception_runtime_error(), format!("{}: {e}", file.wire_path))
368
393
  })?;
369
394
  let mut cache = reader.cache.lock().expect("class cache");
395
+ // The stored wire keeps the attacher's source_end_offset; the model
396
+ // layer does not declare it.
397
+ let mut wire = wire;
398
+ strip_end_offsets(&mut wire);
370
399
  let model = value_to_ruby(ruby, &mut cache, &wire)?;
371
400
  let pair = RArray::with_capacity(2);
372
401
  pair.push(ruby.str_new(&file.wire_path))?;
@@ -387,6 +416,10 @@ fn set_next(ruby: &Ruby, reader: &SetReader) -> Result<magnus::Value, Error> {
387
416
  Error::new(ruby.exception_runtime_error(), format!("{}: {e}", file.wire_path))
388
417
  })?;
389
418
  let mut cache = reader.cache.lock().expect("class cache");
419
+ // The stored wire keeps the attacher's source_end_offset; the model
420
+ // layer does not declare it.
421
+ let mut wire = wire;
422
+ strip_end_offsets(&mut wire);
390
423
  let model = value_to_ruby(ruby, &mut cache, &wire)?;
391
424
  let pair = RArray::with_capacity(2);
392
425
  pair.push(ruby.str_new(&file.wire_path))?;
@@ -465,13 +498,29 @@ fn value_to_ruby(ruby: &Ruby, cache: &mut ClassCache, wire: &Wire) -> Result<mag
465
498
  Ok(array.as_value())
466
499
  }
467
500
  Wire::Object(map) => {
468
- let class_name = map.get("_class").and_then(Wire::as_str).ok_or_else(|| {
469
- Error::new(
470
- ruby.exception_runtime_error(),
471
- "expressir-core: model node without _class",
472
- )
473
- })?;
474
- let klass = cache.resolve(ruby, class_name)?;
501
+ // RemarkInfo wires carry no `_class` (the Ruby map does not
502
+ // render one); their key set is closed, so recognize them
503
+ // structurally and construct through the declared class.
504
+ let is_remark_info = !map.contains_key("_class")
505
+ && map
506
+ .keys()
507
+ .all(|k| matches!(k.as_str(), "text" | "format" | "tag" | "placement" | "region" | "source_offset"));
508
+ let class_name = if is_remark_info {
509
+ "Expressir::Model::RemarkInfo".to_string()
510
+ } else {
511
+ map.get("_class").and_then(Wire::as_str).ok_or_else(|| {
512
+ let mut keys: Vec<&str> = map.keys().map(String::as_str).collect();
513
+ keys.sort_unstable();
514
+ Error::new(
515
+ ruby.exception_runtime_error(),
516
+ format!(
517
+ "expressir-core: model node without _class (keys: {:?})",
518
+ keys
519
+ ),
520
+ )
521
+ })?.to_string()
522
+ };
523
+ let klass = cache.resolve(ruby, &class_name)?;
475
524
  let attrs = RHash::new();
476
525
  let mut null_members: Vec<String> = Vec::new();
477
526
  for (key, item) in map {
@@ -508,15 +557,60 @@ fn model_object(ruby: &Ruby, source: String, path: String) -> Result<magnus::Val
508
557
  )
509
558
  })?;
510
559
  let wire = tree.to_model_json(&path).map_err(|e| parse_error(ruby, e))?;
560
+ let mut wire = wire;
561
+ strip_end_offsets(&mut wire);
511
562
  let mut cache = ClassCache::default();
512
563
  value_to_ruby(ruby, &mut cache, &wire)
513
564
  }
514
565
 
566
+ /// `parse_to_model` with the remark attachment run in the core
567
+ /// (issue #20): the scanner + attacher produce the attached wire before
568
+ /// hydration, so the Ruby lane never runs RemarkAttacher.
569
+ fn model_object_attached(ruby: &Ruby, source: String, path: String) -> Result<magnus::Value, Error> {
570
+ let tree = ParsedTree::parse(&source).map_err(|e| {
571
+ Error::new(
572
+ ruby.exception_runtime_error(),
573
+ format!("expressir-core: parse error: {e:?}"),
574
+ )
575
+ })?;
576
+ let mut wire = tree.to_model_json(&path).map_err(|e| parse_error(ruby, e))?;
577
+ expressir_rs::attach::attach_tagged_remarks(&mut wire, &source);
578
+ expressir_rs::attach::attach_untagged_remarks(&mut wire, &source);
579
+ strip_end_offsets(&mut wire);
580
+ let mut cache = ClassCache::default();
581
+ value_to_ruby(ruby, &mut cache, &wire)
582
+ }
583
+
584
+ /// `check_model_hash(wire_json, dialect)`: the semantic checks over a
585
+ /// wire (issue #21). `wire_json` is the model-hash JSON of one file;
586
+ /// findings come back as hashes with id/severity/schema/message in the
587
+ /// checker's canonical order.
588
+ fn check_model_hash(ruby: &Ruby, wire_json: String, dialect: Option<String>) -> Result<magnus::Value, Error> {
589
+ let mut wire: Wire = serde_json::from_str(&wire_json)
590
+ .map_err(|e| Error::new(ruby.exception_arg_error(), format!("wire: {e}")))?;
591
+ let notes = expressir_rs::checker::check(&mut wire, dialect.as_deref());
592
+ let array = ruby.ary_new_capa(notes.len());
593
+ for note in &notes {
594
+ let hash = ruby.hash_new();
595
+ hash.aset(ruby.sym_new("id"), ruby_str(ruby, &note.id))?;
596
+ hash.aset(ruby.sym_new("severity"), ruby_str(ruby, note.severity))?;
597
+ match &note.schema {
598
+ Some(schema) => hash.aset(ruby.sym_new("schema"), ruby_str(ruby, schema))?,
599
+ None => hash.aset(ruby.sym_new("schema"), ruby.qnil().as_value())?,
600
+ }
601
+ hash.aset(ruby.sym_new("message"), ruby_str(ruby, &note.message))?;
602
+ array.push(hash)?;
603
+ }
604
+ Ok(array.as_value())
605
+ }
606
+
515
607
  #[magnus::init]
516
608
  fn init(ruby: &Ruby) -> Result<(), Error> {
517
609
  let module = ruby.define_module("Expressir")?.define_module("Core")?;
518
610
  module.define_singleton_method("parse_to_model_hash", function!(model_json, 2))?;
611
+ module.define_singleton_method("check_model_hash", function!(check_model_hash, 2))?;
519
612
  module.define_singleton_method("parse_to_model", function!(model_object, 2))?;
613
+ module.define_singleton_method("parse_to_model_attached", function!(model_object_attached, 2))?;
520
614
  module.define_singleton_method("scan_remarks", function!(scan_remarks, 1))?;
521
615
  module.define_singleton_method("write_set", function!(set_write, 3))?;
522
616
  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
@@ -40,6 +40,14 @@ module Expressir
40
40
  JSON.parse(::Expressir::Core.parse_to_model_hash(source, path))
41
41
  end
42
42
 
43
+ # Parse EXPRESS source into the hydrated model with the remark
44
+ # attachment run in the core (issue #20): the wire carries the
45
+ # attached remarks before hydration, so the Ruby RemarkAttacher
46
+ # never runs on this lane.
47
+ def self.parse_to_model_attached(source, path)
48
+ ::Expressir::Core.parse_to_model_attached(source, path)
49
+ end
50
+
43
51
  # Scan remarks (issue #20): an Array of Hashes mirroring
44
52
  # RemarkScanner::Remark's fields (position, end_position, line,
45
53
  # text, tag, format), straight from the Rust scanner.
@@ -47,6 +55,23 @@ module Expressir
47
55
  ::Expressir::Core.scan_remarks(source)
48
56
  end
49
57
 
58
+ # Semantic checks (issue #21): the Checker's findings over one
59
+ # file's model-hash wire, as an Array of Hashes with
60
+ # id/severity/schema/message in the checker's canonical order.
61
+ # `dialect` is nil or a Dialect value; the 1994 edition is
62
+ # translated to the short form the core expects.
63
+ def self.check_model_hash(wire, dialect = nil)
64
+ raise NotImplementedError, "the native extension is unavailable" unless NATIVE_AVAILABLE
65
+
66
+ wire_json = JSON.generate(wire)
67
+ core_dialect = case dialect
68
+ when nil then nil
69
+ when Dialect::EDITION_1994, "10303-11:1994" then "1994"
70
+ else dialect.to_s
71
+ end
72
+ ::Expressir::Core.check_model_hash(wire_json, core_dialect)
73
+ end
74
+
50
75
  # Parse EXPRESS source into the hydrated model directly: the
51
76
  # extension walks the wire definition once and constructs every
52
77
  # node through Serializable.instantiate (lutaml-model's fast
@@ -208,14 +208,21 @@ module Expressir
208
208
  source = strip_bom(File.read(file))
209
209
  schema_file = root_path ? Pathname.new(file.to_s).relative_path_from(root_path).to_s : file.to_s
210
210
 
211
+ remarks_attached = false
211
212
  exp_file =
212
213
  begin
213
- Core.parse_to_model(source, schema_file).tap(&:wire_parents)
214
+ if Core.respond_to?(:parse_to_model_attached)
215
+ remarks_attached = true
216
+ Core.parse_to_model_attached(source, schema_file)
217
+ .tap(&:wire_parents)
218
+ else
219
+ Core.parse_to_model(source, schema_file).tap(&:wire_parents)
220
+ end
214
221
  rescue NotImplementedError
215
222
  begin
216
- Model::ExpFile.from_hash(
217
- Core.parse_to_model_hash(source, schema_file),
218
- )&.tap(&:wire_parents)
223
+ wire = JSON.parse(Core.parse_to_model_hash(source, schema_file))
224
+ strip_end_offsets!(wire)
225
+ Model::ExpFile.from_hash(wire)&.tap(&:wire_parents)
219
226
  rescue StandardError => e
220
227
  raise Error::SchemaParseFailure.new(schema_file, e)
221
228
  end
@@ -224,7 +231,8 @@ module Expressir
224
231
  end
225
232
 
226
233
  finalize_loaded_file(exp_file, source, schema_file,
227
- include_source: include_source)
234
+ include_source: include_source,
235
+ remarks_attached: remarks_attached)
228
236
 
229
237
  unless skip_references
230
238
  Expressir::Benchmark.measure_references do
@@ -240,8 +248,10 @@ module Expressir
240
248
  # Shared post-parse steps for every core-path file: remark
241
249
  # attachment, header-remark transfer, and path wiring.
242
250
  def self.finalize_loaded_file(exp_file, source, schema_file,
243
- include_source: nil)
244
- RemarkAttacher.new(source).attach(exp_file) if source && include_source != false
251
+ include_source: nil, remarks_attached: false)
252
+ if source && include_source != false && !remarks_attached
253
+ RemarkAttacher.new(source).attach(exp_file)
254
+ end
245
255
 
246
256
  transfer_header_to_schema(exp_file, source)
247
257
 
@@ -251,6 +261,21 @@ module Expressir
251
261
  schema.file_basename = File.basename(schema_file, ".exp")
252
262
  end
253
263
  end
264
+
265
+ # The model layer declares no source_end_offset; the wire carries
266
+ # it for the attacher, and the from_hash fallback must not see it.
267
+ def self.strip_end_offsets!(obj)
268
+ case obj
269
+ when Hash
270
+ obj.delete("source_end_offset")
271
+ obj.each_value { |value| strip_end_offsets!(value) }
272
+ when Array
273
+ obj.each { |value| strip_end_offsets!(value) }
274
+ end
275
+ obj
276
+ end
277
+ private_class_method :strip_end_offsets!
278
+
254
279
  private_class_method :finalize_loaded_file
255
280
 
256
281
  # Whether the native batch compiler is usable: the extension is
@@ -3,6 +3,6 @@ module Expressir
3
3
  # autoload it (Ruby autoload only works for module/class constants, not
4
4
  # for string constants like `Expressir::VERSION`).
5
5
  module Version
6
- VERSION = "2.4.53".freeze
6
+ VERSION = "2.4.55".freeze
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: expressir
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.53
4
+ version: 2.4.55
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2026-11-03 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rb_sys
@@ -807,7 +806,6 @@ metadata:
807
806
  source_code_uri: https://github.com/lutaml/expressir
808
807
  changelog_uri: https://github.com/lutaml/expressir/releases
809
808
  rubygems_mfa_required: 'true'
810
- post_install_message:
811
809
  rdoc_options: []
812
810
  require_paths:
813
811
  - lib
@@ -822,8 +820,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
822
820
  - !ruby/object:Gem::Version
823
821
  version: '0'
824
822
  requirements: []
825
- rubygems_version: 3.5.22
826
- signing_key:
823
+ rubygems_version: 3.6.9
827
824
  specification_version: 4
828
825
  summary: EXPRESS parser and toolkit for Ruby
829
826
  test_files: []