parsanol 1.3.37 → 1.3.38

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: f3ee6550442261f9f42d66c0b51e9b5fe5f186c54c9b36a2932abc0410608a42
4
- data.tar.gz: 9f0476cfd0d65c1642c81bf86bd36a2a0a6627d1c2978ba65f00989e84e6bd44
3
+ metadata.gz: 8160526df9d517b13742be64b4507b1d5ce7b036045ac28427bea31b0c1b95ab
4
+ data.tar.gz: dc5287c93e31034c8421274be3c383db30d0d81a896f948e30edc96fb5d7be3e
5
5
  SHA512:
6
- metadata.gz: b1dbb402205ebfb234148f7f87b5d9bcf6cd201b7f72f3c73bd096c7a0c3ba092582ad1a37a543f1665fd2542d8b2c6841b5ca9e4f21525a2ecfac68e343bad7
7
- data.tar.gz: dc490cc9e39a4feb101139c1fd9a2d47e5509d495cb99920f6856cf65eac3303147e8cb95c13b25f8086d2fc31cb77be5193438527e28d4d261f08f28a7842cb
6
+ metadata.gz: 382334b59ceb6e08c8615cbd36895d8c9c3bf5f2f7f94767b0ff3d552734d1659d85ce7e3840aac23cd756504708857cc2ca82cab15cceb855ee88954021420f
7
+ data.tar.gz: 68ca0460ab220b9ded30c07d1d08a2e2f368b2173d655deaef82e13ffd91564c6a0f37bb92b3c4c145fd506dfb5f3a61dbfcf2fa4fbfcf0eea45d83fd6cb0c06
@@ -28,7 +28,7 @@ rb-sys = { version = "0.9.124", features = ["global-allocator"] }
28
28
  magnus = { version = "0.9" }
29
29
 
30
30
  # parsanol parser library (from git for latest features)
31
- parsanol = { version = "0.7.3", features = ["ruby"] }
31
+ parsanol = { version = "0.7.4", features = ["ruby"] }
32
32
 
33
33
  # Logging
34
34
  log = "0.4"
@@ -123,6 +123,15 @@ module Parsanol
123
123
  # Override to disable caching for simple atoms.
124
124
  #
125
125
  # @return [Boolean]
126
+ # Single-atom JSON in the native grammar format
127
+ # ({"Str":{"pattern":"a"}}, ...). Protocol for dynamic-atom
128
+ # callbacks whose blocks return atoms: the Rust callback bridge
129
+ # resolves the returned value through this method.
130
+ def to_atom_json
131
+ require "parsanol/native"
132
+ Parsanol::GrammarSerializer.atom_json(self)
133
+ end
134
+
126
135
  def cached?
127
136
  true
128
137
  end
@@ -27,6 +27,9 @@ module Parsanol
27
27
  block = @block
28
28
  result = block.call(source, context)
29
29
 
30
+ # A nil return fails the atom (native callback parity).
31
+ return context.err(self, source, "dynamic block returned nil") if result.nil?
32
+
30
33
  # Result is a parslet atom.
31
34
  result.apply(source, context, consume_all)
32
35
  end
@@ -29,6 +29,13 @@ module Parsanol
29
29
  %({"atoms":#{@atoms.to_json},"root":#{root_id}})
30
30
  end
31
31
 
32
+ # Grammar JSON for dynamic-atom callbacks: {"atoms":[...],"root":N}.
33
+ # The Rust bridge inlines the referenced atoms into a self-contained
34
+ # atom tree before running it.
35
+ def self.atom_json(atom)
36
+ serialize(atom)
37
+ end
38
+
32
39
  private
33
40
 
34
41
  # Serialize a single atom and return its atom_id
@@ -155,40 +162,20 @@ module Parsanol
155
162
  nil
156
163
  end
157
164
 
158
- if parslet
159
- # Serialize the resolved parslet inline (don't call serialize_atom to avoid double-caching)
160
- serialized = case parslet
161
- when Parsanol::Atoms::Str
162
- serialize_str(parslet)
163
- when Parsanol::Atoms::Re
164
- serialize_re(parslet)
165
- when Parsanol::Atoms::Sequence
166
- serialize_sequence(parslet)
167
- when Parsanol::Atoms::Alternative
168
- serialize_alternative(parslet)
169
- when Parsanol::Atoms::Repetition
170
- serialize_repetition(parslet)
171
- when Parsanol::Atoms::Named
172
- serialize_named(parslet)
173
- when Parsanol::Atoms::Entity
174
- # Nested entity - just reference it via serialize_atom
175
- { "Entity" => { "atom" => serialize_atom(parslet) } }
176
- when Parsanol::Atoms::Lookahead
177
- serialize_lookahead(parslet)
178
- else
179
- serialize_unknown(parslet)
180
- end
181
-
182
- # Replace the placeholder with the serialized atom
183
- @atoms[atom_id] = serialized
184
- else
185
- # If the entity's block returns nil, create a placeholder that will fail
186
- @atoms[atom_id] = {
187
- "Str" => {
188
- "pattern" => "\x00__UNIMPLEMENTED_ENTITY_#{atom.name}__",
189
- },
190
- }
191
- end
165
+ # Serialize the resolved parslet via the normal dispatch. A
166
+ # uniform Entity reference keeps every atom type supported here
167
+ # (a duplicated inline table once dropped Dynamic/Capture/Scope
168
+ # and made every rule-wrapped Dynamic atom unserializable).
169
+ @atoms[atom_id] = if parslet
170
+ { "Entity" => { "atom" => serialize_atom(parslet) } }
171
+ else
172
+ # If the entity's block returns nil, create a placeholder that will fail
173
+ {
174
+ "Str" => {
175
+ "pattern" => "\x00__UNIMPLEMENTED_ENTITY_#{atom.name}__",
176
+ },
177
+ }
178
+ end
192
179
  atom_id
193
180
  end
194
181
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Parsanol
4
- VERSION = "1.3.37"
4
+ VERSION = "1.3.38"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parsanol
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.37
4
+ version: 1.3.38
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.