Class: Spectre::SymParser

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

Overview

Provides lazy evaluation of the Parser name, so you can use it recursively and before specifying it.

Instance Attribute Summary

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) ⇒ SymParser

Initializes the SymParser to look for sym.



37
38
39
# File 'lib/spectre/base/grammar.rb', line 37

def initialize sym
    @sym = sym
end

Instance Method Details

#inspectObject



48
49
50
# File 'lib/spectre/base/grammar.rb', line 48

def inspect
    "[<#{@sym.inspect}>]"
end

#scan(is) ⇒ Object



41
42
43
44
45
46
# File 'lib/spectre/base/grammar.rb', line 41

def scan is
    n = @node.find @sym
    raise "rule #{@sym.inspect} not found." unless n
    n.parent = @node
    n.parse is
end