class Crass::Scanner
Experimental RBS support (using type sampling data from the type_fusion
project).
# sig/crass/scanner.rbs class Crass::Scanner def eos?: () -> bool def initialize: (String input) -> void def mark: () -> Integer def marked: () -> String def reset: () -> Integer end
CSS while preserving the original text.
Similar to a StringScanner, but with extra functionality needed to tokenize
def consume
Consumes the next character and returns it, advancing the pointer, or
def consume if @pos < @len @pos += 1 @current = @scanner.getch else '' end end
def consume_rest
the end of the string. Returns an empty string is the end of the string
Consumes the rest of the string and returns it, advancing the pointer to
def consume_rest result = @scanner.rest @current = result[-1] @pos = @len result end
def eos?
Experimental RBS support (using type sampling data from the type_fusion
project).
def eos?: () -> bool
This signature was generated using 2 samples from 1 application.
Returns `true` if the end of the string has been reached, `false`
def eos? @pos == @len end
def initialize(input)
Experimental RBS support (using type sampling data from the type_fusion
project).
def initialize: (String input) -> void
This signature was generated using 2 samples from 1 application.
def initialize(input) @string = input.is_a?(IO) ? input.read : input.to_s @scanner = StringScanner.new(@string) reset end
def mark
Experimental RBS support (using type sampling data from the type_fusion
project).
def mark: () -> Integer
This signature was generated using 1 sample from 1 application.
Sets the marker to the position of the next character that will be
def mark @marker = @pos end
def marked
Experimental RBS support (using type sampling data from the type_fusion
project).
def marked: () -> String
This signature was generated using 2 samples from 1 application.
Returns the substring between {#marker} and {#pos}, without altering the
def marked if result = @string[@marker, @pos - @marker] result else '' end end
def peek(length = 1)
doesn't consume them. The number of characters returned may be less than
Returns up to _length_ characters starting at the current position, but
def peek(length = 1) @string[pos, length] end
def reconsume
{#current}. The next call to {#consume} will re-consume the current
Moves the pointer back one character without changing the value of
def reconsume @scanner.unscan @pos -= 1 if @pos > 0 end
def reset
Experimental RBS support (using type sampling data from the type_fusion
project).
def reset: () -> Integer
This signature was generated using 1 sample from 1 application.
def reset @current = nil @len = @string.size @marker = 0 @pos = 0 end
def scan(pattern)
matched substring will be returned and the pointer will be advanced.
Tries to match _pattern_ at the current position. If it matches, the
def scan(pattern) if match = @scanner.scan(pattern) @pos += match.size @current = match[-1] end match end
def scan_until(pattern)
to and including the end of the match, and advances the pointer. If there
Scans the string until the _pattern_ is matched. Returns the substring up
def scan_until(pattern) if match = @scanner.scan_until(pattern) @pos += match.size @current = match[-1] end match end