parslet 1.8.1 → 1.8.2

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
  SHA1:
3
- metadata.gz: 94602845df56ad6245d6fe225d5e2e7e79b0e004
4
- data.tar.gz: 73a1e12177b7bcd0a6997ac82bc8801694094203
3
+ metadata.gz: bf32b3cc2b921b4719c37f9db7e0e1449e55cfc2
4
+ data.tar.gz: 18c1fa21fa37be7feb7c82d835e959e6c892edee
5
5
  SHA512:
6
- metadata.gz: 55d3142ff71dc7466f10a1c13c99ba0dd25cf400cdea2d260370da4e63d50e5911a658b65bf2e1e88f354c46ff212fd4cc7e1bb4ebebfcfd7916681bb28954d4
7
- data.tar.gz: 9eaace33f733d00247396c6697db87d946f6ac51a8f6646ee72e08e9b07fa6bcda3a9c3933188fafb11ffc296ff4ad0805bb683b527ec12bd511a6553914190c
6
+ metadata.gz: c3f7130bc7fead70924701060a12c884bc1eb350336aa1d2808853fa602b86e9163e6051bdb458def9e16062f894cb4cb1575a3b87b6005a3d2978574076233d
7
+ data.tar.gz: 0a69e33741168a4048514856b3c60756d92162f21a21f91c1bc8fed688857682fc5ef34281b575021f0f5417629ee175a8f121def608c1c68422f29a87d8fe31
@@ -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
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2017 Kaspar Schiess
1
+ Copyright (c) 2010-2018 Kaspar Schiess
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person
4
4
  obtaining a copy of this software and associated documentation
@@ -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
- prec = 0
10
- BASE = (prec+=1) # everything else
11
- LOOKAHEAD = (prec+=1) # &SOMETHING
12
- REPETITION = (prec+=1) # 'a'+, 'a'?
13
- SEQUENCE = (prec+=1) # 'a' 'b'
14
- ALTERNATE = (prec+=1) # 'a' | 'b'
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, @error_msg, errors)
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
- @error_msgs = {
19
- :positive => ["Input should start with ", bound_parslet],
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, @error_msgs[:positive], error_pos)
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, @error_msgs[:negative], error_pos)
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
@@ -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
- @error_msgs = {
18
- :premature => "Premature end of input",
19
- :failed => "Failed to match #{match.inspect[1..-2]}"
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, @error_msgs[:premature]) \
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, @error_msgs[:failed])
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, @max = min, max
20
+ @min = min
21
+ @max = max
21
22
  @tag = tag
22
- @error_msgs = {
23
- :minrep => "Expected at least #{min} of #{parslet.inspect}",
24
- :unconsumed => "Extra input after last repetition"
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
- @error_msgs[:minrep],
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
- @error_msgs[:unconsumed],
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
- @error_msgs = {
14
- :failed => "Failed to match sequence (#{self.inspect})"
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, @error_msgs[:failed], [value])
35
+ return context.err(self, source, error_msgs[:failed], [value])
33
36
  end
34
37
 
35
38
  result[idx+1] = value
@@ -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
- @error_msgs = {
16
- :premature => "Premature end of input",
17
- :failed => "Expected #{str.inspect}, but got "
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, @error_msgs[:premature]) \
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
- [@error_msgs[:failed], source.consume(@len)], error_pos)
35
+ [error_msgs[:failed], source.consume(@len)], error_pos)
33
36
  end
34
37
 
35
38
  def to_s_inner(prec)
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'parslet'
5
- s.version = '1.8.1'
5
+ s.version = '1.8.2'
6
6
 
7
7
  s.authors = ['Kaspar Schiess']
8
8
  s.email = 'kaspar.schiess@absurd.li'
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.1
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: 2017-11-19 00:00:00.000000000 Z
11
+ date: 2018-02-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: kaspar.schiess@absurd.li