Skip to content

Commit

Permalink
Specs for the captures, first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kschiess committed Dec 27, 2012
1 parent c80816b commit 1cdb04a
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 13 deletions.
22 changes: 18 additions & 4 deletions Gemfile.lock
Original file line number Original file line Diff line number Diff line change
@@ -1,22 +1,34 @@
PATH PATH
remote: . remote: .
specs: specs:
parslet (1.4.1) parslet (1.5)
blankslate (~> 2.0) blankslate (~> 2.0)


GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
blankslate (2.1.2.4) blankslate (2.1.2.4)
coderay (1.0.8)
diff-lcs (1.1.3) diff-lcs (1.1.3)
flexmock (0.9.0) flexmock (0.9.0)
growl (1.0.3) growl (1.0.3)
guard (0.8.8) guard (1.6.1)
thor (~> 0.14.6) listen (>= 0.6.0)
lumberjack (>= 1.0.2)
pry (>= 0.9.10)
thor (>= 0.14.6)
guard-rspec (0.5.9) guard-rspec (0.5.9)
guard (>= 0.8.4) guard (>= 0.8.4)
json (1.6.3) json (1.6.3)
listen (0.6.0)
lumberjack (1.0.2)
method_source (0.8.1)
pry (0.9.10)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.3.1)
rake (0.9.2.2) rake (0.9.2.2)
rb-fsevent (0.9.2)
rdoc (3.11) rdoc (3.11)
json (~> 1.4) json (~> 1.4)
rspec (2.8.0) rspec (2.8.0)
Expand All @@ -30,7 +42,8 @@ GEM
sdoc (0.3.16) sdoc (0.3.16)
json (>= 1.1.3) json (>= 1.1.3)
rdoc (~> 3.10) rdoc (~> 3.10)
thor (0.14.6) slop (3.3.3)
thor (0.16.0)


PLATFORMS PLATFORMS
ruby ruby
Expand All @@ -42,6 +55,7 @@ DEPENDENCIES
guard-rspec guard-rspec
parslet! parslet!
rake rake
rb-fsevent
rdoc rdoc
rspec rspec
sdoc sdoc
7 changes: 5 additions & 2 deletions HISTORY.txt
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
- prsnt? and absnt? are now finally banned into oblivion. Wasting vocals for - prsnt? and absnt? are now finally banned into oblivion. Wasting vocals for
the win. the win.


= 1.4.1 / ??? = 1.5 / ??

+ Handles unconsumed input at end of parse completely differently. Instead + Handles unconsumed input at end of parse completely differently. Instead
of generating a toplevel error, it now raises an error in every branch of generating a toplevel error, it now raises an error in every branch
of the parse. More information in the resulting exception ensues! Thanks of the parse. More information in the resulting exception ensues! Thanks
Expand All @@ -16,6 +16,9 @@
* This history now finally reads like the Changelog of the linux kernel. * This history now finally reads like the Changelog of the linux kernel.
Meaning that probably no one ever reads this. Meaning that probably no one ever reads this.


+ Captures and parsing subsequent input based on captured values. This has
been long overdue - finally you can parse HEREdocs with parslet!

= 1.4.0 / 25May2012 = 1.4.0 / 25May2012


+ Revised documentation. A few new API features have finally made it into + Revised documentation. A few new API features have finally made it into
Expand Down
3 changes: 3 additions & 0 deletions example/output/capture.out
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,3 @@
[{:line=>"Text1\n"@9},
{:doc=>[{:line=>"Text3\n"@23}, {:line=>"Text4\n"@29}]},
{:line=>"\nText2\n"@41}]
9 changes: 8 additions & 1 deletion lib/parslet/scope.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,9 @@
class Parslet::Scope class Parslet::Scope
# Raised when the accessed slot has never been assigned a value.
#
class NotFound < StandardError
end

class Binding class Binding
attr_reader :parent attr_reader :parent


Expand All @@ -8,7 +13,9 @@ def initialize(parent=nil)
end end


def [](k) def [](k)
@hash.fetch(k) @hash.has_key?(k) && @hash[k] ||
parent && parent[k] or
raise NotFound
end end
def []=(k,v) def []=(k,v)
@hash.store(k,v) @hash.store(k,v)
Expand Down
10 changes: 4 additions & 6 deletions parslet.gemspec
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@


Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = 'parslet' s.name = 'parslet'
s.version = '1.4.1' s.version = '1.5.0'


s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
s.authors = ['Kaspar Schiess'] s.authors = ['Kaspar Schiess']
s.date = Date.today
s.email = 'kaspar.schiess@absurd.li' s.email = 'kaspar.schiess@absurd.li'
s.extra_rdoc_files = ['README'] s.extra_rdoc_files = ['README']
s.files = %w(HISTORY.txt LICENSE Rakefile README) + Dir.glob("{lib,example}/**/*") s.files = %w(HISTORY.txt LICENSE Rakefile README) + Dir.glob("{lib,example}/**/*")
s.homepage = 'http://kschiess.github.com/parslet' s.homepage = 'http://kschiess.github.com/parslet'
s.rdoc_options = ['--main', 'README'] s.rdoc_options = ['--main', 'README']
s.require_paths = ['lib'] s.require_paths = ['lib']
s.rubygems_version = '1.8.6'
s.summary = 'Parser construction library with great error reporting in Ruby.' s.summary = 'Parser construction library with great error reporting in Ruby.'


s.add_dependency 'blankslate', '~> 2.0' s.add_dependency 'blankslate', '~> 2.0'


%w(rspec flexmock rdoc sdoc guard guard-rspec growl).each { |gem_name| %w(rspec flexmock rdoc sdoc guard guard-rspec rb-fsevent growl).
s.add_development_dependency gem_name } each { |gem_name|
s.add_development_dependency gem_name }
end end
45 changes: 45 additions & 0 deletions spec/parslet/scope_spec.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'spec_helper'

describe Parslet::Scope do
let(:scope) { described_class.new }

describe 'simple store/retrieve' do
before(:each) { scope[:foo] = :bar }
it "allows storing objects" do
scope[:obj] = 42
end
it "raises on access of empty slots" do
expect {
scope[:empty]
}.to raise_error(Parslet::Scope::NotFound)
end
it "allows retrieval of stored values" do
scope[:foo].should == :bar
end
end

describe 'scoping' do
before(:each) { scope[:depth] = 1 }
before(:each) { scope.push }

let(:depth) { scope[:depth] }
subject { depth }

it { should == 1 }
describe 'after a push' do
before(:each) { scope.push }
it { should == 1 }

describe 'and reassign' do
before(:each) { scope[:depth] = 2 }

it { should == 2 }

describe 'and a pop' do
before(:each) { scope.pop }
it { should == 1 }
end
end
end
end
end

0 comments on commit 1cdb04a

Please sign in to comment.