Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 33 lines (27 sloc) 0.638 kB
b87a572 @kschiess + How to extend parslets capabilities
authored
1 # A small example on how to make parslet ignore parts of the parse tree.
2
3 $:.unshift File.dirname(__FILE__) + "/../lib"
4 require 'parslet'
5
6 class IgnoreParslet < Parslet::Atoms::Base
7 def initialize(parslet)
8 @parslet = parslet
9 end
10 def to_s_inner(prec)
11 @parslet.to_s(prec)
12 end
13 def try(source, context)
14 result = @parslet.try(source, context)
15
16 return success(nil) unless result.error?
17 return result
18 end
19
20 end
21 module IgnoreDSL
22 def ignore
23 IgnoreParslet.new(self)
24 end
25 end
26
27 class Parslet::Atoms::Base
28 include IgnoreDSL
29 end
30
31 include Parslet
32 p (str('a') >> str('b').ignore >> str('c')).
33 parse('abc')
Something went wrong with that request. Please try again.