ela
Contents

ManualLanguage

Strings

In the terminalela --spec strings

Which quotes a string takes depends on what it holds and where it stands. A command's word is each word after a command's name; code is an assignment, a call's argument, a condition or a return.

The textWriteExample
Text with a variable or a command's output"..."echo "built $name on $(date)"
A regular expression in a command'...'grep '^## |^- \*\*' MoSCoW.md
A regular expression in code`...`ok = re.match(`^\$\d+\.\d\d$`, $price)
Text holding a '`...` in code, "..." in a commandnote = `don't stop` , echo "don't stop"
Several lines with variables"""body below
Several lines as written''', or ``` in codescript below
ela code handed over by another shell or an agenta quoted here-document, ela <<'EOF' ... EOFAGENT.md, Calling ela
body = """    Hello $name,    the build of $(git rev-parse --short HEAD) is ready.    """script = '''    grep -c 'error' app.log    echo "$HOME is left to the shell"    '''

ela has three one-line forms and three multi-line forms. Only the double-quoted ones interpolate $name, $(cmd) and ${expr}.

One lineSeveral linesInterpolatesEscapes
"...""""yes\", \\, \$, \t, \n, \r, \0, and \ at a line's end
'...''''nonone
`...````nonone

One line #

  • A one-line string ends on the line it starts on. A line break inside one is an error that names the line and says what to write: close it, write \n, end the line with \ (double quotes), or use a multi-line form.
  • Double quotes interpolate: "hello $name", "${name}_backup", "built on $(date)".
  • In double quotes, a \ at the end of a line carries the string on to the next line, with no line break in the text; the next line's leading spaces or tabs are the code's and are dropped. Spaces the text needs go before the \.
  • In double quotes, any other \ is an error at that backslash: "\f", "\v" and "\d" say which escapes there are. Write \\ for a backslash, or put the text where a \ is a backslash: in single quotes as a command's word, grep '\d+' log.txt, and in backticks in code, re.replace(`[ \t\f\v]+$`, $line, ""). The error says the one that fits where the string stands.
  • Code handed to ela from another shell as ela -c '...' sits inside that shell's single quotes, so a ' in it ends them, and a regular expression can't go in '...'. Pass the code as a quoted here-document, ela <<'EOF' ... EOF, and every form in this table works as it is written (AGENT.md, Calling ela; ela --spec heredoc).
  • Single quotes are literal: no interpolation and no escapes. They can't hold a ', and two touching, bash's 'it''s done', stop the script before line 1, in code and in a command: two single-quoted texts touch, and a ' can't go inside one; write `it's done` , or in a command, which refuses backticks, '''. Two backtick texts touching stop it the same way, naming '...'. Quotes of different kinds touching are one word of a command, as in bash: '--include='"$pat".
  • Backticks are literal too, in code: an assignment, a call's argument, a condition, a return. They hold anything but a backtick, so text with a ' or " in it, and a regular expression, is written as it is. A \ in single quotes or backticks is a backslash, at a line's end too.
  • Interpolation always produces one string.
  • \0 is a NUL byte, as find -print0 and git ls-files -z end each name: str.split($(git ls-files -z), "\0"). A program's argument can't hold one, since the program would see its text end there: a command given one is an error that says to hand the text to it on stdin, echo -n $text | xargs -0 ls -l, as echo is built in and writes the NUL as it is.
  • s = "${s}more" adds more to the text s holds, in place, as xs = list.append($xs, x) adds to a list: a string built a piece at a time in a loop costs each piece once, never a copy of the whole string a round. t = "${s}more" is a new string, and s stays as it was.
msg = "Deploy of web finished in ${secs}s; \       the old pods are drained and removed."ok = re.match(`^\$\d+\.\d\d$`, $price)grep 'use `git ls-remote` here' notes.md

msg is one line: Deploy of web finished in 41s; the old pods are drained and removed.

Several lines #

  • """, ''' and ``` hold text of several lines. """ interpolates and takes the escapes of "..."; ''' and ``` are literal, so text holding one marker goes in the other.
  • Nothing follows the opening marker on its line. The text starts on the next line, and that first line break is not part of it.
  • The closing marker stands on its own line, with only indentation before it; code may follow it there, as a call's ), a ,, a | or a comment. In an expression, after =, (, ,, an operator or a keyword such as return, a line of the text may start with the marker when a word, a number, a quote or a $ follows it, ''' starts a string's text: it is text, and closes nothing. A string that is a command's word, after a word on its line, ends at the first line that starts with its marker, whatever follows: the words after it are the command's next words, sh -c ''' … ''' sh $file. Its indentation is the code's: it is removed from every line of the text, and what is indented further stays, as the text's own. A closing marker at column 0 removes nothing.
  • A line indented less than the closing marker is an error that names the line, so text is never cut off. An empty line is allowed, and is an empty line in the text.
  • Indentation is spaces or tabs, never both: a line's indentation must begin with exactly the closing marker's characters, or it is an error that names the line.
  • The line break after the last line is part of the text, so a file written from it ends with one.
  • In """, a \ at the end of a line joins it to the next, with no line break in the text. \\ there is a backslash that ends the line.
  • ``` is code only, as backticks are; """ and ''' may also stand as a command's word.
USAGE :: """    usage: ci-status [--branch B] <repo>...    For each repo, MakeHub's newest run of branch B's head.    A line says "makehub <repo> <B> <commit> run <n>: <state>".    """ proc manifest(name: string, replicas: number)    return """        apiVersion: apps/v1        kind: Deployment        metadata:          name: $name        spec:          replicas: $replicas        """end proc file.write("deploy.yaml", manifest("web", 3))

The closing """ of manifest has 8 spaces before it, so 8 are removed from each line: metadata: starts at column 0 and name: keeps its 2, and the file ends with a line break.

In a command a backtick, or ```, is an error that says to write $(cmd) to run a command or 'text' for text, since echo `date` there would mean Bash's command substitution to anyone who knows Bash.

  • Variables mean the same inside and outside strings: $s.host reads a struct field, $m[$key] a map key and $xs[1:] a slice, in commands and in double quotes alike. A key written out goes in single quotes inside double quotes, since a double quote there ends the string: echo $m["port"], but echo "port $m['port']".
  • To put text straight after a variable, always use braces: "${file}.bak", cp $file ${file}.bak. There is no second, Bash-style rule.
  • After a field read, the read goes inside the braces whole, $ and all, as ${ } holds an expression: cp app.toml ${$env.HOME}.bak, "${$s.host}_backup". ${env.HOME} is no name, and $env.HOME.bak reads a field bak. ela --lint reports ${s.host} as an error, as the run would at that line, and $VERSION.tar or $env.HOME.bak where it knows the value is text (Strict rules).
  • ${...} holds any expression, in a command and in a double-quoted string alike: echo ${len($files)}, "found ${len($xs)} files, ${text.bytes($size)}", cp $f ${path.join($dir, "backup")}. A name alone, ${file}, is that variable; anything else is an expression, with its variables written $name. Quotes inside the braces nest, as inside $( ). The value goes in as a variable holding it would.
  • Bash's ${NAME:-default}, ${#xs}, ${s%.txt} and the like are errors that name the ela form: env.get("NAME", "default"), len($xs), str.trim_suffix($s, ".txt"). A pattern in the Bash form names the call that does its usual job: ${f##*/} is path.base($f), ${f%/*} is path.dir($f), ${f%.*} is str.trim_suffix($f, path.ext($f)). Inside a string the error names the form a string takes: a call inside ${ }, ${len($xs)}, and a key in single quotes, $m['k'], or the whole in ${ }, ${$m["k"]}.