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 +4 -4
- data/lib/parsanol/parser.rb +7 -0
- data/lib/parsanol/skip.rb +36 -1
- data/lib/parsanol/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2876669149be4d6b90a15246708d4a40ef6bb75d0d2991b53485cff21abd768e
|
|
4
|
+
data.tar.gz: 1750418bf4195336601f90f0bc67bf8dd669069440def4be0ceba728f7a0ef47
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6ba314ff5ac132d5bb04470b024e8df3b45e1736ae64a5a5ddfa743a96fbd6971211cf9e0a2fa31be1a6d24ed9b5a612ee685f6d3ad11e5e97b9adb6875c356a
|
|
7
|
+
data.tar.gz: f50c7d6d2e8dcb09588127755fdc12a60917406b3ee2be068f8309138a8d36f4c92175e661915484872aa3b989c51e306b741a30e2e11073866d992df68251ab
|
data/lib/parsanol/parser.rb
CHANGED
|
@@ -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? ?
|
|
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
|
data/lib/parsanol/version.rb
CHANGED