Skip to content
..
Failed to load latest commit information.
output Parslet accelerators Aug 16, 2013
big.erb Parslet accelerators Aug 16, 2013
boolean_algebra.rb . improves layout to match code guidelines Apr 9, 2011
calc.rb . cleanup Aug 10, 2012
capture.rb Documentation for the scoping Dec 27, 2012
comments.rb + prsnt? -> present?, absnt? -> absent? Mar 2, 2011
deepest_errors.rb + Implementation of a deepest error May 2, 2012
documentation.rb + Cleaning up txus patch Feb 28, 2011
email_parser.rb refactored getting input in email parser example Apr 7, 2013
empty.rb + Cleaning up txus patch Feb 28, 2011
erb.rb + prsnt? -> present?, absnt? -> absent? Mar 2, 2011
ip_address.rb + Cleaning up txus patch Feb 28, 2011
json.rb - cleanup: error tree is completely gone May 25, 2012
local.rb + prsnt? -> present?, absnt? -> absent? Mar 2, 2011
mathn.rb ! Fixes interaction with mathn Dec 15, 2011
minilisp.rb + prsnt? -> present?, absnt? -> absent? Mar 2, 2011
modularity.rb + A few ways of making parlset parsers modular. Mar 25, 2012
nested_errors.rb + Implementation of a deepest error May 2, 2012
optimized_erb.rb Fixes load path in example Jan 20, 2014
parens.rb + Cleaning up txus patch Feb 28, 2011
prec_calc.rb Small bugfixes to infix parser Jun 20, 2013
readme.rb + prsnt? -> present?, absnt? -> absent? Mar 2, 2011
scopes.rb Documentation for the scoping Dec 27, 2012
seasons.rb + Cleaning up txus patch Feb 28, 2011
sentence.rb ! Fixes issue #38: IO is now read using gets(nil, len) Jun 5, 2011
simple.lit ! Fixes the missing recursive flatten Mar 16, 2010
simple_xml.rb + prsnt? -> present?, absnt? -> absent? Mar 2, 2011
string_parser.rb + prsnt? -> present?, absnt? -> absent? Mar 2, 2011
test.lit . Reorg into a real project structure Mar 16, 2010

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.