Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

+ Now this can use Entity as well

  • Loading branch information...
commit a98356a509b7337353d275d561bb798d2b3d6d28 1 parent b3259a4
@kschiess authored
Showing with 3 additions and 21 deletions.
  1. +3 −21 example/local.rb
View
24 example/local.rb
@@ -9,35 +9,17 @@
#
# S = E2 | E1 S
-class Local < Parslet::Atoms::Base
- def initialize(&block)
- @block = block
- end
-
- def try(source, context) # :nodoc:
- parslet.apply(source, context)
- end
-
- def parslet
- @parslet ||= @block[]
- end
-
- def to_s_inner(prec) # :nodoc:
- '{ ... }'
- end
-end
-
-def this(&block); return Local.new(&block) end
+def this(name, &block); return Parslet::Atoms::Entity.new(name, &block) end
def epsilon; any.absnt? 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 }.as(:rec) | epsilon
+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 }.as(:rec)
+b = str('aa').as(:e2) >> epsilon | str('a').as(:e1) >> this('b') { b }.as(:rec)
p a.parse('aaaa')
p b
Please sign in to comment.
Something went wrong with that request. Please try again.