Dodo doc > Syntax > Literal Values > Text String Literals


Text string literals

Simple text string literals

Text string literals are enclosed in double quotes. They can be prefixed by an encoding specifier which tells the compiler which encoding to use for storing the text string. The character encoding of source files is set with the "enc" parameter of the compiler.

Some encoding specifiers are:

o"	UTF-8
x" UTF-16LE little endian, e.g. Intel x86
X" UTF-16BE big endian, e.g. Sparc
L1" Latin-1
A" ASCII

Text string literals do not define an escape character. Special characters should be escaped outside the literal. An expression inside brackets after the final double quote or between two double-quotes is evaluated and added to the text string literal. Two double-quotes in succession insert a double quote in the text string.

Examples:

"blue"
o"Café ""Fior"""
"C:\Program files\NeoCo\startup"(extension)
Rationale: encoding specifiers ensure that a text is stored using the correct encoding, which is important in non-Unicode context. Defining an escape character means there is a special character which must itself be escaped, ruining character alignment. So dodo does not define one.
The use of two double-quotes is necessary to allow the double quote character in text string literals. Using an expression in brackets is an elegant way to mix code with text.

Multi line string literals

Multi-line string literals open each line with a double quote. Each line of the multi-line literal ends with the last character of the line. The last line of the multi-line literal ends with a double quote.

Example:

"This continued
"		text ends
"			here."
Rationale: the double quote before each line of a multi-line literal allows text to be easily aligned and indicates the literal continues on that line.

Interpolated string literals

Unlike regular text string literals, interpolated string literals can contain special characters escaped with a backslash "\". They are enclosed with single quotes. Inside an interpolated string literal the single-quote character must be escaped (\').

Examples:

'Ol\' castle on the hill'
'A\nB\nC'

Interpolated string literals cannot use an encoding specifier. A succession of interpolated string literals without a "+" operator between them are joined with newlines, which means 'A' 'B' 'C' is the same as 'A\nB\nC'.

An interpolated string literal can contain expressions enclosed with "${}" which are evaluated and inserted in the string.

Example:

'The ${colour} house'
Rationale: the single-quote syntax allows to write a sequence of special characters in a simple way. Since it supports escaping, that enables expression interpolation in string literals. Multi-line interpolated string literals can be written with simple juxtaposition. That can ensure no invisible character enters the string, allows comments after the line and is more text editor friendly.

^ 2.4.1. Number Literals

v 2.4.3. Special Characters