Permalink
Browse files

Documentation for the scoping

  • Loading branch information...
1 parent a4d72f9 commit 9f6cecbfd60f4efcd75c337d98711d39ac876427 @kschiess committed Dec 27, 2012
View
@@ -8,8 +8,6 @@
require 'parslet/convenience'
require 'pp'
-
-
class CapturingParser < Parslet::Parser
root :document
@@ -30,13 +28,13 @@ class CapturingParser < Parslet::Parser
# The end of the document is marked by the marker that was at the beginning
# of the document, by itself on a line.
rule(:doc_end) { captured_marker }
-
- rule(:newline) { match["\n"] }
rule(:captured_marker) {
dynamic { |source, context|
str(context.captures[:marker])
}
}
+
+ rule(:newline) { match["\n"] }
end
parser = CapturingParser.new
@@ -0,0 +1 @@
+parses 'aba'
View
@@ -0,0 +1,15 @@
+
+$:.unshift File.dirname(__FILE__) + "/../lib"
+require 'parslet'
+
+include Parslet
+
+parser = str('a').capture(:a) >> scope { str('b').capture(:a) } >>
+ dynamic { |s,c| str(c.captures[:a]) }
+
+begin
+ parser.parse('aba')
+ puts "parses 'aba'"
+rescue
+ puts "exception!"
+end
View
@@ -169,6 +169,37 @@ def any
end
module_function :any
+ # Introduces a new capture scope. This means that all old captures stay
+ # accessible, but new values stored will only be available during the block
+ # given and the old values will be restored after the block.
+ #
+ # Example:
+ # # :a will be available until the end of the block. Afterwards,
+ # # :a from the outer scope will be available again, if such a thing
+ # # exists.
+ # scope { str('a').capture(:a) }
+ #
+ def scope(&block)
+ Parslet::Atoms::Scope.new(block)
+ end
+ module_function :scope
+
+ # Designates a piece of the parser as being dynamic. Dynamic parsers can
+ # either return a parser at runtime, which will be applied on the input, or
+ # return a result from a parse.
+ #
+ # Dynamic parse pieces are never cached and can introduce performance
+ # abnormalitites - use sparingly where other constructs fail.
+ #
+ # Example:
+ # # Parses either 'a' or 'b', depending on the weather
+ # dynamic { rand() < 0.5 ? str('a') : str('b') }
+ #
+ def dynamic(&block)
+ Parslet::Atoms::Dynamic.new(block)
+ end
+ module_function :dynamic
+
# A special kind of atom that allows embedding whole treetop expressions
# into parslet construction.
#
View
@@ -106,33 +106,4 @@ def as(name)
def capture(name)
Parslet::Atoms::Capture.new(self, name)
end
-
- # Introduces a new capture scope. This means that all old captures stay
- # accessible, but new values stored will only be available during the block
- # given and the old values will be restored after the block.
- #
- # Example:
- # # :a will be available until the end of the block. Afterwards,
- # # :a from the outer scope will be available again, if such a thing
- # # exists.
- # scope { str('a').capture(:a) }
- #
- def scope(&block)
- Parslet::Atoms::Scope.new(block)
- end
-
- # Designates a piece of the parser as being dynamic. Dynamic parsers can
- # either return a parser at runtime, which will be applied on the input, or
- # return a result from a parse.
- #
- # Dynamic parse pieces are never cached and can introduce performance
- # abnormalitites - use sparingly where other constructs fail.
- #
- # Example:
- # # Parses either 'a' or 'b', depending on the weather
- # dynamic { rand() < 0.5 ? str('a') : str('b') }
- #
- def dynamic(&block)
- Parslet::Atoms::Dynamic.new(block)
- end
end
View
@@ -3,6 +3,7 @@ source "https://rubygems.org"
gem "middleman"
gem 'rb-fsevent'
gem 'RedCloth'
+gem 'slim'
gem 'cod'
gem 'case'
View
@@ -2,117 +2,117 @@ GEM
remote: https://rubygems.org/
specs:
RedCloth (4.2.9)
- activesupport (3.2.2)
+ activesupport (3.2.9)
i18n (~> 0.6)
multi_json (~> 1.0)
- addressable (2.2.7)
blankslate (2.1.2.4)
case (0.5.2.1)
- chunky_png (1.2.5)
- cod (0.4.4)
+ chunky_png (1.2.6)
+ cod (0.5.0)
coffee-script (2.2.0)
coffee-script-source
execjs
- coffee-script-source (1.2.0)
- compass (0.12.1)
+ coffee-script-source (1.3.3)
+ compass (0.12.2)
chunky_png (~> 1.2)
fssm (>= 0.2.7)
sass (~> 3.1)
- daemons (1.1.8)
diff-lcs (1.1.3)
- em-websocket (0.3.6)
- addressable (>= 2.1.1)
- eventmachine (>= 0.12.9)
- eventmachine (0.12.10)
- execjs (1.2.13)
+ execjs (1.4.0)
multi_json (~> 1.0)
- fssm (0.2.8.1)
- guard (0.6.3)
- thor (~> 0.14.6)
- guard-livereload (0.3.1)
- em-websocket (>= 0.2.0)
- guard (>= 0.4.0)
- multi_json (~> 1.0.3)
- haml (3.1.4)
+ ffi (1.2.0)
+ fssm (0.2.9)
+ haml (3.1.7)
hike (1.2.1)
http_router (0.10.2)
rack (>= 1.0.0)
url_mount (~> 0.2.1)
- i18n (0.6.0)
- maruku (0.6.0)
+ i18n (0.6.1)
+ listen (0.5.3)
+ maruku (0.6.1)
syntax (>= 1.0.0)
- middleman (2.0.15.1)
- coffee-script (~> 2.2.0)
- compass (~> 0.11)
- execjs (~> 1.2.7)
- guard (~> 0.6.2)
- haml (~> 3.1.0)
- maruku (~> 0.6.0)
- middleman-livereload (~> 0.2.0)
- padrino-core (~> 0.10.5)
- padrino-helpers (~> 0.10.5)
- rack (~> 1.3.5)
+ middleman (3.0.7)
+ middleman-core (= 3.0.7)
+ middleman-more (= 3.0.7)
+ middleman-sprockets (~> 3.0.2)
+ middleman-core (3.0.7)
+ activesupport (~> 3.2.6)
+ bundler (~> 1.1)
+ listen (~> 0.5.2)
+ rack (~> 1.4.1)
rack-test (~> 0.6.1)
- sass (>= 3.1.7)
- sinatra (~> 1.3.1)
- slim (~> 1.0.2)
- sprockets (~> 2.0.3)
- thin (~> 1.2.11)
- thor (~> 0.14.0)
+ rb-fsevent (~> 0.9.1)
+ rb-inotify (~> 0.8.8)
+ thor (~> 0.15.4)
tilt (~> 1.3.1)
- uglifier (~> 1.0.0)
- middleman-livereload (0.2.1)
- guard-livereload (~> 0.3.1)
- multi_json (1.0.4)
- padrino-core (0.10.6)
+ middleman-more (3.0.7)
+ coffee-script (~> 2.2.0)
+ coffee-script-source (~> 1.3.3)
+ compass (>= 0.12.2)
+ execjs (~> 1.4.0)
+ haml (>= 3.1.6)
+ i18n (~> 0.6.0)
+ maruku (~> 0.6.0)
+ middleman-core (= 3.0.7)
+ padrino-helpers (= 0.10.7)
+ sass (>= 3.1.20)
+ uglifier (~> 1.2.6)
+ middleman-sprockets (3.0.5)
+ middleman-more (>= 3.0.1)
+ sprockets (~> 2.1, < 2.5)
+ sprockets-sass (~> 0.9.0)
+ multi_json (1.5.0)
+ padrino-core (0.10.7)
activesupport (~> 3.2.0)
http_router (~> 0.10.2)
sinatra (~> 1.3.1)
- thor (~> 0.14.3)
+ thor (~> 0.15.2)
tilt (~> 1.3.0)
- padrino-helpers (0.10.6)
+ padrino-helpers (0.10.7)
i18n (~> 0.6)
- padrino-core (= 0.10.6)
+ padrino-core (= 0.10.7)
parslet (1.4.0)
blankslate (~> 2.0)
- rack (1.3.6)
- rack-protection (1.2.0)
+ rack (1.4.1)
+ rack-protection (1.3.2)
rack
- rack-test (0.6.1)
+ rack-test (0.6.2)
rack (>= 1.0)
- rb-fsevent (0.9.1)
- rspec (2.10.0)
- rspec-core (~> 2.10.0)
- rspec-expectations (~> 2.10.0)
- rspec-mocks (~> 2.10.0)
- rspec-core (2.10.1)
- rspec-expectations (2.10.0)
+ rb-fsevent (0.9.2)
+ rb-inotify (0.8.8)
+ ffi (>= 0.5.0)
+ rspec (2.12.0)
+ rspec-core (~> 2.12.0)
+ rspec-expectations (~> 2.12.0)
+ rspec-mocks (~> 2.12.0)
+ rspec-core (2.12.2)
+ rspec-expectations (2.12.1)
diff-lcs (~> 1.1.3)
- rspec-mocks (2.10.1)
- sass (3.1.15)
- sinatra (1.3.2)
+ rspec-mocks (2.12.1)
+ sass (3.2.4)
+ sinatra (1.3.3)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
slim (1.0.4)
temple (~> 0.3.4)
tilt (~> 1.3.2)
- sprockets (2.0.3)
+ sprockets (2.4.5)
hike (~> 1.2)
+ multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
+ sprockets-sass (0.9.1)
+ sprockets (~> 2.0)
+ tilt (~> 1.1)
syntax (1.0.0)
temple (0.3.5)
text-highlight (1.0.2)
- thin (1.2.11)
- daemons (>= 1.0.9)
- eventmachine (>= 0.12.6)
- rack (>= 1.0.0)
- thor (0.14.6)
+ thor (0.15.4)
tilt (1.3.3)
- uglifier (1.0.4)
+ uglifier (1.2.7)
execjs (>= 0.3.0)
- multi_json (>= 1.0.2)
+ multi_json (~> 1.3)
url_mount (0.2.1)
rack
@@ -127,4 +127,5 @@ DEPENDENCIES
parslet
rb-fsevent
rspec
+ slim
text-highlight
View
@@ -1,9 +1,8 @@
+require 'slim'
require 'tilt'
require 'RedCloth'
class NBRedClothTemplate < Tilt::RedClothTemplate
- include Middleman::CoreExtensions::FrontMatter::YamlAware
-
def prepare
super
@engine.hard_breaks = false
Oops, something went wrong.

0 comments on commit 9f6cecb

Please sign in to comment.