parsanol 1.3.8 → 1.3.9

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: ca5f39af8b6ed42fb15609ae995687d58531d88b899a7c81fd708b2e36f9cf8d
4
- data.tar.gz: 2a1d92d10d6f258ba0f79de6d6df22ffab5993ba8bc60f4ddfcbbc86a036546b
3
+ metadata.gz: eb19c18264a1e1c6e26dfb2bab0ff9c9fd005f631423b918240a321e2470848a
4
+ data.tar.gz: 49af7d190c09e38ec7c46a168e0f2a20bbbfd4afe1d63b006becbe20b69e14f5
5
5
  SHA512:
6
- metadata.gz: bede99bb9de3cef6a3cb934c3405114bc082fd7e071d3ec320739b93ecedb73bc114d41452cacd9ef3337ca950047916b48ba3d3001f46accf813ec8e2338e3d
7
- data.tar.gz: 7f29093ef0e2023dffbbb8a5bcffd0c8e59a99a247ca73361e349c62e4defdb2039afe31c0b5c29050074b93767dfd187931ec567051b9bf30f23577ab7b1fc3
6
+ metadata.gz: 58f02929ffcffb52c15fad2545f9fb36076e8396ec04ca90ea5c1d1a8186b5cd242b11fc415127906bccf724d3da3f175ad67c2b54ced828ad61a286802e6648
7
+ data.tar.gz: 3581460ba7dd3cd81634ab19fbb405c6220ac6d0084b0c9d1d13a8232d5d700346c560a76b6eaf610ff30c967b506c10fcb87879d4df46a18c2a2615feac261f
data/Cargo.lock CHANGED
@@ -206,15 +206,15 @@ dependencies = [
206
206
 
207
207
  [[package]]
208
208
  name = "itoa"
209
- version = "1.0.17"
209
+ version = "1.0.18"
210
210
  source = "registry+https://github.com/rust-lang/crates.io-index"
211
- checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2"
211
+ checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
212
212
 
213
213
  [[package]]
214
214
  name = "js-sys"
215
- version = "0.3.91"
215
+ version = "0.3.92"
216
216
  source = "registry+https://github.com/rust-lang/crates.io-index"
217
- checksum = "b49715b7073f385ba4bc528e5747d02e66cb39c6146efb66b781f131f0fb399c"
217
+ checksum = "cc4c90f45aa2e6eacbe8645f77fdea542ac97a494bcd117a67df9ff4d611f995"
218
218
  dependencies = [
219
219
  "once_cell",
220
220
  "wasm-bindgen",
@@ -305,8 +305,8 @@ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
305
305
 
306
306
  [[package]]
307
307
  name = "parsanol"
308
- version = "0.4.1"
309
- source = "git+https://github.com/parsanol/parsanol-rs?rev=3716de2#3716de22dc7e371e2dfb59bb28f443d0d1550b9e"
308
+ version = "0.5.0"
309
+ source = "git+https://github.com/parsanol/parsanol-rs?branch=main#99a5a2f3fa292ce506cda9ea7a6d5403abd5e8a0"
310
310
  dependencies = [
311
311
  "ahash",
312
312
  "getrandom 0.3.4",
@@ -322,8 +322,8 @@ dependencies = [
322
322
 
323
323
  [[package]]
324
324
  name = "parsanol-derive"
325
- version = "0.4.1"
326
- source = "git+https://github.com/parsanol/parsanol-rs?rev=3716de2#3716de22dc7e371e2dfb59bb28f443d0d1550b9e"
325
+ version = "0.5.0"
326
+ source = "git+https://github.com/parsanol/parsanol-rs?branch=main#99a5a2f3fa292ce506cda9ea7a6d5403abd5e8a0"
327
327
  dependencies = [
328
328
  "proc-macro2",
329
329
  "quote",
@@ -439,9 +439,9 @@ checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a"
439
439
 
440
440
  [[package]]
441
441
  name = "rustc-hash"
442
- version = "2.1.1"
442
+ version = "2.1.2"
443
443
  source = "registry+https://github.com/rust-lang/crates.io-index"
444
- checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d"
444
+ checksum = "94300abf3f1ae2e2b8ffb7b58043de3d399c73fa6f4b73826402a5c457614dbe"
445
445
 
446
446
  [[package]]
447
447
  name = "rustversion"
@@ -565,9 +565,9 @@ dependencies = [
565
565
 
566
566
  [[package]]
567
567
  name = "wasm-bindgen"
568
- version = "0.2.114"
568
+ version = "0.2.115"
569
569
  source = "registry+https://github.com/rust-lang/crates.io-index"
570
- checksum = "6532f9a5c1ece3798cb1c2cfdba640b9b3ba884f5db45973a6f442510a87d38e"
570
+ checksum = "6523d69017b7633e396a89c5efab138161ed5aafcbc8d3e5c5a42ae38f50495a"
571
571
  dependencies = [
572
572
  "cfg-if",
573
573
  "once_cell",
@@ -578,9 +578,9 @@ dependencies = [
578
578
 
579
579
  [[package]]
580
580
  name = "wasm-bindgen-macro"
581
- version = "0.2.114"
581
+ version = "0.2.115"
582
582
  source = "registry+https://github.com/rust-lang/crates.io-index"
583
- checksum = "18a2d50fcf105fb33bb15f00e7a77b772945a2ee45dcf454961fd843e74c18e6"
583
+ checksum = "4e3a6c758eb2f701ed3d052ff5737f5bfe6614326ea7f3bbac7156192dc32e67"
584
584
  dependencies = [
585
585
  "quote",
586
586
  "wasm-bindgen-macro-support",
@@ -588,9 +588,9 @@ dependencies = [
588
588
 
589
589
  [[package]]
590
590
  name = "wasm-bindgen-macro-support"
591
- version = "0.2.114"
591
+ version = "0.2.115"
592
592
  source = "registry+https://github.com/rust-lang/crates.io-index"
593
- checksum = "03ce4caeaac547cdf713d280eda22a730824dd11e6b8c3ca9e42247b25c631e3"
593
+ checksum = "921de2737904886b52bcbb237301552d05969a6f9c40d261eb0533c8b055fedf"
594
594
  dependencies = [
595
595
  "bumpalo",
596
596
  "proc-macro2",
@@ -601,9 +601,9 @@ dependencies = [
601
601
 
602
602
  [[package]]
603
603
  name = "wasm-bindgen-shared"
604
- version = "0.2.114"
604
+ version = "0.2.115"
605
605
  source = "registry+https://github.com/rust-lang/crates.io-index"
606
- checksum = "75a326b8c223ee17883a4251907455a2431acc2791c98c26279376490c378c16"
606
+ checksum = "a93e946af942b58934c604527337bad9ae33ba1d5c6900bbb41c2c07c2364a93"
607
607
  dependencies = [
608
608
  "unicode-ident",
609
609
  ]
@@ -738,18 +738,18 @@ dependencies = [
738
738
 
739
739
  [[package]]
740
740
  name = "zerocopy"
741
- version = "0.8.42"
741
+ version = "0.8.48"
742
742
  source = "registry+https://github.com/rust-lang/crates.io-index"
743
- checksum = "f2578b716f8a7a858b7f02d5bd870c14bf4ddbbcf3a4c05414ba6503640505e3"
743
+ checksum = "eed437bf9d6692032087e337407a86f04cd8d6a16a37199ed57949d415bd68e9"
744
744
  dependencies = [
745
745
  "zerocopy-derive",
746
746
  ]
747
747
 
748
748
  [[package]]
749
749
  name = "zerocopy-derive"
750
- version = "0.8.42"
750
+ version = "0.8.48"
751
751
  source = "registry+https://github.com/rust-lang/crates.io-index"
752
- checksum = "7e6cc098ea4d3bd6246687de65af3f920c430e236bee1e3bf2e441463f08a02f"
752
+ checksum = "70e3cd084b1788766f53af483dd21f93881ff30d7320490ec3ef7526d203bad4"
753
753
  dependencies = [
754
754
  "proc-macro2",
755
755
  "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 = { git = "https://github.com/parsanol/parsanol-rs", rev = "3716de2", features = ["ruby"] }
31
+ parsanol = { git = "https://github.com/parsanol/parsanol-rs", branch = "main", features = ["ruby"] }
32
32
 
33
33
  # Logging
34
34
  log = "0.4"
@@ -323,9 +323,26 @@ module Parsanol
323
323
  all_items_are_hashes = non_hash_items.empty?
324
324
 
325
325
  if all_items_are_hashes
326
- # Merge all inner hashes into merged_hash
327
- item.each do |sub_item|
328
- merged_hash.merge!(sub_item) if sub_item.is_a?(Hash)
326
+ # Check if merging would overwrite existing keys in merged_hash.
327
+ # If so, this is a repetition pattern (item >> (sep >> item).repeat)
328
+ # and should be kept as array, not merged.
329
+ # Example: merged_hash={namedTypeOrRename: A}, array=[{namedTypeOrRename: B}]
330
+ # → should produce [{namedTypeOrRename: A}, {namedTypeOrRename: B}]
331
+ existing_keys = merged_hash.keys
332
+ shares_keys = item.any? do |sub_item|
333
+ sub_item.is_a?(Hash) && sub_item.keys.intersect?(existing_keys)
334
+ end
335
+
336
+ if shares_keys
337
+ has_non_empty_array = true
338
+ item.each do |sub_item|
339
+ hash_count += 1 if sub_item.is_a?(Hash)
340
+ end
341
+ total_items += 1
342
+ else
343
+ item.each do |sub_item|
344
+ merged_hash.merge!(sub_item) if sub_item.is_a?(Hash)
345
+ end
329
346
  end
330
347
  else
331
348
  # Non-empty repetition with non-hash items - mark that we should keep as array
@@ -57,6 +57,27 @@ module Parsanol
57
57
  grammar_atom)
58
58
  end
59
59
 
60
+ # Memory-bounded parsing without packrat cache.
61
+ #
62
+ # This creates a fresh arena and empty cache per call, bounding memory
63
+ # to AST size rather than input × atoms. Use for large files.
64
+ #
65
+ # @param grammar [Parsanol::Atoms::Base] Ruby grammar definition
66
+ # @param input [String] Input string to parse
67
+ # @return [Hash, Array, Parsanol::Slice] Transformed AST
68
+ def parse_fresh(grammar, input)
69
+ raise LoadError, "Native parser not available" unless available?
70
+
71
+ grammar_json = if grammar.is_a?(String)
72
+ grammar
73
+ else
74
+ Parser.serialize_grammar(grammar)
75
+ end
76
+
77
+ raw_ast = _parse_fresh_raw(grammar_json, input)
78
+ BatchDecoder.decode_and_flatten(raw_ast, input, Parsanol::Slice, grammar)
79
+ end
80
+
60
81
  # Parse and return RAW AST without transformation.
61
82
  #
62
83
  # This returns the raw Parslet intermediate format before any transformation.
@@ -67,6 +67,10 @@ module Parsanol
67
67
 
68
68
  alias length size
69
69
 
70
+ def empty?
71
+ content.empty?
72
+ end
73
+
70
74
  def +(other)
71
75
  self.class.new(@byte_position, content + other.to_s, @input)
72
76
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Parsanol
4
- VERSION = "1.3.8"
4
+ VERSION = "1.3.9"
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.8
4
+ version: 1.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.