ela
Contents

ManualLanguage

Statements and blocks

In the terminalela --spec statements-and-blocks

  • A newline ends a statement.
  • A semicolon is only used to put two statements on one line.
  • Indentation is not significant.
  • A keyword (if, for, while, switch, with, proc, struct, enum, catch, and defer alone on its line) opens a block; end closes it.
  • Bash's block ends, fi, done and esac, are errors that say to write end. Since a line that starts with done is one, done names nothing: a variable, a loop variable, a parameter or a named result called done stops the script before line 1, with 'done' is reserved, as ela refuses bash's 'done', so it can't be a variable: call it something else, such as 'finished'.
  • end may be followed by an optional label: end if, end for, end while, end switch, end with, end proc, end struct, end enum, end catch, end defer. If a label is present, the parser checks that it matches the block.
  • One line. if, for, while, with, catch, defer and proc take their body on their own line, after a ;, and struct and enum their fields and values, ; between them; the line's end closes it; an end on the line closes it too. else and else if go on the same line, and so does a block inside such a body. A ; with nothing after it on the line starts no body: if $ok; and the body below is a block as any other.
  • A body begun on its header's line stays on it: a line after it is not in the block, end or else on a later line is an error that says so, and ela --lint warns of a line indented under one. switch and case take their body on the lines below.
if $a == $b; echo samefor f in *.log; rm $fif $n < 0; echo negative; else if $n == 0; echo zero; else; echo positivefor x in $xs; if $x > 1; echo $xenum Level; LOW; MID; HIGHcatch signal INT TERM; exit 130proc paid(r); return $r["paid"]

A statement continues onto the next line if the line ends with an open bracket ((, [, {, $(), a comma, a pipe or = with a space before it, or if the next line starts with and or or. A = glued to a word (key=) and a rule of = signs (=====) are words of a command, and end their line; a lone = at the end of a command's line is an error, since the next line would be more of its words: write '='. A line that is a name and = alone, echo =, is an assignment whose value is the line below, so a command there is an error at the = that says to write echo '='. A line ending in and or or is an error. Newlines inside brackets are ignored. Brackets, captures, strings inside ${ } and blocks nest at most 1000 levels deep. Arithmetic and comparison operators do not continue a line, because cd -, cd / and ls * are valid line endings, so a line ending in one is an error; wrap long arithmetic in brackets instead. No backslashes.

if file.exists($path)    and $size > 0    or $force    echo "go"end if