kpeg 1.3.2 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +9 -0
- data/Rakefile +6 -0
- data/examples/calculator/calculator.kpeg +1 -1
- data/kpeg.gemspec +1 -1
- data/lib/kpeg/compiled_parser.rb +2 -0
- data/lib/kpeg/format_parser.rb +2 -0
- data/lib/kpeg/grammar.rb +1 -11
- data/lib/kpeg/string_escape.rb +2 -0
- data/test/test_kpeg_compiled_parser.rb +57 -0
- 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: d833890a30055ccb0575be00d3ef66bfcb447d3b18f518d2ed3dfb2aa273eec7
|
4
|
+
data.tar.gz: 3e056a615b305db820064549a9a94292aadc19a9af20293f9939ae4305897536
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3becd99c88978dd486ecb9db5074ed453f8b953bd29d5a22fb8e112e66b5deb5d2d199b791077e16a10734b6d1de61f3d381ec5461c8e531399df2e2eda75150
|
7
|
+
data.tar.gz: 44a83605de6a673d5cc1ac98017680581d374595a6eb028c08ed09098f433e7d297775b9474dcef8737c1483e0a19b6dac34574423c0a600fc0308cf70e2dab4
|
data/History.txt
CHANGED
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ space = " "
|
|
9
9
|
num = < /[1-9][0-9]*/ > { text.to_i }
|
10
10
|
|
11
11
|
term = term:t1 - "+" - term:t2 { t1 + t2 }
|
12
|
-
| term:t1 - "-" -
|
12
|
+
| term:t1 - "-" - term:t2 { t1 - t2 }
|
13
13
|
| fact
|
14
14
|
fact = fact:f1 - "*" - fact:f2 { f1 * f2 }
|
15
15
|
| fact:f1 - "/" - fact:f2 { f1 / f2 }
|
data/kpeg.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "kpeg"
|
5
|
-
s.version = "1.3.
|
5
|
+
s.version = "1.3.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.metadata = { "bug_tracker_uri" => "https://github.com/evanphx/kpeg/issues", "homepage_uri" => "https://github.com/evanphx/kpeg" } if s.respond_to? :metadata=
|
data/lib/kpeg/compiled_parser.rb
CHANGED
@@ -227,6 +227,7 @@ module KPeg
|
|
227
227
|
end
|
228
228
|
|
229
229
|
def apply_with_args(rule, *args)
|
230
|
+
@result = nil
|
230
231
|
memo_key = [rule, args]
|
231
232
|
if m = @memoizations[memo_key][@pos]
|
232
233
|
@pos = m.pos
|
@@ -260,6 +261,7 @@ module KPeg
|
|
260
261
|
end
|
261
262
|
|
262
263
|
def apply(rule)
|
264
|
+
@result = nil
|
263
265
|
if m = @memoizations[rule][@pos]
|
264
266
|
@pos = m.pos
|
265
267
|
if !m.set
|
data/lib/kpeg/format_parser.rb
CHANGED
@@ -277,6 +277,7 @@ class KPeg::FormatParser
|
|
277
277
|
end
|
278
278
|
|
279
279
|
def apply_with_args(rule, *args)
|
280
|
+
@result = nil
|
280
281
|
memo_key = [rule, args]
|
281
282
|
if m = @memoizations[memo_key][@pos]
|
282
283
|
@pos = m.pos
|
@@ -310,6 +311,7 @@ class KPeg::FormatParser
|
|
310
311
|
end
|
311
312
|
|
312
313
|
def apply(rule)
|
314
|
+
@result = nil
|
313
315
|
if m = @memoizations[rule][@pos]
|
314
316
|
@pos = m.pos
|
315
317
|
if !m.set
|
data/lib/kpeg/grammar.rb
CHANGED
@@ -106,20 +106,10 @@ module KPeg
|
|
106
106
|
|
107
107
|
if reg.kind_of? String
|
108
108
|
flags = 0
|
109
|
-
lang = nil
|
110
109
|
|
111
110
|
if opts
|
112
111
|
opts.split("").each do |o|
|
113
112
|
case o
|
114
|
-
when "n", "N", "e", "E", "s", "S"
|
115
|
-
lang = o.downcase
|
116
|
-
when "u", "U"
|
117
|
-
if RUBY_VERSION > "1.8.7"
|
118
|
-
# Ruby 1.9 defaults to UTF-8 for string matching
|
119
|
-
lang = ""
|
120
|
-
else
|
121
|
-
lang = "u"
|
122
|
-
end
|
123
113
|
when "m"
|
124
114
|
flags |= Regexp::MULTILINE
|
125
115
|
when "x"
|
@@ -130,7 +120,7 @@ module KPeg
|
|
130
120
|
end
|
131
121
|
end
|
132
122
|
|
133
|
-
@regexp = Regexp.new(reg, flags
|
123
|
+
@regexp = Regexp.new(reg, flags)
|
134
124
|
else
|
135
125
|
@regexp = reg
|
136
126
|
end
|
data/lib/kpeg/string_escape.rb
CHANGED
@@ -285,6 +285,7 @@ class KPeg::StringEscape
|
|
285
285
|
end
|
286
286
|
|
287
287
|
def apply_with_args(rule, *args)
|
288
|
+
@result = nil
|
288
289
|
memo_key = [rule, args]
|
289
290
|
if m = @memoizations[memo_key][@pos]
|
290
291
|
@pos = m.pos
|
@@ -318,6 +319,7 @@ class KPeg::StringEscape
|
|
318
319
|
end
|
319
320
|
|
320
321
|
def apply(rule)
|
322
|
+
@result = nil
|
321
323
|
if m = @memoizations[rule][@pos]
|
322
324
|
@pos = m.pos
|
323
325
|
if !m.set
|
@@ -20,6 +20,15 @@ class TestKPegCompiledParser < Minitest::Test
|
|
20
20
|
|
21
21
|
KPeg.compile gram, "CompTestParser", self
|
22
22
|
|
23
|
+
gram = <<-GRAM
|
24
|
+
letter = < [a-z] > { text }
|
25
|
+
number = [0-9]
|
26
|
+
n_or_l = letter | number
|
27
|
+
root = letter:l n_or_l*:n { [l, n] }
|
28
|
+
GRAM
|
29
|
+
|
30
|
+
KPeg.compile gram, "ProdTestParser", self
|
31
|
+
|
23
32
|
def test_current_column
|
24
33
|
r = TestParser.new "hello\nsir\nand goodbye"
|
25
34
|
assert_equal 1, r.current_column(0)
|
@@ -116,4 +125,52 @@ class TestKPegCompiledParser < Minitest::Test
|
|
116
125
|
assert_equal expected, r.failure_oneline
|
117
126
|
end
|
118
127
|
|
128
|
+
def test_producing_parser_one_product
|
129
|
+
r = ProdTestParser.new "a"
|
130
|
+
assert r.parse, "should parse"
|
131
|
+
|
132
|
+
assert_equal ["a", []], r.result
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_producing_parser_two_products
|
136
|
+
r = ProdTestParser.new "ab"
|
137
|
+
assert r.parse, "should parse"
|
138
|
+
|
139
|
+
assert_equal ["a", ["b"]], r.result
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_producing_parser_three_products
|
143
|
+
r = ProdTestParser.new "abc"
|
144
|
+
assert r.parse, "should parse"
|
145
|
+
|
146
|
+
assert_equal ["a", ["b", "c"]], r.result
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_producing_parser_product_and_nil
|
150
|
+
r = ProdTestParser.new "a1"
|
151
|
+
assert r.parse, "should parse"
|
152
|
+
|
153
|
+
assert_equal ["a", [nil]], r.result
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_producing_parser_product_and_nil2
|
157
|
+
r = ProdTestParser.new "a1b"
|
158
|
+
assert r.parse, "should parse"
|
159
|
+
|
160
|
+
assert_equal ["a", [nil, "b"]], r.result
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_producing_parser_product_and_nil3
|
164
|
+
r = ProdTestParser.new "ab1"
|
165
|
+
assert r.parse, "should parse"
|
166
|
+
|
167
|
+
assert_equal ["a", ["b", nil]], r.result
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_producing_parser_product_and_nil4
|
171
|
+
r = ProdTestParser.new "a12"
|
172
|
+
assert r.parse, "should parse"
|
173
|
+
|
174
|
+
assert_equal ["a", [nil, nil]], r.result
|
175
|
+
end
|
119
176
|
end
|