Skip to content

Commit

Permalink
Fix nested look-ahead switches.
Browse files Browse the repository at this point in the history
Closes #1810.
  • Loading branch information
rsmmr committed Jul 29, 2024
1 parent 4c5c26b commit 215b8bf
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions spicy/toolchain/src/compiler/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,7 @@ unit_switch_case
| exprs ARROW unit_item { $$ = builder->typeUnitItemSwitchCase($1, {$3}, __loc__); }
| '*' ARROW unit_item { $$ = builder->typeUnitItemSwitchCase(type::unit::Items{$3}, __loc__); }
| ARROW unit_field { $$ = builder->typeUnitItemSwitchCase($2, __loc__); }
| ARROW unit_switch { $$ = builder->typeUnitItemSwitchCase($2, __loc__); }

/* --- End of Spicy units --- */

Expand Down
11 changes: 11 additions & 0 deletions tests/Baseline/spicy.types.unit.switch-nested-lahead/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
foo::X {
a: a
}
foo::X {
b: b
}
foo::X {
c: c
}
[fatal error] terminating with uncaught exception of type spicy::rt::ParseError: no expected look-ahead token found (<...>/switch-nested-lahead.spicy:18:10-18:20)
20 changes: 20 additions & 0 deletions tests/spicy/types/unit/switch-nested-lahead.spicy
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# @TEST-EXEC: spicyc %INPUT -j -o %INPUT.hlto
# @TEST-EXEC: ${SCRIPTS}/printf a | spicy-dump %INPUT.hlto >>output 2>&1
# @TEST-EXEC: ${SCRIPTS}/printf b | spicy-dump %INPUT.hlto >>output 2>&1
# @TEST-EXEC: ${SCRIPTS}/printf c | spicy-dump %INPUT.hlto >>output 2>&1
# @TEST-EXEC-FAIL: ${SCRIPTS}/printf d | spicy-dump %INPUT.hlto >>output 2>&1
# @TEST-EXEC: btest-diff output
#
# @TEST-DOC: Check nested switch constructs both using look-ahead.

module foo;

public type X = unit {
switch {
-> switch {
-> a: b"a";
-> b: b"b";
};
-> c: b"c";
};
};

0 comments on commit 215b8bf

Please # to comment.