Permalink
Browse files

Specs for the captures, first commit

  • Loading branch information...
1 parent c80816b commit 1cdb04a747b405a2b5ea60454b2bd0e359288c0b @kschiess committed Dec 27, 2012
Showing with 83 additions and 13 deletions.
  1. +18 −4 Gemfile.lock
  2. +5 −2 HISTORY.txt
  3. +3 −0 example/output/capture.out
  4. +8 −1 lib/parslet/scope.rb
  5. +4 −6 parslet.gemspec
  6. +45 −0 spec/parslet/scope_spec.rb
View
@@ -1,22 +1,34 @@
PATH
remote: .
specs:
- parslet (1.4.1)
+ parslet (1.5)
blankslate (~> 2.0)
GEM
remote: http://rubygems.org/
specs:
blankslate (2.1.2.4)
+ coderay (1.0.8)
diff-lcs (1.1.3)
flexmock (0.9.0)
growl (1.0.3)
- guard (0.8.8)
- thor (~> 0.14.6)
+ guard (1.6.1)
+ listen (>= 0.6.0)
+ lumberjack (>= 1.0.2)
+ pry (>= 0.9.10)
+ thor (>= 0.14.6)
guard-rspec (0.5.9)
guard (>= 0.8.4)
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)
+ rb-fsevent (0.9.2)
rdoc (3.11)
json (~> 1.4)
rspec (2.8.0)
@@ -30,7 +42,8 @@ GEM
sdoc (0.3.16)
json (>= 1.1.3)
rdoc (~> 3.10)
- thor (0.14.6)
+ slop (3.3.3)
+ thor (0.16.0)
PLATFORMS
ruby
@@ -42,6 +55,7 @@ DEPENDENCIES
guard-rspec
parslet!
rake
+ rb-fsevent
rdoc
rspec
sdoc
View
@@ -3,8 +3,8 @@
- prsnt? and absnt? are now finally banned into oblivion. Wasting vocals for
the win.
-= 1.4.1 / ???
-
+= 1.5 / ??
+
+ Handles unconsumed input at end of parse completely differently. Instead
of generating a toplevel error, it now raises an error in every branch
of the parse. More information in the resulting exception ensues! Thanks
@@ -16,6 +16,9 @@
* This history now finally reads like the Changelog of the linux kernel.
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
+ Revised documentation. A few new API features have finally made it into
@@ -0,0 +1,3 @@
+[{:line=>"Text1\n"@9},
+ {:doc=>[{:line=>"Text3\n"@23}, {:line=>"Text4\n"@29}]},
+ {:line=>"\nText2\n"@41}]
@@ -1,4 +1,9 @@
class Parslet::Scope
+ # Raised when the accessed slot has never been assigned a value.
+ #
+ class NotFound < StandardError
+ end
+
class Binding
attr_reader :parent
@@ -8,7 +13,9 @@ def initialize(parent=nil)
end
def [](k)
- @hash.fetch(k)
+ @hash.has_key?(k) && @hash[k] ||
+ parent && parent[k] or
+ raise NotFound
end
def []=(k,v)
@hash.store(k,v)
View
@@ -2,22 +2,20 @@
Gem::Specification.new do |s|
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.date = Date.today
s.email = 'kaspar.schiess@absurd.li'
s.extra_rdoc_files = ['README']
s.files = %w(HISTORY.txt LICENSE Rakefile README) + Dir.glob("{lib,example}/**/*")
s.homepage = 'http://kschiess.github.com/parslet'
s.rdoc_options = ['--main', 'README']
s.require_paths = ['lib']
- s.rubygems_version = '1.8.6'
s.summary = 'Parser construction library with great error reporting in Ruby.'
s.add_dependency 'blankslate', '~> 2.0'
- %w(rspec flexmock rdoc sdoc guard guard-rspec growl).each { |gem_name|
- s.add_development_dependency gem_name }
+ %w(rspec flexmock rdoc sdoc guard guard-rspec rb-fsevent growl).
+ each { |gem_name|
+ s.add_development_dependency gem_name }
end
@@ -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.