TextScanner


TextScanner creates an object that wraps raw text enabling character-by-character scanning with arbitrary advancement and backtracking. Text can optionally be “squeezed” of any unquoted whitespace, i.e. between pairs of unescaped ' or ".

Constructors


TextScanner(string, [bool]) ➜ TextScanner

Constructs a new TextScanner over given text, optionally ignoring unquoted whitespace, i.e. between pairs of unescaped ' or ". By default all whitespace is considered a token.

Instance Properties


Index ➜ int

Current location of the scanner in the raw text.

Index :: int

Offset ➜ int

Total number of characters that have been scanned, not counting whitespace if it is being ignored.

Text ➜ string

Raw text being scanned.

Instance Methods


Advance([int]) ➜ ()

Moves the scanner forward a given number of characters, stopping if it reaches the end. Default is one character.

Backtrack([int]) ➜ ()

Moves the scanner backwards a given number of characters, stopping if it reaches the beginning. Default is one character.

Read([int]) ➜ ReadOnlyMemory<char>

Moves the scanner forward and returns a given number of characters, stopping if it reaches the end. Default is one character.

ReadToEnd() ➜ ReadOnlyMemory<char>

Moves the scanner forward and returns all unscanned characters.

Reset() ➜ ()

Moves the scanner to the beginning.