Scanner class
Scanner
scans strings for symbols, matches brackets, skips whitespace, etc.
Constructors
- Scanner.new(String doc, [int pos = 0])
- Create a new Scanner.
Properties
- document ↔ String
-
Text to parse.
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- inBounds → bool
-
Whether or not
position
is between 0 andlength
.no setter - length → int
-
Shorthand for
document.length
.no setter - position ↔ int
-
Current index into
document
.getter/setter pair - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
chainParse(
Map< String, void Function()> handlerChain, [bool trimWhitespace = true]) → void -
Call a series of functions based on the first matched symbol. If
trimWhitespace
is true, whitespace is skipped in between text. -
clampPos(
int pos, [int min = 0]) → int -
Make sure
pos
is betweenmin
(default: 0) and the length of this document. -
getLineCol(
[int pos = -1]) → String -
Get
pos
(defaults tothis.position
) as a line:column string. -
matchBrackets(
String open, String close, [bool canEscape = true, bool mustClose = true]) → String -
Get all characters between
open
andclose
, assumingopen
occurs atposition
indocument
. This function allows nesting unlessopen
andclose
match. IfcanEscape
istrue
(default) backslashes can escapeopen
orclose
, otherwise they are just parsed as text. IfmustClose
istrue
, an exception will be thrown if a matchingclose
to the top-levelopen
is not found. Either way, this function will throw an exception ifdocument
ends with\
or ifopen
doesn't occur atposition
. This function's result is exclusive, meaning it will not contain the top-levelopen
orclose
(but will include any nested ones. Did you get all that? -
matches(
String text) → bool -
Check if
text
occurs atposition
indocument
. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
parseAttributes(
) → Map< String, String> -
Parse a series of Dingo-style attributes starting at
position
. -
parseName(
NameScannerMode mode) → String - Read a Dingo-compliant name.
-
peek(
[int count = 1]) → String -
Get a substring from the document. If
count
is negative, this function returnscount.abs()
characters leading up to the current position. Ifcount
is positive, this function returnscount
characters after the current position. Ifcount
is 0, this function returns an empty string. The calculated start and end positions ofpeek
are bounds-checked (meaning they bottom out at0
and top out atlength
.) -
seek(
[int n = 1]) → bool -
Nudge the cursor
n
characters forward or backward. Returnstrue
if the new position is in bounds. -
skipUntil(
int condition(), [bool allowEof = false]) → void -
Skip until
condition
returns a value equal to or below 0. Throws an exception ifcondition
returns 0. Increments bycondition().abs()
. -
skipWhitespace(
) → void - Skip until we've left whitespace. Does nothing if we're not in whitespace.
-
toString(
) → String -
A string representation of this object.
inherited
-
unexpectedSymbol(
[String? expected]) → String - Throw an 'unexpected symbol' style exception.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
- invalidChars → const String
- quoteChars → const String
-
whitespaceChars
→ const List<
String>