parse method
- String source
override
Attempts to parse the source string matching this element.
Returns a ParseResult containing the parsed lexeme and remaining string on success. On failure, returns a failed ParseResult.
Implementation
@override
ParseResult parse(String source) {
// Check if the source string is empty.
if (source.isEmpty) {
return ParseResult(false, source, element: toString());
}
final rune = source.runes.first;
// Check if the 32-bit code point falls within the range.
if (rune < start || rune > end) {
return ParseResult(false, source, element: toString());
}
// Yield exactly one rune.
final lexeme = String.fromCharCode(rune);
return ParseResult(
true,
source.substring(lexeme.length),
element: toString(),
lexeme: lexeme,
);
}