Skip to content

Commit

Permalink
Fix line number reporting in unclosed #else condition
Browse files Browse the repository at this point in the history
  • Loading branch information
sideeffect42 committed Feb 8, 2024
1 parent 6db2e5e commit d2a6015
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions test/39-ifelse-unclosed/expect.err
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test/39-ifelse-unclosed/input:5: error: unclosed #if (opened at test/39-ifelse-unclosed/input:2)
1 change: 1 addition & 0 deletions test/39-ifelse-unclosed/expect.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
X is defined.
1 change: 1 addition & 0 deletions test/39-ifelse-unclosed/expect.status
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
5 changes: 5 additions & 0 deletions test/39-ifelse-unclosed/input
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#define X 42
#ifdef X
X is defined.
#else
X is not defined.
11 changes: 10 additions & 1 deletion ygpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,15 @@ function p_pop(p_name, type, _ov) {
return _ov
}

function p_set(p_name, v) {
# update the value of the top of the p_stack,
# this is used for switching conditional branches (if/switch)

if (p_isempty(p_name)) return
p_stacks[p_name, p_stacks[p_name, "p_last"]] = v
_p_update(p_name)
}

function p_last(p_name, info) {
return p_stacks[p_name, p_stacks[p_name, "p_last"] (info ? "."info : "")]
}
Expand Down Expand Up @@ -278,7 +287,7 @@ function eval_input(p_name, _iname, _res, _x) {
} else if (_iname == "ifndef") {
p_push(p_name, "if", !isdef($2))
} else if (_iname == "else") {
p_push(p_name, "if", !p_pop(p_name, "if"))
p_set(p_name, !p_last(p_name))
} else if (_iname == "endif") {
p_pop(p_name, "if")
} else if (_iname == "define") {
Expand Down

0 comments on commit d2a6015

Please sign in to comment.