Sha256: c16f4f53ead9160e2a57b64b4d20aa21fedfca26b4253c136212f8d78553cbc1

Contents?: true

Size: 942 Bytes

Versions: 19

Compression:

Stored size: 942 Bytes

Contents

# An exploration of two ideas: 
#   a) Constructing a whole parser inline, without the artificial class around
#      it. 
# and:
#   b) Constructing non-greedy or non-blind parsers by transforming the 
#      grammar.

$:.unshift File.dirname(__FILE__) + "/../lib"

require 'parslet'
include Parslet

a =  str('a').repeat >> str('aa')

# E1% E2
# 
# S = E2 | E1 S 

def this(name, &block); return Parslet::Atoms::Entity.new(name, &block) end
def epsilon; any.absent? end 

# Traditional repetition will try as long as the pattern can be matched and 
# then give up. This is greedy and blind. 
a = str('a').as(:e) >> this('a') { a }.as(:rec) | epsilon

# Here's a pattern match that is greedy and non-blind. The first pattern
# 'a'* will be tried as many times as possible, while still matching the 
# end pattern 'aa'.
b = str('aa').as(:e2) >> epsilon | str('a').as(:e1) >> this('b') { b }.as(:rec)

p a.parse('aaaa')
p b
p b.parse('aaaa')

Version data entries

19 entries across 19 versions & 3 rubygems

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