Sha256: da61b64be2a6d542fc4fb503ffa61d712e6aebb52ca135123e56b693345fee90
Contents?: true
Size: 878 Bytes
Versions: 3
Compression:
Stored size: 878 Bytes
Contents
# 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 ).repeat.as(:string) >> str('"') # 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" }.strip) tree # => {:string=>"This is a \\\"String\\\" in which you can escape stuff"} # Here's how you can grab results from that tree: # 1) transform = Parslet::Transform.new do rule(:string => simple(:x)) { puts "String contents: #{x}" } end transform.apply(tree)
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
parslet-1.1.1 | example/readme.rb |
parslet-1.1.0 | example/readme.rb |
parslet-1.0.1 | example/readme.rb |