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) {
final result = sequence.elements._parseSequenceWithBacktracking(
source,
toString(),
);
if (result.success) {
return result;
} else {
// If the sequence parse failed, the optional sequence still succeeds,
// but consumes nothing and returns an empty result.
return ParseResult(
true, // Success is true because it's optional
source, // No input consumed, remaining is the original source
element: toString(),
lexeme: '', // No lexeme produced
stack: Stack<ParseResult>(), // Empty stack
);
}
}