Class: Spectre::StringParsing::RegExpParser

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

Overview

Matches a regular expression. Naturally this Parser is an implicit lexeme, i.e. it will ignore any skippers set on the InputIterator.

NOTE: In order to calculate the Match, the regular expression will be applied to the whole rest of the InputIterator.

Shortcut: rex.

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(rex) ⇒ RegExpParser

Returns a new instance of RegExpParser.



46
47
48
49
# File 'lib/spectre/string/additionals.rb', line 46

def initialize rex
    super()
    @rex = rex
end

Instance Method Details

#inspectObject



64
65
66
# File 'lib/spectre/string/additionals.rb', line 64

def inspect
    "[regexp:#{@rex.inspect}]"
end

#scan(iter) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/spectre/string/additionals.rb', line 51

def scan iter
    m = @rex.match iter.rest

    if m and m.pre_match.empty?
        backtrack iter
        data = nil
        iter.ignore_skipper { |i| data = i + m[0].length }
        create_match iter, data
    else
        nil
    end
end