Skip to content

Parsing Patterns

Groundbreaking edited this page Aug 29, 2025 · 1 revision

Parsing Patterns and Examples

Key-Value Parsing

CharSource source = Fission.chars("key = \"value\"");
String key = source.readWhile(Character::isLetter);
source.skipWhitespace();
source.consume("=");
source.skipWhitespace();
source.consume("\"");
String value = source.readUntil('"');

Backtracking Pattern

source.mark();
String token = source.readWhile(Character::isLetter);
if (token.length() < 3) {
    source.reset(); // Backtrack
    token = source.readWhile(Character::isLetterOrDigit);
}

Look-Ahead Validation

if (source.startsWith("import")) {
    source.consume("import");
    String module = source.readWhile(ch -> ch != ';');
    source.consume(";");
}

Clone this wiki locally