Within a Z specification, a string literal may be written by enclosing it in double quotes, e.g. "hello, world".
In the lexis, the characters of a string are expected to appear literally, with escaped-denotations provided for just the string delimiter (\") and the escape character (). The character '"' remains in the SYMBOL class and can be used in a WORDPART, but not as the first character in a WORD.
In mark-up, characters may be denoted using similar conventions to those used in the C programming language.
STRING | = | '"' , { STRCHAR } , '"' ; |
STRCHAR | = | '\' , ESCAPE |
| | ? any UCS character other than '\', '"' and NLCHAR ? | |
; |
ESCAPE | = | 'n' | (* linefeed *) |
| | 't' | (* tab *) | |
| | 'b' | (* backspace *) | |
| | 'r' | (* return *) | |
| | 'f' | (* form-feed *) | |
| | '"' | (* " *) | |
| | '\' | (* backslash *) | |
| | NLCHAR | (* continuation (elided) *) | |
| | OCTAL | OCTAL , OCTAL | OCTAL , OCTAL , OCTAL | (* base 8 encoding *) | |
| | 'u' , HEX , HEX , HEX , HEX | (* encoding on BMP *) | |
| | 'U' , HEX , HEX , HEX , HEX , HEX , HEX , HEX , HEX | (* UCS encoding *) | |
; |
OCTAL | = | '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' ; |
HEX | = | '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' ; |
Also, a \ followed by any other character is taken to be just that character.
In the concrete syntax, strings are used as literals in expressions and for commentary as predicates.
Predicate | = | comment , STRING ; |
Expression | = | STRING ; |
There is no limit on the length of a string.
String literals are of type seq ,
with the numbers being UCS encodings.
There is no notation for denoting a character literal. (The delimiter used in most other languages having been reserved in Z for use as a decoration.)