Class: Spectre::StringParsing::RegExpParser
- Inherits:
-
Object
- Object
- Spectre::StringParsing::RegExpParser
- 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
Instance Method Summary collapse
-
#initialize(rex) ⇒ RegExpParser
constructor
A new instance of RegExpParser.
- #inspect ⇒ Object
- #scan(iter) ⇒ Object
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
#inspect ⇒ Object
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 |