parsanol 1.3.90 → 1.3.91

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: 990d56f1eade7c92ce7e2c2eee1fb7d40dcb5f20d65e908ca96de667f52e3e04
4
- data.tar.gz: 266ccec852e0e33bd3ff716be9a4cfaa7585da8e7c1bf29150f3e06c20c2868a
3
+ metadata.gz: 2876669149be4d6b90a15246708d4a40ef6bb75d0d2991b53485cff21abd768e
4
+ data.tar.gz: 1750418bf4195336601f90f0bc67bf8dd669069440def4be0ceba728f7a0ef47
5
5
  SHA512:
6
- metadata.gz: 2d83cc5f03a2e59ddad9b3dabe3b3ae2fcf4848ef0863d772838d82f2c4cb63581440e3c47e5d13dea24ca55c733c22a678f2c55438504a625b73ba7a9a3fd35
7
- data.tar.gz: 426f89a6fead4a7bddcee5618881593914015e12b32abeafa470bd0a467c03f4bbca45733455978f6a4f9838a49f677f02006e2eceb9353de79947a8317b736d
6
+ metadata.gz: 6ba314ff5ac132d5bb04470b024e8df3b45e1736ae64a5a5ddfa743a96fbd6971211cf9e0a2fa31be1a6d24ed9b5a612ee685f6d3ad11e5e97b9adb6875c356a
7
+ data.tar.gz: f50c7d6d2e8dcb09588127755fdc12a60917406b3ee2be068f8309138a8d36f4c92175e661915484872aa3b989c51e306b741a30e2e11073866d992df68251ab
@@ -77,6 +77,13 @@ module Parsanol
77
77
  # `skip = trivia capture: comments` shape) instead of being
78
78
  # discarded; whitespace-shaped units never record.
79
79
  #
80
+ # +exempt:+ (parsanol-ruby#195) lists rule names whose bodies
81
+ # build WITHOUT injection — the DSL mirror of the PARG
82
+ # compiler's automatic skip-rule-closure exemption. Declare it
83
+ # for rules that manage their own trivia explicitly (expressir's
84
+ # remark rules): a wrapper inside them consumes text the rule
85
+ # itself captures, corrupting the value and double-recording it.
86
+ #
80
87
  # @example
81
88
  # class MyParser < Parsanol::Parser
82
89
  # rule(:spaces) { match(/[ \t]/).repeat(1) }
data/lib/parsanol/skip.rb CHANGED
@@ -41,11 +41,46 @@ module Parsanol
41
41
 
42
42
  markers = capturer_markers(parser_instance, captures)
43
43
  whitespace_kind = whitespace&.to_sym
44
- exempt_names = exempt.nil? ? nil : Set.new(exempt.map(&:to_s))
44
+ exempt_names = Set.new(exempt.nil? ? [] : exempt.map(&:to_s))
45
+ exempt_names.merge(closure_names(skip_atom))
45
46
  injector = Injector.new(skip_atom, markers, whitespace_kind, exempt_names)
46
47
  [injector.inject(root_atom, entry: true), skip_atom]
47
48
  end
48
49
 
50
+ # The skip rule's transitive rule-reference closure (parsanol-ruby#195
51
+ # follow-up): those rule bodies build without injection — the same
52
+ # exemption the PARG compiler applies to its skip declaration's
53
+ # closure. The docstring promised this; the code exempted only the
54
+ # skip atom itself. Rules the grammar manages explicitly stay
55
+ # declarable through +exempt:+ (their names merge with these).
56
+ def self.closure_names(skip_atom)
57
+ names = Set.new
58
+ seen = {}.compare_by_identity
59
+ queue = [skip_atom]
60
+ until queue.empty?
61
+ node = queue.shift
62
+ next if node.nil? || seen.key?(node)
63
+
64
+ seen[node] = true
65
+ case node
66
+ when Atoms::Entity
67
+ names << node.rule_name.to_s
68
+ begin
69
+ queue << node.parslet
70
+ rescue StandardError
71
+ nil
72
+ end
73
+ else
74
+ queue.concat(node.parslets) if node.respond_to?(:parslets)
75
+ queue.concat(node.alternatives) if node.respond_to?(:alternatives)
76
+ queue << node.parslet if node.respond_to?(:parslet)
77
+ queue << node.bound_parslet if node.respond_to?(:bound_parslet)
78
+ queue << node.wrapped_atom if node.respond_to?(:wrapped_atom)
79
+ end
80
+ end
81
+ names
82
+ end
83
+
49
84
  # Derives each capturer's leading literal (the leftmost Str the
50
85
  # rule can start with) and keys the marker table by it — the same
51
86
  # derivation the PARG compiler applies to its skip declaration. A
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Parsanol
4
- VERSION = "1.3.90"
4
+ VERSION = "1.3.91"
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.90
4
+ version: 1.3.91
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.