expressir 2.4.55 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b3d75ba4d678e222bdca54971e9351c3b28ccd183624643ea23ecbdbdcc6bc59
4
- data.tar.gz: 119ca50607135311f5b59ce7dde96af55b808856bd670c23a6afeee9c1bd17b8
3
+ metadata.gz: a538e044b224fb0f69703d44d79f683d256113c419a13016de659ef971cde5ca
4
+ data.tar.gz: 3c0fd091a74ed3808cf337cafd146b01f65c4f796f46dd9d61f59cfefa9ad195
5
5
  SHA512:
6
- metadata.gz: '09eefedf81abfb902639ceaea4d22c4cf2d6407f20fae519a2228529813b3e38261d50cd99199d6393894f5e88fa64724da5214e89f39aae985aa3303529ecbb'
7
- data.tar.gz: 983abe96e120404dd0c519f59fd133e7d3952d884b9d9806c421bd4ddbd810ed1ba27863fd3c82cd9aeed5c7dc4824a6dc1a83d9b9089a663fedae3e7a2f3d03
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.24" }
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,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
@@ -211,9 +211,9 @@ module Expressir
211
211
  remarks_attached = false
212
212
  exp_file =
213
213
  begin
214
- if Core.respond_to?(:parse_to_model_attached)
214
+ if Core.respond_to?(:parse_to_model_attached_with_wire)
215
215
  remarks_attached = true
216
- Core.parse_to_model_attached(source, schema_file)
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
@@ -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.55".freeze
6
+ VERSION = "2.4.56".freeze
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: expressir
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.55
4
+ version: 2.4.56
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.