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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: abed16806bd433f58dd9911eb8c68f2d50e4a56af15b4e2a7f4eba333727a969
4
- data.tar.gz: 28e547321489a71fa5fc8058d9b236123d1e4da143fe6e7d4f437a8f8bd2c27f
3
+ metadata.gz: d833890a30055ccb0575be00d3ef66bfcb447d3b18f518d2ed3dfb2aa273eec7
4
+ data.tar.gz: 3e056a615b305db820064549a9a94292aadc19a9af20293f9939ae4305897536
5
5
  SHA512:
6
- metadata.gz: 96523e0c2694a0f5e5af682e22ecbebf268d40add7dd97e25db90725c686982d220fb77c22962bf21025cbddfe570763c01b3720304a8b57d99508e9eab0d00a
7
- data.tar.gz: 94716fa06ffb6e5a9322753ae60de879ad4aab8bdeb854590e9b5a201cb73b35aeec7378a5907b38e8571433586f28c323251a66c274368ce687f4994614b041
6
+ metadata.gz: 3becd99c88978dd486ecb9db5074ed453f8b953bd29d5a22fb8e112e66b5deb5d2d199b791077e16a10734b6d1de61f3d381ec5461c8e531399df2e2eda75150
7
+ data.tar.gz: 44a83605de6a673d5cc1ac98017680581d374595a6eb028c08ed09098f433e7d297775b9474dcef8737c1483e0a19b6dac34574423c0a600fc0308cf70e2dab4
data/History.txt CHANGED
@@ -1,3 +1,12 @@
1
+ === 1.3.3 / 2023-03-06
2
+
3
+ * Remove 3rd argument to Regexp.new
4
+
5
+ === 1.3.2 / 2022-11-02
6
+
7
+ * Fix column calculation
8
+ * General improvement in line/column calculation
9
+
1
10
  === 1.3.1 / 2022-01-10
2
11
 
3
12
  * File.exists? => File.exist?
data/Rakefile CHANGED
@@ -1,6 +1,12 @@
1
1
  # -*- ruby -*-
2
2
 
3
3
  require 'rubygems'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ end
4
10
 
5
11
  task :test => :parser
6
12
 
@@ -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 - "-" - termLt2 { t1 - t2 }
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.2"
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=
@@ -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
@@ -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, lang)
123
+ @regexp = Regexp.new(reg, flags)
134
124
  else
135
125
  @regexp = reg
136
126
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kpeg
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Phoenix