diff --git a/pages/book/expressions.mdx b/pages/book/expressions.mdx index ba454036..e6b7a045 100644 --- a/pages/book/expressions.mdx +++ b/pages/book/expressions.mdx @@ -68,17 +68,69 @@ Read more about booleans and [`Bool{:tact}`](/book/types#booleans) type in the d A string literal is zero or more characters enclosed in double (`"`) quotation marks. All string literals are objects of [`String{:tact}`][p] type. ```tact -"foo" -"1234" +"foo"; +"1234"; +``` + +Tact strings support a range of [escape sequences](https://en.wikipedia.org/wiki/Escape_sequence) starting with a backslash `\\` character: + +* `\\{:tact}` — literal backslash +* `\"{:tact}` — double quote +* `\n{:tact}` — newline +* `\r{:tact}` — carriage return +* `\t{:tact}` — tab +* `\v{:tact}` — vertical tab +* `\b{:tact}` — backspace +* `\f{:tact}` — form feed +* `\x00{:tact}` through `\xFF{:tact}` — [code point](https://en.wikipedia.org/wiki/Code_point), must be exactly two hex digits long +* `\u0000{:tact}` through `\uFFFF{:tact}` — [Unicode code point][unicode], must be exactly four hex digits long +* `\u{0}{:tact}` through `\u{FFFFFF}{:tact}` — [Unicode code point][unicode], can be from $1$ to $6$ hex digits long + +[unicode]: https://en.wikipedia.org/wiki/Unicode#Codespace_and_code_points + +```tact +// \\ +"escape \\ if \\ you \\ can \\"; + +// \" +"this \"literally\" works"; + +// \n +"line \n another line"; + +// \r +"Shutters \r Like \r This \r One"; -// Note, that at the moment Tact strings can't have escape characters in them: -"line \n another"; // SYNTAX ERROR!, see: https://github.com/tact-lang/tact/issues/25 +// \t +"spacing \t granted!"; -// This means, that double quotes inside strings are also prohibited: -"this \"can't be!\""; // SYNTAX ERROR! +// \v +"those \v words \v are \v aligned"; + +// \b +"rm\b\bcreate!"; + +// \f +"form \f feed"; + +// \x00 - \xFF +"this \x22literally\x22 works"; // \x22 represents a double quote + +// \u0000 - \uFFFF +"danger, \u26A1 high voltage \u26A1"; // \u26A1 represents the ⚡ emoji + +// \u{0} - \u{FFFFFF} +"\u{1F602} LOL \u{1F602}"; // \u{1F602} represents the 😂 emoji ``` -Read more about strings and [`String{:tact}`][p] type there: [Primitive types][p]. + + + Read more about strings and [`String{:tact}`][p] type:\ + [Primitive types in the Book][p]\ + [Strings and StringBuilders in the Reference](/ref/api-strings) + + + ### `null` literal