endwhen

The endwhen command ends a when construct.

Syntax

endwhen

endwhen takes no arguments and stands alone on its line.

What it does

The preprocessor ends the when it closes. Text after it is read in the ordinary way, whichever branch was taken.

When James applies it

By the preprocessor, when it is read. The text of a branch not taken is dropped. A when is resolved before the phase of the parser matters, so it is legal anywhere.

Rules James adds

  • A closer that crosses another construct is reported once, and the construct that was force-closed forgives one later closer of its kind, so a single overlap does not cascade into a second error.
  • Every when must close in the file that opened it.

Diagnostics

  • E0302: there is no open when for it to close.
  • E0307: it crosses another construct instead of closing the innermost one.
  • E0309: the keyword shares its line with other input.
  • E0316: the open construct is not a when.

Example

The script tests/corpus/021-if-inside-when-rejected/input.tg, which make test runs:

para x 2;
para y 1;
when(%x.gt.1) then
if(%y.eq.1)then
para z 1;
endif
endwhen

James prints this, which tests/corpus/021-if-inside-when-rejected/expected.diag.txt holds:

input.tg:4:1: error [E0306]: an if scope must be disjoint from every when, for, and while scope
input.tg:3:1: note [E0306]: 'when' opened here is still open
james: 1 error, 0 warnings

An if inside a when is refused: the if on line 4 breaks the rule that the two families never nest. James reports it and names the when that is still open, and the prep dump keeps only the two para lines before the when.

See also


James 0.3.1.

This site uses Just the Docs, a documentation theme for Jekyll.