Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

This branch is 278 commits behind kschiess:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

..
Failed to load latest commit information.
output
boolean_algebra.rb
comments.rb
documentation.rb
email_parser.rb
empty.rb
erb.rb
ignore.rb
ip_address.rb
json.rb
local.rb
minilisp.rb
parens.rb
readme.rb
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.