Skip to content
Latest commit 07a2834 Jan 20, 2014 @kschiess Fixes load path in example
..
Failed to load latest commit information.
output
big.erb
boolean_algebra.rb
calc.rb . cleanup Aug 10, 2012
capture.rb
comments.rb
deepest_errors.rb
documentation.rb + Cleaning up txus patch Feb 28, 2011
email_parser.rb refactored getting input in email parser example Apr 7, 2013
empty.rb
erb.rb
ignore.rb . refactor: postfix -> consume_all Sep 17, 2012
ip_address.rb
json.rb
local.rb
mathn.rb
minilisp.rb + prsnt? -> present?, absnt? -> absent? Mar 2, 2011
modularity.rb
nested_errors.rb
optimized_erb.rb
parens.rb
prec_calc.rb
readme.rb
scopes.rb Documentation for the scoping Dec 27, 2012
seasons.rb
sentence.rb
simple.lit
simple_xml.rb
string_parser.rb
test.lit

readme.rb

# The example from the readme. With this, I am making sure that the readme 
# 'works'. Is this too messy?

$:.unshift File.dirname(__FILE__) + "/../lib"

# cut here -------------------------------------------------------------------
require 'parslet'
include Parslet

# Constructs a parser using a Parser Expression Grammar like DSL: 
parser =  str('"') >> 
          (
            str('\\') >> any |
            str('"').absent? >> any
          ).repeat.as(:string) >> 
          str('"')
  
# Parse the string and capture parts of the interpretation (:string above)        
tree = parser.parse('"This is a \\"String\\" in which you can escape stuff"')

tree # => {:string=>"This is a \\\"String\\\" in which you can escape stuff"}

# Here's how you can grab results from that tree:

transform = Parslet::Transform.new do
  rule(:string => simple(:x)) { 
    puts "String contents: #{x}" }
end
transform.apply(tree)

Something went wrong with that request. Please try again.