Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
58 lines (41 sloc) 1.57 KB
Parslet makes developing complex parsers easy. It does so by
* providing the best *error reporting* possible
* *not generating* reams of code for you to debug
Parslet takes the long way around to make *your job* easier. It allows for
incremental language construction. Often, you start out small, implementing
the atoms of your language first; _parslet_ takes pride in making this
Eager to try this out? Please see the associated web site:
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}" }
This library should work with both ruby 1.8 and ruby 1.9.
On the road to 1.0; improving documentation, packaging and upgrading to rspec2.
(c) 2010 Kaspar Schiess
Something went wrong with that request. Please try again.