Layout
In the terminalela --spec layout
ela --fmt lays a script out one way, in place, and ela.fmt(text) gives the same as a string
(PACKAGES.md, The ela package). ela --fmt --check changes nothing and lists the files it would change,
exiting 1, for CI. A file that does not parse is an error at its line and column, and is left as
it is.
- Indentation is four spaces a level, never tabs. A block's lines are one level in from its
keyword's line;
else,else ifandcasestand at theirif's orswitch's level, andendat its block's. - Continued lines are one level in from their statement's first line: after a trailing
=, comma or pipe, and on a line starting withandoror. Inside brackets, the lines after one that opens brackets are one level in from it, however many it opens, and a line starting with the closing bracket stands at that line's level. - Spaces in code stand one on each side of
=and::, in an assignment, a constant, a default, a named argument andwith env.NAME = value; none before a comma and one after it; one wherever the script has any between two words. A command stays as written, its words, quotes, redirects and the spaces between them, and so does every command in code: aftertryandrun, inside$( ), a block whose head is a command, a deferred command,execandalias. - Blank lines in a run are kept as one, and none stay at the start or the end of the file. A proc, struct or enum at the top level has a blank line above it, above the comments that lead into it, and one below it.
- Comments stay on their lines. A trailing comment keeps the spaces before it; a comment on a
line of its own takes the indentation of the line after it, or its block's before
endor a closing bracket. endnames its block: a bareendbecomesend if,end for,end while,end switch,end with,end catch,end defer,end spin,end proc,end structorend enum, the word of the block it closes, and one already named is left as it is. A block whose body is on its own line stays on that line, itsendtoo if it has one, and the next line stands at the block's level.- A semicolon that ends a line, or doubles another, separates nothing and is left out; the one between two statements stays.
- Line breaks are the script's: a line is never broken or joined. A long line is broken where
a line may continue (Statements and blocks): after an open bracket, a comma, a pipe or
=, or beforeandoror. - Line endings are the file's: when its first line ends in CRLF, every line of the layout does.
- Strings are never changed inside. A multi-line string's closing marker stands one level in
from the line its opening marker is on, and its lines move with it, so its text stays the same;
the next line of a
"..."carried on by\moves with its statement.
proc deploy(target: string,retries=3) for i,host in hosts($target) out,err=try $(ssh $host uptime) # as typed if $err != null echo "down: $host" end if end forend proc
is laid out as
proc deploy(target: string, retries = 3) for i, host in hosts($target) out, err = try $(ssh $host uptime) # as typed if $err != null echo "down: $host" end if end forend proc