Permalink
Browse files

+ This addresses first half of #63.

  • Loading branch information...
1 parent ef7dc56 commit 23a771c9d6bbca9a41db6b3d98370781195f35b2 @kschiess kschiess committed Apr 12, 2012
Showing with 26 additions and 1 deletion.
  1. +3 −0 HISTORY.txt
  2. +4 −1 lib/parslet/atoms/base.rb
  3. +19 −0 spec/parslet/atoms/base_spec.rb
View
@@ -5,6 +5,9 @@
= 1.3.1 / ???
+ + Made it possible to pass a custom Parslet::Source implementor to #parse.
+ (see #63)
+
= 1.3.0 / 5Mar2012
! Parslet::Transform::Context is now much more well-behaved. It has
@@ -43,7 +43,10 @@ def parse_vm(io)
end
def parse_traditional(io)
- source = Parslet::Source.new(io)
+ source = io.respond_to?(:line_and_column) ?
+ io :
+ Parslet::Source.new(io)
+
context = Parslet::Atoms::Context.new
result = nil
@@ -56,6 +56,24 @@ def unnamed(obj)
unnamed([[{:a=>"a"}, {:m=>"m"}], {:a=>"a"}]).should == [{:a=>"a"}]
end
end
+ describe '#parse(source)' do
+ context "when given something that looks like a source" do
+ let(:source) { flexmock("source lookalike",
+ :line_and_column => [1,2],
+ :pos => 1,
+ :eof? => true) }
+
+ it "should not rewrap in a source" do
+ flexmock(Parslet::Source).
+ should_receive(:new => :source_created).never
+
+ begin
+ parslet.parse(source)
+ rescue NotImplementedError
+ end
+ end
+ end
+ end
context "when the parse fails, the exception" do
it "should contain a string" do
@@ -85,6 +103,7 @@ def unnamed(obj)
parslet.cause.should == "cause at line 1 char 1."
end
+
it "should reset the #cause to nil" do
success = flexmock(:success, :error? => false)
flexmock(parslet).

0 comments on commit 23a771c

Please sign in to comment.