endif
The endif command ends an if construct.
Syntax
endif
endif takes no arguments and stands alone on its line.
What it does
James ends the if it closes and reads on from the next line. A construct that is skipped is closed in the same way, and its nested if constructs are matched and counted.
When James applies it
By the command parser, when it is read. It is legal in any phase: Control, Part or Merge.
Rules James adds
- Every
ifmust close with its ownendifin the file that opened it. If a file ends with anifstill open, James reports it in that file. - An
endifinside awhen,fororwhilewith noifof its own is reported as having no matchingif(E0300).
Diagnostics
- E0300: there is no open
iffor it to close. - E0309: the keyword shares its line with other input.
- E0319: an
ifreaches the end of its file without anendif.
Example
The script tests/corpus/143-if-closed-in-parent-rejected/input.tg includes branch.inc, a file in the same directory, which make test runs. branch.inc holds an if and a title, with no endif:
if(1.eq.1)then
title inner
The script itself is tests/corpus/143-if-closed-in-parent-rejected/input.tg:
include branch.inc
endif
James prints this, which tests/corpus/143-if-closed-in-parent-rejected/expected.diag.txt holds:
branch.inc:1:1: error [E0319]: 'if' is not closed with 'endif'
input.tg:2:1: error [E0300]: endif with no matching if
james: 2 errors, 0 warnings
The endif on line 2 of the script is too late: the if belongs to branch.inc and must close there. James reports it in branch.inc, and then reports the endif as having no if.