Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

String Literals

This chapter specifies string literal syntax in Dada.

Delimiters

There are multiple forms of string literals:

  • .quoted Single-quoted string literals begin with a " and end with a ".
  • .triple-quoted Triple-quoted string literals begin with a """ and end with a """.

The syntax """ is interpreted as the start of a triple-quoted string literal and not a single-quoted string literal followed by the start of another single-quoted string literal.

A triple-quoted string literal cannot contain three consecutive unescaped double-quote characters.

Type

String literals have type my String.

Escape Sequences

String literals support the following escape sequences:

The \" escape sequence is not needed in triple-quoted strings, since embedded double quotes do not terminate the string.

A \ followed by a character not listed above is an error.

Interpolation

String literals may contain interpolation expressions delimited by curly braces ({ and }). Any valid Dada expression may appear inside the braces.

Literal brace characters are produced by the \{ and \} escape sequences.

The lexer tracks brace nesting depth, so that braces within interpolated expressions (e.g., block expressions, struct literals) do not prematurely terminate the interpolation.

Quotes inside interpolated expressions do not terminate the enclosing string literal.

Interpolated expressions are evaluated at runtime in the enclosing scope.

Interpolated expressions are evaluated left-to-right.

Each interpolated expression must produce a value that can be converted to a string. This is checked at compile time.

The permission system applies normally to interpolated expressions.

Multiline Strings

A string literal that begins with a newline immediately after the opening quote (either " or """) is a multiline string literal with automatic indentation handling.

The leading newline immediately after the opening quote is removed.

The trailing newline immediately before the closing quote is removed, along with any whitespace on the final line.

The common whitespace prefix across all non-empty lines is removed from the start of each line.

Escape sequences are part of the string content, not whitespace. They are not affected by leading/trailing stripping or dedenting.

A string literal beginning with "\ followed by a newline disables automatic dedenting. The string preserves its content exactly as written, including the leading newline and all indentation.

String Conversion

Interpolated expressions must produce values that can be converted to strings. The exact conversion mechanism is not yet defined and depends on Dada’s trait/interface system.

Implementation Notes

A string literal with no interpolation expressions can be compiled as a simple string constant with no runtime overhead.