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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9eb43d37e76e0d2483832c1d9f9d3f32b5ea66304b21c4aa0f1c6cb86731f81c
4
- data.tar.gz: adf4a7e05cddc6b4da594f4ad7fc14df058444ba13bfce9008830bbf96c37c9d
3
+ metadata.gz: 0bc2202f0fc776a4211bfdb92685bef4060456ed45f2dcc7d1a6da101ea43b6d
4
+ data.tar.gz: 9fcbbedcd54b53cee1fdf09ff749f3f61f247288f71c5e74ca7684b357603093
5
5
  SHA512:
6
- metadata.gz: 78115ec7794cd6587de1fbee17583027faabd1bc282aeda18d5cd3f26c6e1540d25f2ece6ae701de54405fc4d6fad960f030ee235c43545e70071c794aebe41a
7
- data.tar.gz: 7cdfc3b8811cdd777085aec1333217602dfd0cbb19572e00c4b6b351182963495bc5add5b79b7b91eec7be3c2db61e27638f1aa43c4a591933eb7ed2c2e19c43
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#9076b51c4a6a4921751fbc59674d3769637b526f"
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#9076b51c4a6a4921751fbc59674d3769637b526f"
273
+ source = "git+https://github.com/parsanol/parsanol-rs?branch=main#0191b5c95ae0808957bd771a68387599f488cb61"
274
274
  dependencies = [
275
275
  "proc-macro2",
276
276
  "quote",
@@ -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
- # One interpreter pass with the error reporter attached covers
208
- # both jobs: a success means the native backend could not
209
- # express the grammar (recover the tree), a failure raises the
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)
@@ -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?(:prefix) &&
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,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Parsanol
4
- VERSION = "1.3.21"
4
+ VERSION = "1.3.24"
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.21
4
+ version: 1.3.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.