class StringScanner

Overview

StringScanner provides for lexical scanning operations on a String.

Example

require "string_scanner"

s = StringScanner.new("This is an example string")
s.eos? # => false

s.scan(/\w+/) # => "This"
s.scan(/\w+/) # => nil
s.scan(/\s+/) # => " "
s.scan(/\s+/) # => nil
s.scan(/\w+/) # => "is"
s.eos?        # => false

s.scan(/\s+/) # => " "
s.scan(/\w+/) # => "an"
s.scan(/\s+/) # => " "
s.scan(/\w+/) # => "example"
s.scan(/\s+/) # => " "
s.scan(/\w+/) # => "string"
s.eos?        # => true

s.scan(/\s+/) # => nil
s.scan(/\w+/) # => nil

Scanning a string means remembering the position of a scan offset, which is just an index. Scanning moves the offset forward, and matches are sought after the offset; usually immediately after it.

Method Categories

Methods that advance the scan offset:

Methods that look ahead:

Methods that deal with the position of the offset:

Methods that deal with the last match:

Miscellaneous methods:

Defined in:

cltk/lexer.cr

Instance Method Summary

Instance methods inherited from class Object

in?(collection : Array | Set) in?

Instance Method Detail

def last_match : Regex::MatchData? #

[View source]