parslet 1.1.0 → 1.1.1

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.
data/Gemfile CHANGED
@@ -10,5 +10,6 @@ group :development do
10
10
  gem 'sdoc'
11
11
 
12
12
  gem 'guard'
13
+ gem 'guard-rspec'
13
14
  gem 'growl'
14
15
  end
data/HISTORY.txt CHANGED
@@ -1,3 +1,9 @@
1
+ = 1.1.1 / 4Feb2011
2
+
3
+ ! FIX: Line counting was broken by performance optimisations.
4
+
5
+ + Squeezed out another few drops of performance.
6
+
1
7
  = 1.1.0 / 2Feb2011
2
8
 
3
9
  + Uses return (fail/success), cached line counts, memoizing of parse results
@@ -0,0 +1,37 @@
1
+ # A small example on how to parse common types of comments. The example
2
+ # started out with parser code from Stephen Waits.
3
+
4
+ $:.unshift '../lib'
5
+
6
+ require 'pp'
7
+ require 'parslet'
8
+ require 'parslet/convenience'
9
+
10
+ class ALanguage < Parslet::Parser
11
+ root(:expressions)
12
+
13
+ rule(:expressions) { (line >> eol).repeat(1) | line }
14
+ rule(:line) { space? >> an_expression.as(:exp).repeat }
15
+ rule(:an_expression) { str('a').as(:a) >> space? }
16
+
17
+ rule(:eol) { space? >> match["\n\r"].repeat(1) >> space? }
18
+
19
+ rule(:space?) { space.repeat }
20
+ rule(:space) { multiline_comment.as(:multi) | line_comment.as(:line) | str(' ') }
21
+
22
+ rule(:line_comment) { str('//') >> (match["\n\r"].absnt? >> any).repeat }
23
+ rule(:multiline_comment) { str('/*') >> (str('*/').absnt? >> any).repeat >> str('*/') }
24
+ end
25
+
26
+ code = %q(
27
+ a
28
+ // line comment
29
+ a a a // line comment
30
+ a /* inline comment */ a
31
+ /* multiline
32
+ comment */
33
+ )
34
+
35
+ pp ALanguage.new.parse_with_debug(code)
36
+
37
+
data/example/minilisp.rb CHANGED
@@ -84,7 +84,6 @@ result = parser.parse_with_debug %Q{
84
84
  (display "something")
85
85
  (display 1)
86
86
  (display 3.08))))
87
- (test)
88
87
  }
89
88
 
90
89
  # Transform the result
@@ -33,7 +33,7 @@ class Parslet::Atoms::Base
33
33
  # Stack trace will be off, but the error tree should explain the reason
34
34
  # it failed.
35
35
  if value.error?
36
- raise Parslet::ParseFailed, value.message
36
+ parse_failed(value.message)
37
37
  end
38
38
 
39
39
  # assert: value is a success answer
@@ -85,7 +85,8 @@ class Parslet::Atoms::Base
85
85
  # behaviour.
86
86
  #
87
87
  def try(source, context)
88
- raise NotImplementedError, "Atoms::Base doesn't have behaviour, please implement #try(io)."
88
+ raise NotImplementedError, \
89
+ "Atoms::Base doesn't have behaviour, please implement #try(source, context)."
89
90
  end
90
91
 
91
92
  # Construct a new atom that repeats the current atom min times at least and
@@ -21,7 +21,6 @@ class Parslet::Source
21
21
  # but probably make a scan to that position neccessary.
22
22
  @line_ends = []
23
23
  @line_ends.extend RangeSearch
24
- @eof_reached_once = false
25
24
  end
26
25
 
27
26
  def read(n)
@@ -100,13 +99,22 @@ class Parslet::Source
100
99
  private
101
100
 
102
101
  def scan_for_line_endings(start_pos, buf)
102
+ return unless buf
103
+ return unless buf.index("\n")
104
+ cur = -1
105
+
106
+ # If we have already read part or all of buf, we already know about
107
+ # line ends in that portion. remove it and correct cur (search index)
108
+ if @last_line_end && start_pos < @last_line_end
109
+ # Let's not search the range from start_pos to last_line_end again.
110
+ cur = @last_line_end - start_pos -1
111
+ end
112
+
103
113
  # Scan the string for line endings; store the positions of all endings
104
114
  # in @line_ends.
105
- cur = -1
106
115
  while buf && cur = buf.index("\n", cur+1)
107
- @line_ends << (start_pos + cur+1)
116
+ @last_line_end = (start_pos + cur+1)
117
+ @line_ends << @last_line_end
108
118
  end
109
-
110
- @eof_reached_once = true
111
119
  end
112
120
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 1
8
- - 0
9
- version: 1.1.0
8
+ - 1
9
+ version: 1.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kaspar Schiess
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-02-02 00:00:00 +01:00
17
+ date: 2011-02-04 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -109,6 +109,7 @@ files:
109
109
  - lib/parslet/source.rb
110
110
  - lib/parslet/transform.rb
111
111
  - lib/parslet.rb
112
+ - example/comments.rb
112
113
  - example/documentation.rb
113
114
  - example/email_parser.rb
114
115
  - example/empty.rb