Skip to content

Left-recursion

Compare
Choose a tag to compare
@PhilippeSigaud PhilippeSigaud released this 31 Jan 14:42
· 206 commits to master since this release

This new minor release (v0.3) brings left-recursion to Pegged, thanks to Bastiaan Veelo (@veelo).

Pegged grammars now supports direct, indirect and hidden left-recursion:

import pegged.grammar;

mixin(grammar(`
  Left:
    S <- E eoi
    E <- E '+n' / 'n'
`));

void main() {  
    ParseTree result = Left("n+n+n+n");
    assert(result.successful);
    assert(result.matches == ["n", "+n", "+n", "+n"]);
}

This version also offers case-insensitive literals, marked like this: "abc"i (with a i after the literal).

import pegged.grammar;

mixin(grammar(`
    CaseInsensitive:
        S  <- "abc"i
    `));

void main() {
    assert(CaseInsensitive("aBc").successful);
    assert(CaseInsensitive("abc").successful);
    assert(CaseInsensitive("AbC").successful);
}