parslet 1.8.1 → 1.8.2
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/HISTORY.txt +5 -0
- data/LICENSE +1 -1
- data/lib/parslet/atoms.rb +8 -10
- data/lib/parslet/atoms/alternative.rb +6 -3
- data/lib/parslet/atoms/lookahead.rb +10 -8
- data/lib/parslet/atoms/re.rb +8 -5
- data/lib/parslet/atoms/repetition.rb +10 -6
- data/lib/parslet/atoms/sequence.rb +6 -3
- data/lib/parslet/atoms/str.rb +8 -5
- data/parslet.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf32b3cc2b921b4719c37f9db7e0e1449e55cfc2
|
4
|
+
data.tar.gz: 18c1fa21fa37be7feb7c82d835e959e6c892edee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3f7130bc7fead70924701060a12c884bc1eb350336aa1d2808853fa602b86e9163e6051bdb458def9e16062f894cb4cb1575a3b87b6005a3d2978574076233d
|
7
|
+
data.tar.gz: 0a69e33741168a4048514856b3c60756d92162f21a21f91c1bc8fed688857682fc5ef34281b575021f0f5417629ee175a8f121def608c1c68422f29a87d8fe31
|
data/HISTORY.txt
CHANGED
@@ -4,6 +4,11 @@
|
|
4
4
|
- prsnt? and absnt? are now finally banned into oblivion. Wasting vocals for
|
5
5
|
the win.
|
6
6
|
|
7
|
+
= 1.8.2 / 13Feb2018
|
8
|
+
|
9
|
+
! Improvements to performance in cases where atoms are dynamically generated
|
10
|
+
(Kevin Olbrich).
|
11
|
+
|
7
12
|
= 1.8.1 / 19Nov2017
|
8
13
|
|
9
14
|
- Minor fixes for language compatibility.
|
data/LICENSE
CHANGED
data/lib/parslet/atoms.rb
CHANGED
@@ -3,18 +3,17 @@
|
|
3
3
|
#
|
4
4
|
module Parslet::Atoms
|
5
5
|
# The precedence module controls parenthesis during the #inspect printing
|
6
|
-
# of parslets. It is not relevant to other aspects of the parsing.
|
6
|
+
# of parslets. It is not relevant to other aspects of the parsing.
|
7
7
|
#
|
8
8
|
module Precedence
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
OUTER = (prec+=1) # printing is done here.
|
9
|
+
BASE = 1 # everything else
|
10
|
+
LOOKAHEAD = 2 # &SOMETHING
|
11
|
+
REPETITION = 3 # 'a'+, 'a'?
|
12
|
+
SEQUENCE = 4 # 'a' 'b'
|
13
|
+
ALTERNATE = 5 # 'a' | 'b'
|
14
|
+
OUTER = 6 # printing is done here.
|
16
15
|
end
|
17
|
-
|
16
|
+
|
18
17
|
require 'parslet/atoms/can_flatten'
|
19
18
|
require 'parslet/atoms/context'
|
20
19
|
require 'parslet/atoms/dsl'
|
@@ -33,4 +32,3 @@ module Parslet::Atoms
|
|
33
32
|
require 'parslet/atoms/scope'
|
34
33
|
require 'parslet/atoms/infix'
|
35
34
|
end
|
36
|
-
|
@@ -19,7 +19,6 @@ class Parslet::Atoms::Alternative < Parslet::Atoms::Base
|
|
19
19
|
super()
|
20
20
|
|
21
21
|
@alternatives = alternatives
|
22
|
-
@error_msg = "Expected one of #{alternatives.inspect}"
|
23
22
|
end
|
24
23
|
|
25
24
|
#---
|
@@ -29,7 +28,11 @@ class Parslet::Atoms::Alternative < Parslet::Atoms::Base
|
|
29
28
|
def |(parslet)
|
30
29
|
self.class.new(*@alternatives + [parslet])
|
31
30
|
end
|
32
|
-
|
31
|
+
|
32
|
+
def error_msg
|
33
|
+
@error_msg ||= "Expected one of #{alternatives.inspect}"
|
34
|
+
end
|
35
|
+
|
33
36
|
def try(source, context, consume_all)
|
34
37
|
errors = alternatives.map { |a|
|
35
38
|
success, value = result = a.apply(source, context, consume_all)
|
@@ -40,7 +43,7 @@ class Parslet::Atoms::Alternative < Parslet::Atoms::Base
|
|
40
43
|
}
|
41
44
|
|
42
45
|
# If we reach this point, all alternatives have failed.
|
43
|
-
context.err(self, source,
|
46
|
+
context.err(self, source, error_msg, errors)
|
44
47
|
end
|
45
48
|
|
46
49
|
precedence ALTERNATE
|
@@ -14,9 +14,11 @@ class Parslet::Atoms::Lookahead < Parslet::Atoms::Base
|
|
14
14
|
# Model positive and negative lookahead by testing this flag.
|
15
15
|
@positive = positive
|
16
16
|
@bound_parslet = bound_parslet
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
end
|
18
|
+
|
19
|
+
def error_msgs
|
20
|
+
@error_msgs ||= {
|
21
|
+
:positive => ["Input should start with ", bound_parslet],
|
20
22
|
:negative => ["Input should not start with ", bound_parslet]
|
21
23
|
}
|
22
24
|
end
|
@@ -29,10 +31,10 @@ class Parslet::Atoms::Lookahead < Parslet::Atoms::Base
|
|
29
31
|
|
30
32
|
if positive
|
31
33
|
return succ(nil) if success
|
32
|
-
return context.err_at(self, source,
|
34
|
+
return context.err_at(self, source, error_msgs[:positive], error_pos)
|
33
35
|
else
|
34
36
|
return succ(nil) unless success
|
35
|
-
return context.err_at(self, source,
|
37
|
+
return context.err_at(self, source, error_msgs[:negative], error_pos)
|
36
38
|
end
|
37
39
|
|
38
40
|
# This is probably the only parslet that rewinds its input in #try.
|
@@ -43,8 +45,8 @@ class Parslet::Atoms::Lookahead < Parslet::Atoms::Base
|
|
43
45
|
|
44
46
|
precedence LOOKAHEAD
|
45
47
|
def to_s_inner(prec)
|
46
|
-
char = positive ? '&' : '!'
|
47
|
-
|
48
|
-
"#{char}#{bound_parslet.to_s(prec)}"
|
48
|
+
@char = positive ? '&' : '!'
|
49
|
+
|
50
|
+
"#{@char}#{bound_parslet.to_s(prec)}"
|
49
51
|
end
|
50
52
|
end
|
data/lib/parslet/atoms/re.rb
CHANGED
@@ -14,9 +14,12 @@ class Parslet::Atoms::Re < Parslet::Atoms::Base
|
|
14
14
|
|
15
15
|
@match = match.to_s
|
16
16
|
@re = Regexp.new(self.match, Regexp::MULTILINE)
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
end
|
18
|
+
|
19
|
+
def error_msgs
|
20
|
+
@error_msgs ||= {
|
21
|
+
premature: 'Premature end of input',
|
22
|
+
failed: "Failed to match #{match.inspect[1..-2]}"
|
20
23
|
}
|
21
24
|
end
|
22
25
|
|
@@ -24,11 +27,11 @@ class Parslet::Atoms::Re < Parslet::Atoms::Base
|
|
24
27
|
return succ(source.consume(1)) if source.matches?(@re)
|
25
28
|
|
26
29
|
# No string could be read
|
27
|
-
return context.err(self, source,
|
30
|
+
return context.err(self, source, error_msgs[:premature]) \
|
28
31
|
if source.chars_left < 1
|
29
32
|
|
30
33
|
# No match
|
31
|
-
return context.err(self, source,
|
34
|
+
return context.err(self, source, error_msgs[:failed])
|
32
35
|
end
|
33
36
|
|
34
37
|
def to_s_inner(prec)
|
@@ -17,11 +17,15 @@ class Parslet::Atoms::Repetition < Parslet::Atoms::Base
|
|
17
17
|
|
18
18
|
|
19
19
|
@parslet = parslet
|
20
|
-
@min
|
20
|
+
@min = min
|
21
|
+
@max = max
|
21
22
|
@tag = tag
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
end
|
24
|
+
|
25
|
+
def error_msgs
|
26
|
+
@error_msgs ||= {
|
27
|
+
minrep: "Expected at least #{min} of #{parslet.inspect}",
|
28
|
+
unconsumed: 'Extra input after last repetition'
|
25
29
|
}
|
26
30
|
end
|
27
31
|
|
@@ -51,7 +55,7 @@ class Parslet::Atoms::Repetition < Parslet::Atoms::Base
|
|
51
55
|
return context.err_at(
|
52
56
|
self,
|
53
57
|
source,
|
54
|
-
|
58
|
+
error_msgs[:minrep],
|
55
59
|
start_pos,
|
56
60
|
[break_on]) if occ < min
|
57
61
|
|
@@ -66,7 +70,7 @@ class Parslet::Atoms::Repetition < Parslet::Atoms::Base
|
|
66
70
|
return context.err(
|
67
71
|
self,
|
68
72
|
source,
|
69
|
-
|
73
|
+
error_msgs[:unconsumed],
|
70
74
|
[break_on]) if consume_all && source.chars_left>0
|
71
75
|
|
72
76
|
return succ(accum)
|
@@ -10,8 +10,11 @@ class Parslet::Atoms::Sequence < Parslet::Atoms::Base
|
|
10
10
|
super()
|
11
11
|
|
12
12
|
@parslets = parslets
|
13
|
-
|
14
|
-
|
13
|
+
end
|
14
|
+
|
15
|
+
def error_msgs
|
16
|
+
@error_msgs ||= {
|
17
|
+
failed: "Failed to match sequence (#{inspect})"
|
15
18
|
}
|
16
19
|
end
|
17
20
|
|
@@ -29,7 +32,7 @@ class Parslet::Atoms::Sequence < Parslet::Atoms::Base
|
|
29
32
|
success, value = p.apply(source, context, child_consume_all)
|
30
33
|
|
31
34
|
unless success
|
32
|
-
return context.err(self, source,
|
35
|
+
return context.err(self, source, error_msgs[:failed], [value])
|
33
36
|
end
|
34
37
|
|
35
38
|
result[idx+1] = value
|
data/lib/parslet/atoms/str.rb
CHANGED
@@ -12,9 +12,12 @@ class Parslet::Atoms::Str < Parslet::Atoms::Base
|
|
12
12
|
@str = str.to_s
|
13
13
|
@pat = Regexp.new(Regexp.escape(str))
|
14
14
|
@len = str.size
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
end
|
16
|
+
|
17
|
+
def error_msgs
|
18
|
+
@error_msgs ||= {
|
19
|
+
premature: 'Premature end of input',
|
20
|
+
failed: "Expected #{str.inspect}, but got "
|
18
21
|
}
|
19
22
|
end
|
20
23
|
|
@@ -22,14 +25,14 @@ class Parslet::Atoms::Str < Parslet::Atoms::Base
|
|
22
25
|
return succ(source.consume(@len)) if source.matches?(@pat)
|
23
26
|
|
24
27
|
# Input ending early:
|
25
|
-
return context.err(self, source,
|
28
|
+
return context.err(self, source, error_msgs[:premature]) \
|
26
29
|
if source.chars_left<@len
|
27
30
|
|
28
31
|
# Expected something, but got something else instead:
|
29
32
|
error_pos = source.pos
|
30
33
|
return context.err_at(
|
31
34
|
self, source,
|
32
|
-
[
|
35
|
+
[error_msgs[:failed], source.consume(@len)], error_pos)
|
33
36
|
end
|
34
37
|
|
35
38
|
def to_s_inner(prec)
|
data/parslet.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parslet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kaspar Schiess
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: kaspar.schiess@absurd.li
|