class PoParser::Scanner

Overview

Polyfill for 1.21 StringScanner methods missing on older Crystal versions

Defined in:

po_parser/scanner.cr

Instance Method Summary

Instance Method Detail

def beginning_of_line? : Bool #

[View source]
def check(pattern : Char) : String | Nil #
Description copied from class StringScanner

Returns the value that #scan would return, without advancing the scan offset. The last match is still saved, however.

require "string_scanner"

s = StringScanner.new("this is a string")
s.offset = 5
s.check(/\w+/) # => "is"
s.check(/\w+/) # => "is"

[View source]
def current_char : Char #

[View source]
def current_char? : Char | Nil #

[View source]
def rewind(len : Int) : Nil #

[View source]
def scan(len : Int) : String | Nil #

[View source]
def scan(pattern : Char) : String | Nil #
Description copied from class StringScanner

Tries to match with pattern at the current position. If there's a match, the scanner advances the scan offset, the last match is saved, and it returns the matched string. Otherwise, the scanner returns nil.

require "string_scanner"

s = StringScanner.new("test string")
s.scan(/\w+/)  # => "test"
s.scan(/\w+/)  # => nil
s.scan(/\s\w/) # => " s"
s.scan('t')    # => "t"
s.scan("ring") # => "ring"
s.scan(/.*/)   # => ""

[View source]
def skip(len : Int) : Int32 | Nil #

[View source]
def skip(pattern : Char) : Int32 | Nil #
Description copied from class StringScanner

Attempts to skip over the given pattern beginning with the scan offset. In other words, the pattern is not anchored to the current scan offset.

If there's a match, the scanner advances the scan offset, the last match is saved, and it returns the size of the skipped match. Otherwise it returns nil and does not advance the offset.

This method is the same as #scan, but without returning the matched string.


[View source]