Class: Parslet::Atoms::Named
- Defined in:
- lib/parslet/atoms/named.rb,
lib/parslet/atoms/visitor.rb
Overview
Names a match to influence tree construction.
Example:
str('foo') # will return 'foo',
str('foo').as(:foo) # will return :foo => 'foo'
Constant Summary
Constants included from Precedence
Precedence::ALTERNATE, Precedence::BASE, Precedence::LOOKAHEAD, Precedence::OUTER, Precedence::REPETITION, Precedence::SEQUENCE
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parslet ⇒ Object
readonly
Returns the value of attribute parslet.
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
Call back visitors #visit_named method.
- #apply(source, context) ⇒ Object
-
#initialize(parslet, name) ⇒ Named
constructor
A new instance of Named.
- #to_s_inner(prec) ⇒ Object
Methods inherited from Base
#inspect, #parse, #parse_with_debug, precedence, #setup_and_apply, #to_s, #try
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(parslet, name) ⇒ Named
Returns a new instance of Named.
10 11 12 13 14 |
# File 'lib/parslet/atoms/named.rb', line 10 def initialize(parslet, name) super() @parslet, @name = parslet, name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/parslet/atoms/named.rb', line 9 def name @name end |
#parslet ⇒ Object (readonly)
Returns the value of attribute parslet.
9 10 11 |
# File 'lib/parslet/atoms/named.rb', line 9 def parslet @parslet end |
Instance Method Details
#accept(visitor) ⇒ Object
Call back visitors #visit_named method. See parslet/export for an example.
33 34 35 |
# File 'lib/parslet/atoms/visitor.rb', line 33 def accept(visitor) visitor.visit_named(name, parslet) end |
#apply(source, context) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/parslet/atoms/named.rb', line 16 def apply(source, context) success, value = result = parslet.apply(source, context) return result unless success succ( produce_return_value( value)) end |
#to_s_inner(prec) ⇒ Object
25 26 27 |
# File 'lib/parslet/atoms/named.rb', line 25 def to_s_inner(prec) "#{name}:#{parslet.to_s(prec)}" end |