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 +4 -4
- data/ext/parsanol_native/Cargo.toml +1 -1
- data/lib/parsanol/atoms/base.rb +9 -0
- data/lib/parsanol/atoms/dynamic.rb +3 -0
- data/lib/parsanol/native/serializer.rb +21 -34
- data/lib/parsanol/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: 8160526df9d517b13742be64b4507b1d5ce7b036045ac28427bea31b0c1b95ab
|
|
4
|
+
data.tar.gz: dc5287c93e31034c8421274be3c383db30d0d81a896f948e30edc96fb5d7be3e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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.
|
|
31
|
+
parsanol = { version = "0.7.4", features = ["ruby"] }
|
|
32
32
|
|
|
33
33
|
# Logging
|
|
34
34
|
log = "0.4"
|
data/lib/parsanol/atoms/base.rb
CHANGED
|
@@ -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
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
|
data/lib/parsanol/version.rb
CHANGED