Skip to content

Commit

Permalink
Produce fatal error when #else is used outside an #if
Browse files Browse the repository at this point in the history
  • Loading branch information
sideeffect42 committed Feb 8, 2024
1 parent 386ed5f commit cfd34bf
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/29-else-outside-if/expect.err
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test/29-else-outside-if/input:1: error: #else can only be used within an #if
1 change: 1 addition & 0 deletions test/29-else-outside-if/expect.status
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
3 changes: 3 additions & 0 deletions test/29-else-outside-if/input
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#else
else
#endif
4 changes: 4 additions & 0 deletions ygpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ function eval_input(p_name, _iname, _res, _x) {
} else if (_iname == "ifndef") {
p_push(p_name, "if", !isdef($2))
} else if (_iname == "else") {
if ("if" != p_last(p_name, "type")) {
fatal("#else can only be used within an #if")
}

p_set(p_name, !p_last(p_name))
} else if (_iname == "endif") {
p_pop(p_name, "if")
Expand Down

0 comments on commit cfd34bf

Please sign in to comment.