Hacker News new | past | comments | ask | show | jobs | submit login

(I'll use position 1...5 to refer to the characters in "aaaaa", and first, second, third level to refer to the initial and then the recursive calls to the Str rule)

1. When the PEG parser enters the third level of Str, its first choice will successfully match on positions 3...5, and return to the second level of Str.

2. The first choice on the second level will fail, however, because it expects an "a" at position 6, which doesn't exist. Therefore, the first choice is discarded.

3. The second choice on the second level will succeed by matching "a" on position 2, successfully returning to the first level.

4. The first level finishes matching the first choice by consuming the "a" on position 3, successfully returning the parse tree Str = ("a" ("a") "a")

5. The remaining "aa" on positions 4...5 weren't consumed.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: