Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

33 lines (27 sloc) 0.638 kb
# A small example on how to make parslet ignore parts of the parse tree.
$:.unshift File.dirname(__FILE__) + "/../lib"
require 'parslet'
class IgnoreParslet < Parslet::Atoms::Base
def initialize(parslet)
@parslet = parslet
end
def to_s_inner(prec)
@parslet.to_s(prec)
end
def try(source, context)
result = @parslet.try(source, context)
return success(nil) unless result.error?
return result
end
end
module IgnoreDSL
def ignore
IgnoreParslet.new(self)
end
end
class Parslet::Atoms::Base
include IgnoreDSL
end
include Parslet
p (str('a') >> str('b').ignore >> str('c')).
parse('abc')
Jump to Line
Something went wrong with that request. Please try again.