parsanol 1.3.4 → 1.3.5

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: a0f607d039167282c6b08c5b6a41eb8439f4c003d74d0ca50c38851306acbfc2
4
- data.tar.gz: 06ee7d75ed17680449dcb2feaeecea6ca381e43764cd9fb202e20b0d5615ee4a
3
+ metadata.gz: 7dcef7aebbd4f89f81ed82f1f162e4f168e8cc824150b610e434e3cd709219a1
4
+ data.tar.gz: 71f39107f54e66fa5c6fa58dc23a7bfa2287212454caa446c2a7444d506d6a7e
5
5
  SHA512:
6
- metadata.gz: 6c889c8431756d6d50cc6b59d99f62650d1d94376f2f59c561c431255e92e081303b9d1e312ad0f74e231c3065b520ee36a5f06cedabe91576db59ba031f6dfa
7
- data.tar.gz: 19ac606754d24dfaac7711f4ba2552ec67bfd2a37a2da2dfc7f09e54638b90f5aa02798996ab30303227bd10b36746adb48abf459e26a2967b102b734d33365f
6
+ metadata.gz: 398f9bdc287b03f8114568fd061299434bd479556f7163145f7269a18507be521f30f582ad02881d88c5479d794e4dea68c2a5e02b36093e33d9f1efa6130c3c
7
+ data.tar.gz: 1460303b64cb6ae52a04db7b26a9e156895d2acaed5f7634eefe2c530a8662815b03ff4b8fe77c6cb8481c0c4fa8452565228c4428346c6f3ffd4804239a5eb1
data/Cargo.lock CHANGED
@@ -306,7 +306,6 @@ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
306
306
  [[package]]
307
307
  name = "parsanol"
308
308
  version = "0.4.1"
309
- source = "git+https://github.com/parsanol/parsanol-rs?rev=4667017#46670172240420221089cb4da6eaecadb23a0015"
310
309
  dependencies = [
311
310
  "ahash",
312
311
  "getrandom 0.3.4",
@@ -323,7 +322,6 @@ dependencies = [
323
322
  [[package]]
324
323
  name = "parsanol-derive"
325
324
  version = "0.4.1"
326
- source = "git+https://github.com/parsanol/parsanol-rs?rev=4667017#46670172240420221089cb4da6eaecadb23a0015"
327
325
  dependencies = [
328
326
  "proc-macro2",
329
327
  "quote",
@@ -28,11 +28,10 @@ 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 = { git = "https://github.com/parsanol/parsanol-rs", rev = "4667017", features = ["ruby"] }
31
+ parsanol = { git = "https://github.com/parsanol/parsanol-rs", rev = "3eda2c0", features = ["ruby"] }
32
32
 
33
33
  # Logging
34
34
  log = "0.4"
35
35
 
36
36
  [profile.release]
37
37
  lto = "off"
38
-
@@ -16,7 +16,13 @@ module Parsanol
16
16
  return @cached_available unless @cached_available.nil?
17
17
 
18
18
  @cached_available = begin
19
- require 'parsanol/parsanol_native'
19
+ # Try versioned path first (released gem), then non-versioned (local dev)
20
+ ruby_version = RUBY_VERSION.split('.').take(2).join('.')
21
+ begin
22
+ require "parsanol/#{ruby_version}/parsanol_native"
23
+ rescue LoadError
24
+ require 'parsanol/parsanol_native'
25
+ end
20
26
  Parsanol::Native.is_available
21
27
  rescue LoadError
22
28
  false
@@ -128,11 +128,44 @@ module Parsanol
128
128
  # Clear grammar caches (call if grammar changes)
129
129
  def clear_cache
130
130
  Parser.clear_cache
131
+ clear_grammar_cache if available?
132
+ end
133
+
134
+ # Clear the Rust grammar cache to free memory.
135
+ #
136
+ # This is useful for batch processing scenarios where you want to
137
+ # limit memory usage by clearing unused grammars.
138
+ #
139
+ # @return [nil]
140
+ def clear_grammar_cache
141
+ raise LoadError, "Native parser not available" unless available?
142
+ _clear_grammar_cache
143
+ end
144
+
145
+ # Get the current number of cached grammars in Rust.
146
+ #
147
+ # @return [Integer] Number of cached grammars
148
+ def grammar_cache_size
149
+ raise LoadError, "Native parser not available" unless available?
150
+ _grammar_cache_size
151
+ end
152
+
153
+ # Get the grammar cache capacity.
154
+ #
155
+ # @return [Integer] Maximum cache capacity
156
+ def grammar_cache_capacity
157
+ raise LoadError, "Native parser not available" unless available?
158
+ _grammar_cache_capacity
131
159
  end
132
160
 
133
161
  # Get cache statistics
134
162
  def cache_stats
135
- Parser.cache_stats
163
+ stats = Parser.cache_stats
164
+ if available?
165
+ stats[:rust_grammar_cache_size] = grammar_cache_size
166
+ stats[:rust_grammar_cache_capacity] = grammar_cache_capacity
167
+ end
168
+ stats
136
169
  end
137
170
  end
138
171
  end
@@ -83,17 +83,11 @@ module Parsanol
83
83
  "Run `rake compile` to build the extension."
84
84
  end
85
85
 
86
- # Try to use native parallel parsing
87
- if respond_to?(:_parse_batch_parallel, true)
88
- Parsanol::Native.parse_batch_parallel(
89
- grammar_json,
90
- inputs,
91
- num_threads: config.num_threads
92
- )
93
- else
94
- # Fallback to sequential if parallel not available
95
- inputs.map { |input| Parsanol::Native.parse(grammar_json, input) }
96
- end
86
+ Parsanol::Native.parse_batch_parallel(
87
+ grammar_json,
88
+ inputs,
89
+ num_threads: config.num_threads
90
+ )
97
91
  end
98
92
 
99
93
  # Parse multiple inputs in parallel with transformation.
@@ -109,13 +109,14 @@ module Parsanol
109
109
  # result[:name].to_s # => "hello"
110
110
  #
111
111
  def parse(input, mode_or_opts = {}, **kwargs)
112
- if mode_or_opts.is_a?(Hash)
113
- # Legacy API: parse(input, options={})
112
+ if mode_or_opts.is_a?(Hash) && !kwargs.key?(:mode)
113
+ # Legacy API: parse(input, options={}) or parse(input, mode: :ruby)
114
114
  merged = mode_or_opts.merge(kwargs)
115
115
  super(input, merged)
116
116
  else
117
117
  # New API: parse(input, mode:, **options)
118
- dispatch_parse(mode_or_opts, input, kwargs)
118
+ mode = kwargs.delete(:mode) || :ruby
119
+ dispatch_parse(mode, input, kwargs)
119
120
  end
120
121
  end
121
122
 
@@ -130,6 +131,38 @@ module Parsanol
130
131
  inputs.map { |str| parse(str, mode: mode, **opts) }
131
132
  end
132
133
 
134
+ # Clear the Rust grammar cache to free memory.
135
+ #
136
+ # @return [nil]
137
+ # @raise [LoadError] if native parser is not available
138
+ def clear_grammar_cache
139
+ Parsanol::Native.clear_grammar_cache
140
+ end
141
+
142
+ # Get the current number of cached grammars in Rust.
143
+ #
144
+ # @return [Integer] number of cached grammars
145
+ # @raise [LoadError] if native parser is not available
146
+ def grammar_cache_size
147
+ Parsanol::Native.grammar_cache_size
148
+ end
149
+
150
+ # Get the grammar cache capacity.
151
+ #
152
+ # @return [Integer] maximum cache capacity
153
+ # @raise [LoadError] if native parser is not available
154
+ def grammar_cache_capacity
155
+ Parsanol::Native.grammar_cache_capacity
156
+ end
157
+
158
+ # Get cache statistics for both Ruby and Rust caches.
159
+ #
160
+ # @return [Hash] cache statistics including Ruby GRAMMAR_CACHE and Rust grammar cache
161
+ # @raise [LoadError] if native parser is not available for Rust stats
162
+ def cache_stats
163
+ Parsanol::Native.cache_stats
164
+ end
165
+
133
166
  private
134
167
 
135
168
  # Dispatches to the appropriate parsing backend based on mode.
@@ -158,6 +191,9 @@ module Parsanol
158
191
  # @param opts [Hash] parsing options
159
192
  # @return [Object] parse result
160
193
  #
194
+ def parse_ruby(input, opts)
195
+ super
196
+ end
161
197
 
162
198
  # Native extension parsing with Ruby fallback.
163
199
  # Returns results with Slice objects containing position info.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Parsanol
4
- VERSION = '1.3.4'
4
+ VERSION = '1.3.5'
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.4
4
+ version: 1.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.