Parsing Python's indent rules
suite ::= stmt_list NEWLINE
| NEWLINE INDENT statement+ DEDENT
token suite {
<stmt_list> <newline>
| <newline> <indent> <statement>
[ <indent_same> <statement> ]* <dedent>
}
- <indent> measures horizontal whitespace, pushes new level onto stack
- <indent_same> verifies same level of nesting as previous line
- <dedent> pops stack to previous indentation level
- These are all just custom Parrot subs
- manage the stack
- fail or throw exceptions if indentation errors arise