This wraps pieces of parslet definition and gives them a name. The wrapped piece is lazily evaluated and cached. This has two purposes:
Avoid infinite recursion during evaluation of the definition
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.
Call back visitors visit_entity method. See parslet/export for an example.
# File lib/parslet/atoms/visitor.rb, line 24 def accept(visitor) visitor.visit_entity(name, block) end
# File lib/parslet/atoms/entity.rb, line 24 def parslet @parslet ||= @block.call.tap { |p| raise_not_implemented unless p } end
# File lib/parslet/atoms/entity.rb, line 30 def to_s_inner(prec) name.to_s.upcase end
# File lib/parslet/atoms/entity.rb, line 20 def try(source, context, consume_all) parslet.apply(source, context, consume_all) end
# File lib/parslet/atoms/entity.rb, line 13 def initialize(name, &block) super() @name = name @block = block end