parsanol 1.3.21 → 1.3.24
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/Cargo.lock +2 -2
- data/lib/parsanol/native.rb +36 -6
- data/lib/parsanol/parser.rb +6 -2
- 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: 0bc2202f0fc776a4211bfdb92685bef4060456ed45f2dcc7d1a6da101ea43b6d
|
|
4
|
+
data.tar.gz: 9fcbbedcd54b53cee1fdf09ff749f3f61f247288f71c5e74ca7684b357603093
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 959e445f1d28863e471658e332596a0c9ad254cad3272011841e29305c27449760c1330bfd7165d8cd81d7dedc44e48d38c582badf1b1592b5b02a16fcfe45f4
|
|
7
|
+
data.tar.gz: ecbaada2b340858f93b22bd30a0065ec5183e688d14783de1cba0b74ba591b9680eeebbc3798302e069c323467197f38809a9fbbf7422a7e12c72e4693add9e8
|
data/Cargo.lock
CHANGED
|
@@ -253,7 +253,7 @@ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
|
|
253
253
|
[[package]]
|
|
254
254
|
name = "parsanol"
|
|
255
255
|
version = "0.5.1"
|
|
256
|
-
source = "git+https://github.com/parsanol/parsanol-rs?branch=main#
|
|
256
|
+
source = "git+https://github.com/parsanol/parsanol-rs?branch=main#0191b5c95ae0808957bd771a68387599f488cb61"
|
|
257
257
|
dependencies = [
|
|
258
258
|
"ahash",
|
|
259
259
|
"getrandom 0.3.4",
|
|
@@ -270,7 +270,7 @@ dependencies = [
|
|
|
270
270
|
[[package]]
|
|
271
271
|
name = "parsanol-derive"
|
|
272
272
|
version = "0.5.1"
|
|
273
|
-
source = "git+https://github.com/parsanol/parsanol-rs?branch=main#
|
|
273
|
+
source = "git+https://github.com/parsanol/parsanol-rs?branch=main#0191b5c95ae0808957bd771a68387599f488cb61"
|
|
274
274
|
dependencies = [
|
|
275
275
|
"proc-macro2",
|
|
276
276
|
"quote",
|
data/lib/parsanol/native.rb
CHANGED
|
@@ -202,14 +202,29 @@ module Parsanol
|
|
|
202
202
|
# native serializer cannot express (e.g. custom atoms). For
|
|
203
203
|
# pre-serialized JSON grammars the native message is wrapped in a
|
|
204
204
|
# Parsanol::ParseFailed directly.
|
|
205
|
+
NATIVE_POS_MARKER = /\n@@parsanol_pos:(\d+)\z/
|
|
206
|
+
|
|
205
207
|
def raise_native_parse_error(error, grammar, input)
|
|
208
|
+
# Native diagnostics: the Rust tracker reports the deepest
|
|
209
|
+
# failure position and the terminals expected there. Build the
|
|
210
|
+
# cause from that directly — the failure path never needs a
|
|
211
|
+
# reporter reparse. The single interpreter pass below stays only
|
|
212
|
+
# to recover inputs from grammars native cannot express.
|
|
213
|
+
if grammar.respond_to?(:parse) && (m = error.message.match(NATIVE_POS_MARKER))
|
|
214
|
+
source = Parsanol::Source.new(input)
|
|
215
|
+
success, value = grammar.run_with_context(source, nil, true)
|
|
216
|
+
return grammar.finalize_result(value) if success
|
|
217
|
+
|
|
218
|
+
pos = m[1].to_i
|
|
219
|
+
msg = error.message.sub(NATIVE_POS_MARKER, "")
|
|
220
|
+
cause = Parsanol::Cause.new(msg, source, pos)
|
|
221
|
+
raise Parsanol::ParseFailed.new(cause.to_s, cause)
|
|
222
|
+
end
|
|
223
|
+
|
|
206
224
|
if grammar.respond_to?(:parse)
|
|
207
|
-
#
|
|
208
|
-
#
|
|
209
|
-
#
|
|
210
|
-
# parslet-compatible cause tree. The native backend has
|
|
211
|
-
# already failed, so a separate plain attempt first would be a
|
|
212
|
-
# wasted parse.
|
|
225
|
+
# No native diagnostics (e.g. incomplete-input errors): one
|
|
226
|
+
# interpreter pass with the reporter attached — a success
|
|
227
|
+
# recovers the tree, a failure raises the cause tree.
|
|
213
228
|
reporter = Parsanol::ErrorReporter::Tree.new
|
|
214
229
|
source = Parsanol::Source.new(input)
|
|
215
230
|
success, value = grammar.run_with_context(source, reporter, true)
|
|
@@ -231,6 +246,21 @@ module Parsanol
|
|
|
231
246
|
raise_native_parse_error(e, grammar_json, input)
|
|
232
247
|
end
|
|
233
248
|
|
|
249
|
+
# Prefix-mode parse (partial match allowed): the grammar registers
|
|
250
|
+
# by handle exactly like #parse; the Rust side returns
|
|
251
|
+
# [value, end_pos] with trailing input unconsumed.
|
|
252
|
+
def parse_prefix(grammar, input)
|
|
253
|
+
handle = Parser.grammar_handle(grammar)
|
|
254
|
+
|
|
255
|
+
begin
|
|
256
|
+
value, end_pos = _parse_handle_prefix(handle, input)
|
|
257
|
+
[value, end_pos]
|
|
258
|
+
rescue ArgumentError
|
|
259
|
+
Parser.invalidate_handle(handle)
|
|
260
|
+
_parse_handle_prefix(Parser.grammar_handle(grammar), input)
|
|
261
|
+
end
|
|
262
|
+
end
|
|
263
|
+
|
|
234
264
|
# Grammar-atom path: registers once and parses by Rust-side handle,
|
|
235
265
|
# so steady-state calls marshal no JSON and copy no input string.
|
|
236
266
|
def parse_atom_grammar(grammar, input)
|
data/lib/parsanol/parser.rb
CHANGED
|
@@ -123,8 +123,7 @@ module Parsanol
|
|
|
123
123
|
# forwarding options via super produces; :mode must be honored
|
|
124
124
|
# wherever it appears, or those callers silently get the native path.
|
|
125
125
|
mode = opts.delete(:mode) ||
|
|
126
|
-
(if Parsanol::Native.available? && !opts.key?(:
|
|
127
|
-
!opts.key?(:reporter)
|
|
126
|
+
(if Parsanol::Native.available? && !opts.key?(:reporter)
|
|
128
127
|
:native
|
|
129
128
|
else
|
|
130
129
|
:ruby
|
|
@@ -219,6 +218,11 @@ module Parsanol
|
|
|
219
218
|
#
|
|
220
219
|
def parse_native(input, opts)
|
|
221
220
|
if Parsanol::Native.available?
|
|
221
|
+
if opts.key?(:prefix) && opts[:prefix]
|
|
222
|
+
value, _end_pos = Parsanol::Native.parse_prefix(root, input)
|
|
223
|
+
return value
|
|
224
|
+
end
|
|
225
|
+
|
|
222
226
|
Parsanol::Native.parse(root, input)
|
|
223
227
|
else
|
|
224
228
|
Parsanol::Atoms::Base.instance_method(:parse).bind_call(self, input,
|
data/lib/parsanol/version.rb
CHANGED