class MetaParse::MetaScanner
Attributes
parser[RW]
Public Class Methods
new(string, parser=nil)
click to toggle source
Initialize MetaScanner
with supplied string as input. Optionally-supplied parser will be receiver of Symbol message sent by subclass, FunctionMatcher
.
Calls superclass method
# File lib/meta_parse.rb, line 96 def initialize(string, parser=nil) super string @parser = parser end
Public Instance Methods
match_char(char)
click to toggle source
NOTE: This is a special case and could actually be handled by match_string
if necessary.
# File lib/meta_parse.rb, line 111 def match_char(char) c = peek(1) if c == char self.pos += 1 c end end
match_string(str, position2=0)
click to toggle source
Match and return a string or return nil, updating internal position on match.
# File lib/meta_parse.rb, line 122 def match_string(str, position2=0) if (string.equal_at(pos, str, position2)) self.pos += str.length str end end
meta()
click to toggle source
MetaScanner
is already a MetaScanner
# File lib/meta_parse.rb, line 103 def meta self end
scan(spec)
click to toggle source
Scan for a Regexp or string, returning any match, or nil, and updating internal position on match.
Calls superclass method
# File lib/meta_parse.rb, line 132 def scan(spec) case spec when Regexp result = super spec matched when String if spec.length > 0 match_string(spec) else match_char(spec) end end end