Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

+ Reduces API surface of Source

Removes eof?
  • Loading branch information...
commit 34364a7e0791d307aea21ab6e4991d40c8fc979a 1 parent 80de8ea
@kschiess authored
View
2  lib/parslet/atoms/base.rb
@@ -51,7 +51,7 @@ def parse(io, options={})
# If we haven't consumed the input, then the pattern doesn't match. Try
# to provide a good error message (even asking down below)
- if !options[:prefix] && !source.eof?
+ if !options[:prefix] && source.chars_left > 0
old_pos = source.pos
Parslet::Cause.format(
source, old_pos,
View
2  lib/parslet/atoms/re.rb
@@ -25,7 +25,7 @@ def try(source, context)
# No string could be read
return context.err(self, source, @error_msgs[:premature]) \
- if source.eof?
+ if source.chars_left < 1
# No match
return context.err(self, source, @error_msgs[:failed])
View
4 lib/parslet/source.rb
@@ -47,10 +47,6 @@ def chars_left
@str.size - @pos
end
- def eof?
- @pos >= @str.size
- end
-
# Position of the parse as a character offset into the original string.
# @note: Encodings...
attr_accessor :pos
View
2  spec/parslet/atoms/base_spec.rb
@@ -55,7 +55,7 @@ def unnamed(obj)
let(:source) { flexmock("source lookalike",
:line_and_column => [1,2],
:pos => 1,
- :eof? => true) }
+ :chars_left => 0) }
it "should not rewrap in a source" do
flexmock(Parslet::Source).
View
13 spec/parslet/source_spec.rb
@@ -15,14 +15,14 @@
source.consume(100).should == 'a'*100
end
end
- describe "<- #eof?" do
- subject { source.eof? }
+ describe "<- #chars_left" do
+ subject { source.chars_left }
- it { should be_false }
+ it { should == 202 }
context "after depleting the source" do
before(:each) { source.consume(10000) }
- it { should be_true }
+ it { should == 0 }
end
end
describe "<- #pos" do
@@ -98,7 +98,7 @@
attr_reader :results
before(:each) {
@results = {}
- while not source.eof?
+ while source.chars_left>0
pos = source.pos
@results[pos] = source.line_and_column
source.consume(1)
@@ -123,7 +123,7 @@
end
it "should give the same results when reading" do
cur = source.pos = 0
- while not source.eof?
+ while source.chars_left>0
source.line_and_column.should == results[cur]
cur += 1
source.consume(1)
@@ -148,7 +148,6 @@
source.consume(1)
source.consume(2)
- source.eof?.should == true
source.chars_left.should == 0
end
end

0 comments on commit 34364a7

Please sign in to comment.
Something went wrong with that request. Please try again.