Quoting constructs: Difference between revisions

→‎{{header|Wren}}: Updated to v0.4.0.
(→‎{{header|Phix}}: added syntax colouring the hard way, phix/basics)
(→‎{{header|Wren}}: Updated to v0.4.0.)
Line 499:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
Wren has two quoting constructs: ''ordinary'' string literals and (from v0.4.0) ''raw'' string literals.
The only quoting construct Wren has is the string literal which is a sequence of characters (usually interpreted as UTF-8) enclosed in double-quotes. It can include various escape sequences as listed in the [[Literals/String#Wren]] task. Unlike many other languages, Wren doesn't currently support any form of 'raw' or 'verbatim' string whereby escape sequences etc. are interpreted literally.
 
TheAn only quoting construct Wren has is the''ordinary'' string literal which is a sequence of characters (usually interpreted as UTF-8) enclosed in double-quotes. It can include various escape sequences as listed in the [[Literals/String#Wren]] task. Unlike many other languages, Wren doesn't currently support any form of 'raw' or 'verbatim' string whereby escape sequences etc. are interpreted literally.
However, it does support interpolation which enables any Wren expression, whatever its type or complexity, to be embedded in a string literal by placing it in parentheses immediately preceded by a ''%'' character. A literal ''%'' character is represented by the escape sequence ''\%''.
 
However, itIt doesalso supportsupports interpolation which enables any Wren expression, whatever its type or complexity, to be embedded in aan ''ordinary'' string literal by placing it in parentheses immediately preceded by a ''%'' character. A literal ''%'' character is represented by the escape sequence ''\%''.
 
If the expression is not a string, then it is automatically converted to one by applying its type's toString method. All classes have such a method which is usually written explicitly or can be just inherited from the Object class which sits at the top of the type hierarchy.
Line 508 ⟶ 510:
 
It can be argued that interpolated strings which contain anything other than simple expressions (for example formatting information) are hard to read anyway and, although not part of the standard language, the above module contains methods modelled after C's 'printf' function family to meet this objection.
 
A ''raw'' string literal is any text delimited by triple double-quotes, """, and is interpreted verbatim i.e. any control codes and/or interpolations are not processed as such.
 
If a triple quote appears on its own line then any trailing whitespace on that line is ignored.
 
Here are some examples of all this.
Line 530 ⟶ 536:
 
// more complicated 'printf' style
Fmt.print("$-8s more complicated 'printf' style $s\%!", h, w.join("\%"))</lang>
 
// raw string literal
var r = """
Hello, raw string literal which interpets a control code such as "\n" and an
interpolation such as %(h) as verbatim text.
Single (") or dual ("") double-quotes can be included without problem.
"""
System.print(r)
</lang>
 
{{out}}
Line 540 ⟶ 555:
Hello more complicated interpolated w%o%r%l%d%!
Hello more complicated 'printf' style w%o%r%l%d%!
Hello, raw string literal which interpets a control code such as "\n" and an
interpolation such as %(h) as verbatim text.
Single (") or dual ("") double-quotes can be included without problem.
</pre>
 
9,485

edits