Class: Parslet::Atoms::Scope

Inherits:
Base
  • Object
show all
Defined in:
lib/parslet/atoms/scope.rb

Overview

Starts a new scope in the parsing process. Please also see the #captures method.

Constant Summary

Constants included from Precedence

Precedence::ALTERNATE, Precedence::BASE, Precedence::LOOKAHEAD, Precedence::OUTER, Precedence::REPETITION, Precedence::SEQUENCE

Instance Attribute Summary collapse

Attributes inherited from Base

#label

Instance Method Summary collapse

Methods inherited from Base

#accept, #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, #capture, #ignore, #maybe, #present?, #repeat, #|

Constructor Details

#initialize(block) ⇒ Scope

Returns a new instance of Scope.



6
7
8
9
10
# File 'lib/parslet/atoms/scope.rb', line 6

def initialize(block)
  super()

  @block = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



5
6
7
# File 'lib/parslet/atoms/scope.rb', line 5

def block
  @block
end

Instance Method Details

#apply(source, context, consume_all) ⇒ Object



16
17
18
19
20
21
# File 'lib/parslet/atoms/scope.rb', line 16

def apply(source, context, consume_all)
  context.scope do
    parslet = block.call
    return parslet.apply(source, context, consume_all)
  end
end

#cached?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/parslet/atoms/scope.rb', line 12

def cached?
  false
end

#to_s_inner(prec) ⇒ Object



23
24
25
# File 'lib/parslet/atoms/scope.rb', line 23

def to_s_inner(prec)
  "scope { #{block.call.to_s(prec)} }"
end