Sha256: 9b5c18ff9c81bc48171d1024717476bf6e9c9fb01924c3b0489156d29c9fbf9c

Contents?: true

Size: 919 Bytes

Versions: 19

Compression:

Stored size: 919 Bytes

Contents

# 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)

Version data entries

19 entries across 19 versions & 3 rubygems

Version Path
parslet-2.0.0 example/readme.rb
parslet-1.8.2 example/readme.rb
parslet-1.8.1 example/readme.rb
parslet-1.8.0 example/readme.rb
swift-pyrite-0.1.1 vendor/bundle/ruby/2.0.0/gems/parslet-1.7.1/example/readme.rb
swift-pyrite-0.1.0 vendor/bundle/ruby/2.0.0/gems/parslet-1.7.1/example/readme.rb
parslet-1.7.1 example/readme.rb
parslet-1.7.0 example/readme.rb
parslet-1.6.2 example/readme.rb
parslet-1.6.1 example/readme.rb
parslet-1.6.0 example/readme.rb
parslet-1.5.0 example/readme.rb
ghazel-parslet-1.4.0.2 example/readme.rb
ghazel-parslet-1.4.0.1 example/readme.rb
parslet-1.4.0 example/readme.rb
parslet-1.3.0 example/readme.rb
parslet-1.2.3 example/readme.rb
parslet-1.2.1 example/readme.rb
parslet-1.2.0 example/readme.rb