parsanol 1.3.41 → 1.3.42
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 +4 -4
- data/ext/parsanol_native/Cargo.toml +1 -1
- data/lib/parsanol/incremental.rb +64 -0
- data/lib/parsanol/version.rb +1 -1
- data/lib/parsanol.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 33fefbd372a900edbe186fa42f8400ad033f65263f6e06dbf5f751c4ab5b2ec2
|
|
4
|
+
data.tar.gz: 41dd91ecda47d9efeca8cdbe8a12a4231b44b5bdbf8c263da5d855c216ecc660
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 56c477c1a26fd62974793a7ad354f9ce0a7cc7036ccc2ff2179a720b4be81c5c45cd6e1a96c0d97d189250e2f1ae7fc4d34ba2e1bd16e531e72c0c081cb959e0
|
|
7
|
+
data.tar.gz: d3f341956f358e26251fc7487ef30fbb8325848166b30c0f6805f3cc705bf1f9a7f3124c454c50f57a008d1885a31c4fa8bd48c2131be11a7756632a9ee102e6
|
data/Cargo.lock
CHANGED
|
@@ -252,9 +252,9 @@ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
|
|
252
252
|
|
|
253
253
|
[[package]]
|
|
254
254
|
name = "parsanol"
|
|
255
|
-
version = "0.7.
|
|
255
|
+
version = "0.7.7"
|
|
256
256
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
257
|
-
checksum = "
|
|
257
|
+
checksum = "d188dfa10e70efb88ef81d209414cdbceec89bf411b612b67335ca7a5deaa199"
|
|
258
258
|
dependencies = [
|
|
259
259
|
"ahash",
|
|
260
260
|
"getrandom 0.3.4",
|
|
@@ -270,9 +270,9 @@ dependencies = [
|
|
|
270
270
|
|
|
271
271
|
[[package]]
|
|
272
272
|
name = "parsanol-derive"
|
|
273
|
-
version = "0.7.
|
|
273
|
+
version = "0.7.7"
|
|
274
274
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
275
|
-
checksum = "
|
|
275
|
+
checksum = "93f5d33a040f1f99c30274764db11bbe84b2dbd5170fc2f6c2574da2dc42c8db"
|
|
276
276
|
dependencies = [
|
|
277
277
|
"proc-macro2",
|
|
278
278
|
"quote",
|
|
@@ -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.7", features = ["ruby"] }
|
|
32
32
|
|
|
33
33
|
# Logging
|
|
34
34
|
log = "0.4"
|
|
@@ -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
|
data/lib/parsanol/version.rb
CHANGED
data/lib/parsanol.rb
CHANGED
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.
|
|
4
|
+
version: 1.3.42
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
@@ -82,6 +82,7 @@ files:
|
|
|
82
82
|
- lib/parsanol/fast_mode.rb
|
|
83
83
|
- lib/parsanol/first_set.rb
|
|
84
84
|
- lib/parsanol/grammar_builder.rb
|
|
85
|
+
- lib/parsanol/incremental.rb
|
|
85
86
|
- lib/parsanol/incremental_parser.rb
|
|
86
87
|
- lib/parsanol/interval_tree.rb
|
|
87
88
|
- lib/parsanol/lazy_result.rb
|