Class: Spectre::ClosureParser

Inherits:
Object
  • Object
show all
Includes:
Parser
Defined in:
lib/spectre/base/closure.rb

Overview

Retrieves a value from the Closure and uses it as a Parser. The retrieval is performed at parse time.

Direct Known Subclasses

NegatedClosureParser

Instance Attribute Summary collapse

Attributes included from Parser

#node

Instance Method Summary collapse

Methods included from Parser

#backtrack, #create_match, from_POD, #pre_skip?, #to_p

Constructor Details

#initialize(sym) ⇒ ClosureParser

sym is the identifier for the value retrieved from the Closure.



60
61
62
# File 'lib/spectre/base/closure.rb', line 60

def initialize sym
    @sym = sym
end

Instance Attribute Details

#symObject (readonly)

The symbol that identifies the Parser inside the Closure.



55
56
57
# File 'lib/spectre/base/closure.rb', line 55

def sym
  @sym
end

Instance Method Details

#inspectObject



72
73
74
# File 'lib/spectre/base/closure.rb', line 72

def inspect
    "[closure:#{@sym}]"
end

#negationObject



64
# File 'lib/spectre/base/closure.rb', line 64

def negation; NegatedClosureParser.new @sym; end

#scan(iter) ⇒ Object



66
67
68
69
70
# File 'lib/spectre/base/closure.rb', line 66

def scan iter
    raise "symbol #{@sym.inspect} not found in closure #{@node.closure.inspect}" unless
        @node.closure and @node.closure[@sym]
    create_match iter, @node.closure[@sym].to_p.parse(iter)
end