Quoting constructs: Difference between revisions

Content added Content deleted
(→‎{{header|Phix}}: added syntax colouring the hard way, phix/basics)
Line 187: Line 187:


=={{header|Phix}}==
=={{header|Phix}}==
{{libheader|Phix/basics}}
Single quotes are used for single ascii characters, eg 'A'. Multibyte unicode characters are typically held as utf-8 strings.<br>
Single quotes are used for single ascii characters, eg 'A'. Multibyte unicode characters are typically held as utf-8 strings.<br>
Double quotes are used for single-line [http://phix.x10.mx/docs/html/strings.htm strings], with backslash interpretation, eg "one\ntwo\nthree\n".<br>
Double quotes are used for single-line [http://phix.x10.mx/docs/html/strings.htm strings], with backslash interpretation, eg "one\ntwo\nthree\n".<br>
Line 192: Line 193:
Phix does not support interpolation other than printf-style, eg printf(1,"Hello %s,\nYour account balance is %3.2f\n",{name,balance}).<br>
Phix does not support interpolation other than printf-style, eg printf(1,"Hello %s,\nYour account balance is %3.2f\n",{name,balance}).<br>
Back-ticks and triple-quotes are used for multi-line strings, without backslash interpretation, eg
Back-ticks and triple-quotes are used for multi-line strings, without backslash interpretation, eg

<lang Phix>constant t123 = `
<!--<lang Phix>-->
one
<span style="color: #008080;">constant</span> <span style="color: #000000;">t123</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">`
two
one
three
two
`</lang>
three
`</span>
<!--</lang>-->

or (entirely equivalent, except the following can contain back-ticks which the above cannot, and vice versa for triple quotes)
or (entirely equivalent, except the following can contain back-ticks which the above cannot, and vice versa for triple quotes)

<lang Phix>constant t123 = """
<!--<lang Phix>-->
one
<span style="color: #008080;">constant</span> <span style="color: #000000;">t123</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
two
one
three
two
"""</lang>
three
"""</span>
<!--</lang>-->

Both are also equivalent to the top double-quote one-liner. Note that a single leading '\n' is automatically stripped.<br>
Both are also equivalent to the top double-quote one-liner. Note that a single leading '\n' is automatically stripped.<br>
Several builtins such as [http://phix.x10.mx/docs/html/substitute.htm substitute], [http://phix.x10.mx/docs/html/split.htm split], and [http://phix.x10.mx/docs/html/join.htm join] are often used to convert such strings into the required internal form.<br>
Several builtins such as [http://phix.x10.mx/docs/html/substitute.htm substitute], [http://phix.x10.mx/docs/html/split.htm split], and [http://phix.x10.mx/docs/html/join.htm join] are often used to convert such strings into the required internal form.<br>
Regular expressions are usually enclosed in back-ticks, specifically to avoid backslash interpretation.<br>
Regular expressions are usually enclosed in back-ticks, specifically to avoid backslash interpretation.<br>
You can also declare hexadecimal strings, eg
You can also declare hexadecimal strings, eg

<lang Phix>x"1 2 34 5678_AbC" -- same as {0x01, 0x02, 0x34, 0x56, 0x78, 0xAB, 0x0C}
<!--<lang Phix>-->
-- note however it displays as {1,2,52,86,120,171,12}
<span style="color: #000000;">x</span><span style="color: #008000;">"1 2 34 5678_AbC"</span> <span style="color: #000080;font-style:italic;">-- same as {0x01, 0x02, 0x34, 0x56, 0x78, 0xAB, 0x0C}
-- whereas x"414243" displays as "ABC" (as all chars)</lang>
-- note however it displays as {1,2,52,86,120,171,12}
-- whereas x"414243" displays as "ABC" (as all chars)</span>
<!--</lang>-->

Literal [http://phix.x10.mx/docs/html/sequences.htm sequences] are represented with curly braces, and can be nested to any depth, eg
Literal [http://phix.x10.mx/docs/html/sequences.htm sequences] are represented with curly braces, and can be nested to any depth, eg
<lang Phix>{2, 3, 5, 7, 11, 13, 17, 19}
<lang Phix>{2, 3, 5, 7, 11, 13, 17, 19}