Commit 9bdf078
Branislav Zahradník
[parser] Formalize KW_FOR as a keyword starting new lexical scope
Tests covering this changes:
- t/op/for-control-scope.t
- t/op/for-over-scope.t
* Motivation
Normalize where new lexical context starts so every variant
of for loop will start it at same position.
Such normalization will later allow reduction of code currently
duplicated.
* Change description
For statement already defined its own lexical scope in each its branch
though in different places for each branch (using <*> as a marker):
```
for (<*> $control = 0; ...)
for my <*> $cursor (...)
for my <*> ($cursor_a, $cursor_b) (...)
for $cursor (<*> ...)
for my \ <*> $cursor (...)
for \ my <*> $cursor (...)
for \ $cursor (<*> ... )
for (<*> ...)
```
This change formalizes every branch to start with:
```
for <*> ...
```
* Technical details
Lexical scope is started by non-terminal `remember` - empty with an action.
Bison's LALR(1) grammar evaluates action before looking which terminal token
follows, which means, that when `remember` occurs it must be either:
- preceded by unique sequence of terminal tokens (approach used before)
- be on same position for every possible branch (approach used by this change)
As far as `KW_FOR` (as statement) always starts new lexical scope,
it's possible to formalize it by starting it right after keyword,
when `for` statement is identified.1 parent 1cb2676 commit 9bdf078
4 files changed
+685
-684
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments