Class: Parslet::Atoms::Entity
- Defined in:
- lib/parslet/atoms/entity.rb,
lib/parslet/atoms/visitor.rb
Overview
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.
Direct Known Subclasses
Constant Summary
Constants included from Precedence
Precedence::ALTERNATE, Precedence::BASE, Precedence::LOOKAHEAD, Precedence::OUTER, Precedence::REPETITION, Precedence::SEQUENCE
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
Call back visitors #visit_entity method.
-
#initialize(name, &block) ⇒ Entity
constructor
A new instance of Entity.
- #parslet ⇒ Object
- #to_s_inner(prec) ⇒ Object
- #try(source, context) ⇒ Object
Methods inherited from Base
#apply, #inspect, #parse, #parse_with_debug, precedence, #setup_and_apply, #to_s
Methods included from CanFlatten
#flatten, #flatten_repetition, #flatten_sequence, #foldl, #merge_fold, #warn_about_duplicate_keys
Methods included from DSL
#>>, #absent?, #as, #maybe, #present?, #repeat, #|
Constructor Details
#initialize(name, &block) ⇒ Entity
Returns a new instance of Entity.
13 14 15 16 17 18 |
# File 'lib/parslet/atoms/entity.rb', line 13 def initialize(name, &block) super() @name = name @block = block end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
12 13 14 |
# File 'lib/parslet/atoms/entity.rb', line 12 def block @block end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/parslet/atoms/entity.rb', line 12 def name @name end |
Instance Method Details
#accept(visitor) ⇒ Object
Call back visitors #visit_entity method. See parslet/export for an example.
24 25 26 |
# File 'lib/parslet/atoms/visitor.rb', line 24 def accept(visitor) visitor.visit_entity(name, block) end |
#parslet ⇒ Object
24 25 26 27 28 |
# File 'lib/parslet/atoms/entity.rb', line 24 def parslet @parslet ||= @block.call.tap { |p| raise_not_implemented unless p } end |
#to_s_inner(prec) ⇒ Object
30 31 32 |
# File 'lib/parslet/atoms/entity.rb', line 30 def to_s_inner(prec) name.to_s.upcase end |
#try(source, context) ⇒ Object
20 21 22 |
# File 'lib/parslet/atoms/entity.rb', line 20 def try(source, context) parslet.apply(source, context) end |