Class: Spectre::ClosureParser
- Inherits:
-
Object
- Object
- Spectre::ClosureParser
- 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
Instance Attribute Summary collapse
-
#sym ⇒ Object
readonly
The symbol that identifies the Parser inside the Closure.
Attributes included from Parser
Instance Method Summary collapse
-
#initialize(sym) ⇒ ClosureParser
constructor
sym
is the identifier for the value retrieved from the Closure. - #inspect ⇒ Object
- #negation ⇒ Object
- #scan(iter) ⇒ Object
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
#sym ⇒ Object (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
#inspect ⇒ Object
72 73 74 |
# File 'lib/spectre/base/closure.rb', line 72 def inspect "[closure:#{@sym}]" end |
#negation ⇒ Object
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 |