string literals

There are 3 forms of string literals (more if you count interpolated strings and block quotes).

without interpolation with interpolation
"string" $"\.x;"
q"string" $q"\.x;"
Q"string" $Q"\.x;"

The q and Q forms allow newlines within the quote.

quote marks

The q and Q forms allow other quote marks to be used. Valid quote mark pairs are shown below.

q"" q'' q//
q() q[] q{} q<>

string/regex modifiers

By default, string literals allow characters designated as "Graphic" by Unicode and ASCII space characters.

modifier description
any allow any code point in a string literal
block part of the syntax for blockquotes, explained next

Modifiers are are designated by a colon and the modifier name, as in the examples below. They may be chained.



Regex literals also have their own modifiers.

block quotes

Using a block modifier after a q or Q token, separated by a colon, allows you to use block quotes with a specific marker. This is similar to a "HEREDOC."

This may also be used with regex literals.

The ending marker must be on a line of its own, with no trailing spaces. As of 0.9.3, leading spaces and tabs are allowed.

val .str = q:block BLOCK_STRING some multi-line string ... BLOCK_STRING

The line return after the opening marker and the line return before the ending marker are not part of the string.

A block modifier is always the last modifier on a literal.

langur escape codes

The plain form and the q form for string literals interpret langur escape codes and the Q form does not.

Bare octal escape codes are not allowed. Use \oXXX instead.

Quote marks are not escaped by doubling, as I find that to be a confusing and inferior syntax.

\" \' \/ \) \] \} \> when otherwise used as a closing quote mark
\0 null (1 to 9 not defined)
\e escape
\t tab
\n line feed
\r carriage return
\N system newline
such as line feed or CR/LF
\L Unicode line separator
\P Unicode paragraph separator
\xXX 2 digit hexadecimal code unit (00 to 7F)
\oXXX 3 digit octal code unit (000 to 177)
\uXXXX 4 digit hexadecimal code point
\UXXXXXXXX 8 digit hexadecimal code point

string miscellany

You can use a w// or W// literal for a quoted word array, as a semantic convenience.

Besides using empty quote marks, you can use the ZLS token for an empty string (zero-length string).

string operators

~ (tilde) concatenate operator
x integer string x integer (see below)

string multiplication

To repeat a string, use it with a multiplication operator and integer.

val .result = "A" x 4 # .result == "AAAA"

String multiplication, instead of throwing an exception, treats negative integers like 0.

string concatenation

The concatenation operator may be used between strings, or between a string and an integer (code point).

"A" ~ "B" == "AB" "a" ~ 99 == "ac"

You can also concatenate code points to generate to a string.

97 ~ 98 ~ 99 == "abc"

As of 0.10.1, you can concatenate a range of numbers directly to a string, instead of using the cp2s() function first.

"a" ~ 98..100 == "abcd"

code point literals

Code point literals are specified with straight single quotes.

They are integers. There is no code point type.

Escape codes may be used in code point literals, unless they might be more than a single code point (no system newline \N escape).

'a' lowercase a
'\L' Unicode line separator
'\uFEFF' code point FEFF; same as 16xFEFF

Bare code point literals (unescaped) allowed are the same as code points allowed in string literals.