Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

42 lines (31 sloc) 1.036 kb
# The example from the readme. With this, I am making sure that the readme
# 'works'. Is this too messy?
$:.unshift '../lib'
require 'pp'
require 'parslet'
include Parslet
require 'parslet'
include Parslet
# Constructs a parser using a Parser Expression Grammar like DSL:
parser = str('"') >>
str('\\') >> any |
str('"').absnt? >> any
) >>
# Parse the string and capture parts of the interpretation (:string above)
tree = parser.parse(%Q{
"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, two methods:
# 1) => simple(:x)).each_match(tree) do |dictionary|
puts "String contents (method 1): #{dictionary[:x]}"
# 2)
transform = do
rule(:string => simple(:x)) {
puts "String contents (method 2): #{x}" }
Jump to Line
Something went wrong with that request. Please try again.