parsanol 1.3.41-x86_64-linux → 1.3.42-x86_64-linux

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: 461c98e52da3422c9d778dfd43323ccf6e920f751135d879c7454b2132034ef2
4
- data.tar.gz: e02a2403f3435da4d69618d6e1386631ecd811467446fd80961de4bce4adb456
3
+ metadata.gz: 921de9d0ca0156e3e82f9f7ff4799e36c5be2a18b18cd287867e7942106e100e
4
+ data.tar.gz: da850b7385934eb63bcb245efb3fc0d44ad9757fd9fe37bc53a76d3da8574ccb
5
5
  SHA512:
6
- metadata.gz: 3f63d22e2cfd3c12106ae7a19002224a1497ac8bd3566cac81ff3a46d0f6947352032c4c8e926bf32ff61e46fd705dbeeb9683f379cd92356dfc17c840403e91
7
- data.tar.gz: 1b17f4d57debb2765578754ad0664759bf307e308e179b5c3f863d429eda4b70db374ec3086481bf9ab594d2eec42004095d44fd0b4622ed4d6145c617bc4d9e
6
+ metadata.gz: 9a295616f8ecf188f7fd1f2e0b6b5e0cdb8342c3fdd1abb59d7a4072e4998b3e727aca48fa777b07f2e1cdfb37ea3ead7790962745ae3a3380066ce91faaea54
7
+ data.tar.gz: a3413d8a70e0592af59217372daf826ca115a0e726a7a24dc80d4f97c9a116693a23575da057952588463025b211d928f2bfb42eab5a7cc29bd06405a3e522d1
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Parsanol
4
+ # Incremental parsing over a persistent Rust-side session
5
+ # (TODO.perf/4): the memo window that an edit provably did not
6
+ # touch is retained across parses, so a keystroke re-parse costs
7
+ # the edit's neighborhood instead of the whole document.
8
+ #
9
+ # Grammars with Dynamic atoms are not eligible (no Ruby re-entry
10
+ # while the input is borrowed); build sessions from plain grammars.
11
+ #
12
+ # @example
13
+ # session = Parsanol::IncrementalSession.new(parser.root_atom)
14
+ # session.parse(doc) # full parse
15
+ # session.parse_with_edit(doc, offset: 42, old_length: 1, new_length: 3)
16
+ # session.release
17
+ #
18
+ class IncrementalSession
19
+ # @param root_atom [Object] a grammar root atom (the same object
20
+ # a Parsanol::Parser rule produces)
21
+ def initialize(root_atom)
22
+ unless Native.available?
23
+ raise NativeUnavailable, "parsanol native extension not loaded"
24
+ end
25
+
26
+ @session = Native._incremental_session(Native::Parser.serialize_grammar(root_atom))
27
+ end
28
+
29
+ # Full parse (also the session's first call).
30
+ #
31
+ # @param input [String]
32
+ # @return [Object] the parslet-shaped tree
33
+ def parse(input)
34
+ Native._incremental_parse(@session, input, -1, 0, 0)
35
+ end
36
+
37
+ # Re-parse after a single edit described by its span.
38
+ #
39
+ # @param input [String] the document AFTER the edit
40
+ # @param offset [Integer] byte offset of the edit
41
+ # @param old_length [Integer] bytes removed
42
+ # @param new_length [Integer] bytes inserted
43
+ # @return [Object] the parslet-shaped tree
44
+ def parse_with_edit(input, offset:, old_length:, new_length:)
45
+ Native._incremental_parse(@session, input, offset, old_length, new_length)
46
+ end
47
+
48
+ # Session cache counters: [hits, misses].
49
+ #
50
+ # @return [Array(Integer, Integer)]
51
+ def stats
52
+ Native._incremental_stats(@session)
53
+ end
54
+
55
+ # Free the Rust-side session. The session becomes unusable.
56
+ #
57
+ # @return [Boolean] true when a session was freed
58
+ def release
59
+ released = Native._incremental_release(@session)
60
+ @session = nil
61
+ released
62
+ end
63
+ end
64
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Parsanol
4
- VERSION = "1.3.41"
4
+ VERSION = "1.3.42"
5
5
  end
data/lib/parsanol.rb CHANGED
@@ -265,6 +265,7 @@ module Parsanol
265
265
  module_function :exp
266
266
 
267
267
  autoload :Expression, "parsanol/expression"
268
+ autoload :IncrementalSession, "parsanol/incremental"
268
269
  end
269
270
 
270
271
  require "parsanol/version"
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.41
4
+ version: 1.3.42
5
5
  platform: x86_64-linux
6
6
  authors:
7
7
  - Ribose Inc.
@@ -67,6 +67,7 @@ files:
67
67
  - lib/parsanol/fast_mode.rb
68
68
  - lib/parsanol/first_set.rb
69
69
  - lib/parsanol/grammar_builder.rb
70
+ - lib/parsanol/incremental.rb
70
71
  - lib/parsanol/incremental_parser.rb
71
72
  - lib/parsanol/interval_tree.rb
72
73
  - lib/parsanol/lazy_result.rb