kpeg 1.2.0 → 1.3.0

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: 8addf56b471f186a44651884101f4159a94927b8c27d5c5eaed867388797fb49
4
- data.tar.gz: cb1c89881fc980f4fd1bedd485a6f4cc0ac2e8aa9df8ffeb9690b9839be6b8be
3
+ metadata.gz: 80dd9b2ed08c2a2ccc37ad658fe0f14864dc5ad8ef4e36d108a243a68a4baa5f
4
+ data.tar.gz: 5dec03b1e86a4ff5d0d10ed7818d561b12c6c71022eed7de16786d0a90160de9
5
5
  SHA512:
6
- metadata.gz: 7207c6d8774c8eec993b962306df6fd529ae7910b279e98dda4f4d2000c4c2dd5183ca5d1ee28ba377fa4664d4b5c417c283fd539cf1b8c80db3ff9f6d66be1b
7
- data.tar.gz: c6980f3355fb4a64cb49ae29ab050e09039074aea8720fab12000e6ce7716749276f4d4cf3a5831982e263de7b3c25c22f5850d4edc4fb06e5468be75943e41c
6
+ metadata.gz: bb96b6bcd8c7f92a6c11355d4022c95a285cf75872b5608fbb6fdc47233c342b42d3a91da524f6fb1678ae78d54109300e1607d7940ae5462c9282757d1bdc25
7
+ data.tar.gz: 9f7e844e84c119ce755e95a4034fcd67c251f90e2f4623a34bdba6f94e568f34adbb92011f96b1efe55b02be4a3191be6414c12aed93e083d705d82d27b95c4f
data/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ === 1.3.0 / 2021-10-20
2
+
3
+ * Fix current_line calculation
4
+
5
+ === 1.2.0 / 2021-10-20
6
+
7
+ * Speed up current_line
1
8
  === 1.2.0 / 2021-10-20
2
9
 
3
10
  * Speed up current_line
@@ -30,16 +30,15 @@ class KPeg::FormatParser
30
30
  if [].respond_to? :bsearch_index
31
31
  def current_line(target=pos)
32
32
  unless @line_offsets
33
- @line_offsets = [-1]
33
+ @line_offsets = []
34
34
  total = 0
35
35
  string.each_line do |line|
36
- @line_offsets << total
37
36
  total += line.size
37
+ @line_offsets << total
38
38
  end
39
- @line_offsets << total
40
39
  end
41
40
 
42
- @line_offsets.bsearch_index {|x| x >= target } || -1
41
+ @line_offsets.bsearch_index {|x| x >= target } + 1 || -1
43
42
  end
44
43
  else
45
44
  def current_line(target=pos)
data/lib/kpeg/position.rb CHANGED
@@ -13,16 +13,15 @@ module KPeg
13
13
  if [].respond_to? :bsearch_index
14
14
  def current_line(target=pos)
15
15
  unless @line_offsets
16
- @line_offsets = [-1]
16
+ @line_offsets = []
17
17
  total = 0
18
18
  string.each_line do |line|
19
- @line_offsets << total
20
19
  total += line.size
20
+ @line_offsets << total
21
21
  end
22
- @line_offsets << total
23
22
  end
24
23
 
25
- @line_offsets.bsearch_index {|x| x >= target } || -1
24
+ @line_offsets.bsearch_index {|x| x >= target } + 1 || -1
26
25
  end
27
26
  else
28
27
  def current_line(target=pos)
@@ -38,16 +38,15 @@ class KPeg::StringEscape
38
38
  if [].respond_to? :bsearch_index
39
39
  def current_line(target=pos)
40
40
  unless @line_offsets
41
- @line_offsets = [-1]
41
+ @line_offsets = []
42
42
  total = 0
43
43
  string.each_line do |line|
44
- @line_offsets << total
45
44
  total += line.size
45
+ @line_offsets << total
46
46
  end
47
- @line_offsets << total
48
47
  end
49
48
 
50
- @line_offsets.bsearch_index {|x| x >= target } || -1
49
+ @line_offsets.bsearch_index {|x| x >= target } + 1 || -1
51
50
  end
52
51
  else
53
52
  def current_line(target=pos)
data/lib/kpeg.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module KPeg
2
2
 
3
- VERSION = "1.2.0"
3
+ VERSION = "1.3.0"
4
4
 
5
5
  def self.grammar
6
6
  g = Grammar.new
@@ -7,6 +7,7 @@ class TestKPegCompiledParser < Minitest::Test
7
7
 
8
8
  gram = <<-GRAM
9
9
  letter = [a-z]
10
+ number = [0-9]
10
11
  root = letter
11
12
  GRAM
12
13
 
@@ -14,7 +15,7 @@ class TestKPegCompiledParser < Minitest::Test
14
15
 
15
16
  gram = <<-GRAM
16
17
  %test = TestKPegCompiledParser::TestParser
17
- root = %test.letter "!"
18
+ root = %test.letter %test.number? "!"
18
19
  GRAM
19
20
 
20
21
  KPeg.compile gram, "CompTestParser", self
@@ -78,4 +79,12 @@ class TestKPegCompiledParser < Minitest::Test
78
79
  assert_equal expected, r.failure_oneline
79
80
  end
80
81
 
82
+ def test_composite_two_char_error
83
+ r = CompTestParser.new "aa"
84
+ assert_nil r.parse, "should not parse"
85
+
86
+ expected = "@1:2 failed rule 'TestKPegCompiledParser::TestParser#_number', got 'a'"
87
+ assert_equal expected, r.failure_oneline
88
+ end
89
+
81
90
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kpeg
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Phoenix
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-20 00:00:00.000000000 Z
11
+ date: 2021-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest