Class: Spectre::StringParsing::CharParser

Inherits:
Object
  • Object
show all
Includes:
Parser
Defined in:
lib/spectre/string/primitives.rb

Overview

Matches one single character. Shortcut: char.

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(char) ⇒ CharParser

Returns a new instance of CharParser.



54
55
56
57
# File 'lib/spectre/string/primitives.rb', line 54

def initialize char
    super()
    @char = char
end

Instance Method Details

#inspectObject



69
70
71
# File 'lib/spectre/string/primitives.rb', line 69

def inspect
    "[char:'#{@char}']"
end

#negationObject



59
# File 'lib/spectre/string/primitives.rb', line 59

def negation; Negations::NegatedSingleTokenParser.new; end

#scan(iter) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/spectre/string/primitives.rb', line 61

def scan iter
    if iter.valid? and +iter == @char
        create_match iter, @char
    else
        nil
    end
end