Sha256: 8196ccc7e085667ac66587e4da5f06d5cea96351c8cd1e65ab3c482b85f87a38
Contents?: true
Size: 1.24 KB
Versions: 2
Compression:
Stored size: 1.24 KB
Contents
# This wraps pieces of parslet definition and gives them a name. The wrapped # piece is lazily evaluated and cached. This has two purposes: # # a) Avoid infinite recursion during evaluation of the definition # # b) Be able to print things by their name, not by their sometimes # complicated content. # # You don't normally use this directly, instead you should generated it by # using the structuring method Parslet#rule. # class Parslet::Atoms::Entity < Parslet::Atoms::Base attr_reader :name, :context, :block def initialize(name, context, block) super() @name = name @context = context @block = block end def try(io) parslet.apply(io) end def parslet @parslet ||= context.instance_eval(&block).tap { |p| raise_not_implemented unless p } end def to_s_inner(prec) name.to_s.upcase end def error_tree parslet.error_tree end private def raise_not_implemented trace = caller.reject {|l| l =~ %r{#{Regexp.escape(__FILE__)}}} # blatantly stolen from dependencies.rb in activesupport exception = NotImplementedError.new("rule(#{name.inspect}) { ... } returns nil. Still not implemented, but already used?") exception.set_backtrace(trace) raise exception end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
parslet-0.11.0 | lib/parslet/atoms/entity.rb |
parslet-0.10.1 | lib/parslet/atoms/entity.rb |