next up previous contents
Next: Comments Up: Lexical Structure Previous: Integers, Identifiers, and Special   Contents

Strings

Strings are enclosed in double quotes "...". Within a string, a sequence `\c' denotes the two characters `\' and `c', with the exception of the following:

$\rm\backslash t$ tab
$\rm\backslash n$ newline


The two-character sequences \n and \t are called escape sequences. Other escape sequences like \r (carriage return) are not part of Cool. These two special escape sequences should not be interpreted or transformed by the lexer; they are handled by the IO module and the run-time system.

A newline character may not appear in a string:

"This is not
OK"
A string may contain embedded double quotes, so long as they are escaped. The following is a valid Cool string:
"David St. Hubbins said, \"It's such a fine line between stupid, and clever.\""

Note that Cool's interpretation of \" may not be what you are expecting. The two-character sequence \" (which is not an escape sequence) does not become " in any sense. Instead, it stays \". This is different from most other languages, but simplifies lexing and interpreting. Example:

A string may not contain EOF; strings cannot cross file boundaries. A string may not contain NUL, the character with ASCII value 0. The lexer must reject source text that contains malformed strings.

A string may contain the two-character sequence \0 (backslash zero). However, that sequence does not have any special meaning -- it just yeilds a backslash followed by a zero inside the string.

The single character with converted integer value zero (the NUL) is not allowed. Any other character may be included in a string.