Skip to content

Left-recursion

Compare
Choose a tag to compare
@PhilippeSigaud PhilippeSigaud released this 01 Feb 19:48
· 202 commits to master since this release

This new minor release (v0.3.0) brings left-recursion to Pegged, thanks to Bastiaan Veelo (@veelo).
[Note: using v0.3 as a version tag in a previous commit was a mistake, consider this the 'real' new minor release].

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);
}