Processing math: 0%

Previous Up Next

Strings

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

\t tab
\n newline

The two-character sequences \rm \backslash n and \rm \backslash t are called \it escape\ sequences. Other escape sequences like \rm \backslash 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 \rm 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 \rm \backslash " may not be what you are expecting. The two-character sequence \rm \backslash " (which is not an escape sequence) does not become \rm " in any sense. Instead, it stays \rm \backslash ". This is different from most other languages, but simplifies lexing and interpreting. Example:

class Main inherits IO {
	main() : Object {
		out_string("She said, \"Hello.\"\n")
	} ;
} ;

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 \rm \backslash 0 (backslash zero). However, that sequence does not have any special meaning -- it just yields 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.

Previous Up Next