|
|
Line 1: |
Line 1: |
| ==Double quotation marks for quoted strings==
| | Content moved to M204int page of same name, but history preserved here. |
|
| |
| As of <var class="product">Sirius Mods</var> version 7.8, the <var class="product">User Language</var> and <var class="product">[[Janus SOAP]]</var> compiler accepts either a single-quotation-mark character (<tt>'</tt>) or a double-quotation-mark character (<tt>"</tt>) as a quoted-string delimiter.
| |
| Prior to this version, only a single-quotation-mark character (also called an
| |
| ''apostrophe'') could be such a delimiter.
| |
|
| |
| These are examples of the feature:
| |
| <ol>
| |
| <li>The statements below are equivalent as of version 7.8:
| |
| <p class="code"> %n = 'abc':stringToHex
| |
|
| |
| %n = "abc":stringToHex
| |
| </p>
| |
| <li>The hex string produced by the statements below as of version 7.8 is
| |
| <code>818283</code>:
| |
| <p class="code"> printText {'abc':stringToHex}
| |
|
| |
| printText {"abc":stringToHex}
| |
| </p>
| |
| <li>The first and second statements below are equivalent as of version 7.8,
| |
| producing the string <code>IT'S COOL!</code>:
| |
| <p class="code"><nowiki> printText {'It''s cool!':toUpper}
| |
|
| |
| printText {"It's cool!":toUpper}
| |
|
| |
| printText {"It''s cool!":toUpper}</nowiki>
| |
| </p>
| |
| The last statement in the example above produces the string <code><nowiki>IT''S COOL!</nowiki></code>,
| |
| which demonstrates that repeating a
| |
| single quotation mark does not escape it if the quoted string is delimited with double quotation marks.
| |
| </ol>
| |
| '''Note:'''
| |
| Since this double quotation mark feature is restricted to the compiler, it does not affect command parsing,
| |
| and the following command is still '''''invalid''''':
| |
| <p class="code"> RESET FUNCOPTS X"00"
| |
| </p>
| |
|
| |
| As a rule, the double quotation mark character can be used to enclose, or bracket,
| |
| a quoted region that begins a string literal, or to bracket a
| |
| "continuation" of a string literal that begins with a double quotation mark,
| |
| but it may not otherwise be used to bracket a quoted region.
| |
|
| |
| The "continuation of a string literal" refers to the peculiar <var class="product">User Language</var> concept that a quoted token does not end until it reaches a space or separator character after the closing quotation mark character.
| |
| So, the following statement prints <code>Hello</code>:
| |
| <p class="code"> print 'Hel'lo
| |
| </p>
| |
|
| |
| You can also continue the quoted region:
| |
| <p class="code"> print 'Hel'lo' World'
| |
| </p>
| |
| This prints <code>Hello World</code>.
| |
| In addition, you can quote parts of unquoted tokens:
| |
| <p class="code"> pr'int' 'Hello World'
| |
| </p>
| |
|
| |
| This also prints <code>Hello World</code>.
| |
|
| |
| <var class="product">User Language</var> quoted string continuation and the new functionality of double quotation marks
| |
| are shown in the following annotated request, which is valid in <var class="product">Sirius Mods</var> version 7.8.
| |
| The letter labels on the left
| |
| are not part of the request but are for the commentary that follows:
| |
| <p class="code"> Begin
| |
| (A) %b'y' string len 255
| |
| %b'y' = 'abc'
| |
| print %b'y'
| |
| (B) print %by
| |
| call foobar
| |
| (C) subroutine foo'bar'
| |
| (D) print "here I am"
| |
| (E) print 'come and 'g"et"
| |
| (F) print "say ""uncle"""
| |
| (G) print "Bob's"Your"Uncle"
| |
| end subroutine
| |
| end
| |
| </p>
| |
| <table>
| |
| <tr><th>(A)
| |
| </th><td>'''%b'y' string len 255'''
| |
|
| |
| <code>'y'</code> is a quoted region that is a continuation of the %variable name.
| |
| </td></tr>
| |
| <tr><th>(B)
| |
| </th><td>'''print %by'''
| |
|
| |
| The %variable <code>%by</code> is the same as the %variable <code>%b'y'</code>.
| |
| </td></tr>
| |
| <tr><th>(C)
| |
| </th><td>'''subroutine foo'bar''''
| |
|
| |
| <code>'bar'</code> is a quoted region that is a continuation of the subroutine name; the name is the same as the name <code>foobar</code>.
| |
| </td></tr>
| |
| <tr><th>(D)
| |
| </th><td>'''print "here I am"'''
| |
|
| |
| The result is: <code>here I am</code>, because of the new feature. Prior to this version, this statement was invalid.
| |
| </td></tr>
| |
| <tr><th>(E)
| |
| </th><td>'''print 'come and 'g"et"'''
| |
|
| |
| The result is <code>come and g"et"</code>, because the double quotation marks are ordinary characters
| |
| (not brackets for a quoted region) in a string literal that starts with a single quotation mark. The string literal extends beyond the second single quotation mark until ended by a blank or the end of the string. Since this result also occurred prior to version 7.8, backward compatibility dictates the new rule that the opening quotation mark in a quoted string determines the quote bracketing character through the rest of the quoted
| |
| string.
| |
| </td></tr>
| |
| <tr><th>(F)
| |
| </th><td>'''print "say ""uncle"""'''
| |
|
| |
| The result is: <code>say "uncle"</code>, because within a quoted region started by a double quotation mark, two consecutive double quotation marks are folded into one.
| |
| </td></tr>
| |
| <tr><th>(G)
| |
| </th><td>'''print "Bob's"Your"Uncle"'''
| |
|
| |
| The result is: <code>Bob'sYourUncle</code>, because <code>"Uncle"</code> is a quoted region which continues the string literal that was started by the initial double quotation mark.
| |
| </td></tr></table>
| |
|
| |
| The following statement would produce a compilation error:
| |
| <p class="code"> print 'say'Uncle" Bob"
| |
| </p>
| |
|
| |
| <code>" Bob"</code> is ''not'' a quoted region that continues the
| |
| string literal (because the string literal is started by the initial
| |
| single quotation mark and not by an initial double quotation mark),
| |
| so the blank before <code>Bob"</code> ends the quoted string and makes the
| |
| final four characters extraneous and invalid for the <var>Print</var> statement.
| |
|
| |
| A final note: in a string that does not start with a quotation mark, only a single
| |
| quotation mark character is allowed to produce a quoted piece of the token.
| |
| For example, the following statement is valid:
| |
| <p class="code"> %x = foo'BAR'
| |
| </p>
| |
|
| |
| This statement causes <code>%x</code> to be set to the value of field FOOBAR.
| |
| However, the following statement results in <code>%x</code> being set to the
| |
| value of field FOO"BAR":
| |
| <p class="code"> %x = foo"BAR"
| |
| </p>
| |
|
| |
| This is necessary to preserve backward compatibility.
| |
| | |
| ==Text/Html statement enhancements==
| |
| These features are added in <var class="product">Sirius Mods</var> 7.8.
| |
| ===Tilde directives===
| |
| As of <var class="product">Sirius Mods</var> 7.8, certain <var>Text</var>/<var>Html</var> statementdirectives can be placed after a tilde character (<tt>~</tt>) inside curly braces (<tt>{ }</tt>) in any of the [[Targeted Text statements|targeted text statements]] (which include <var>AuditText</var>, <var>PrintText</var>, <var>TraceText</var>, and new in V7.8, <var>[[#SetText|SetText]]</var> and <var>[[#ReturnText|ReturnText]]</var>.
| |
| For example, this statement sets <code>%ls</code> to the current time, embedded in hyphens:
| |
| <p class="code">setText %ls = {~nocont}---{$time}---
| |
| </p>
| |
| Because the <code>~nocont</code> directive was specified, the terminating hyphen is not treated as a continuation character.
| |
|
| |
| The tilde directives that are allowed in targeted text statements are:
| |
| <table>
| |
| <tr><th>~exprE
| |
| </th><td>Sets the expression end characters. This directive must be followed by a space and then the expression start characters.
| |
| For example, <code>{~expre >}</code> sets the expression end characters to a single greater-than sign (<tt>></tt>). <var>~exprE</var> can also be written as <code>~exprEnd</code>.
| |
|
| |
| '''Note:''' The <var>~exprE</var> directive must be ended by the current expression end characters, that is, by the end characters that the <var>~expre</var> directive is replacing.
| |
| </td></tr>
| |
| <tr><th>~exprS
| |
| </th><td>Sets the expression start characters. This directive must be followed by a space and then the expression start characters. For example, <code>{~exprs <}</code> sets the expression start characters to a single less-than sign (<tt><</tt>). <var>~exprS</var> can also be written as <code>~exprStart</code>.
| |
| </td></tr>
| |
| <tr><th>~noCont
| |
| </th><td>Indicates that a trailing hyphen is not treated as a continuation character. <var>~noCont</var> can also be written as <code>~noContinuations</code>.
| |
| </td></tr>
| |
| <tr><th>~noEll
| |
| </th><td>Indicates that a trailing ellipsis (<tt>...</tt>) is '''not''' treated as a partial-line indicator. Because it makes no sense to end a <var>SetText</var> or <var>ReturnText</var> with an ellipsis, this is the default for those two statements. So, while allowed, a <var>~noEll</var> directive is completely unnecessary for <var>SetText</var> and <var>ReturnText.</var> <var>~noEll</var> can also be written as <code>~noEllipses</code>.
| |
| </td></tr>
| |
| <tr><th>~noExpr
| |
| </th><td>Indicates that no expressions are to be processed after the directive, and that everything after the <var>~noExpr</var> directive is treated as literal text. No further tilde directives will be processed after a <var>~noExpr.</var> <var>~noExpr</var> can also be written as <code>~noExpressions</code>.
| |
| </td></tr>
| |
| <tr><th>~raw
| |
| </th><td>Acts as if <var>~noCont</var>, <var>~noEll</var>, and <var>~noExpr</var> are specified simultaneously.
| |
|
| |
| '''Note:''' This is slightly different from the <var>Raw</var> directive on the <var>Text</var>/<var>Html</var> statement, which also implies <var>NoDum</var>/<var>NoDummy</var>. Because dummy string substitution applies to lines before they are parsed, dummy string substitution would already have happened in any single-line <var>Text</var> statement before the <var>~raw</var> directive was processed.
| |
| </td></tr></table>
| |
|
| |
| ===~= directives===
| |
| As of <var class="product">Sirius Mods</var> version 7.8, you can use a <b>[[Targeted Text statements#tildeEqual|~= directive]]</b> as a shorthand for <code>{~}={''expression''}</code>.
| |
| For example, <br><code>printtext {~=%i}, {~=%j}, {~=(%i+%j):toPower(3)}</code> displays:
| |
| <p class="code">%i=22, %j=33, (%i + %j):toPower(3)=166375
| |
| </p>
| |
| Note that in the directive, spaces are optional after the equal sign, and the output can produce spaces before or after the equal sign.
| |
| | |
| ===SetText statement===
| |
| The <var>SetText</var> statement works much the same as <var>AuditText</var>, <var>PrintText</var>, and <var>TraceText</var>, but it is used to set a variable instead of outputting a string. That is, its primary intent is to use the text it sets in the current program.
| |
|
| |
| The syntax of the <var>SetText</var> statement is:
| |
| <p class="code">setText %variable = string
| |
| </p>
| |
| Where:
| |
| <table>
| |
| <tr><th>%variable</th>
| |
| <td>A simple variable, a class variable, a class property, or a collection member (which is really just a special kind of class property).
| |
| <p>For example, the following statement sets the <var>String</var> property of a <var>StringTokenizer</var> object to the literal string <code>"Once upon a time"</code>:</p>
| |
| <p class="code">%toke is object stringTokenizer
| |
| ...
| |
| setText %toke:string = Once upon a time
| |
| </p>
| |
| A single blank after the equal sign following a <var>SetText</var> is not required and is ignored, though you can use it for readability. The following statements both set <var class="term">%str</var> to
| |
| <code>Once a jolly swagman camped by a billabong</code>:
| |
| <p class="code">setText %str =Once a jolly swagman camped by a billabong
| |
| </p>
| |
| and
| |
| <p class="code">setText %str = Once a jolly swagman camped by a billabong
| |
| </p>
| |
| Any additional blanks beyond the first one are treated as part of the literal source string.</td></tr>
| |
|
| |
| <tr><th>string</th>
| |
| <td>A literal string which may include expressions enclosed by curly braces, just as is used in the <var>Text</var> statement. <p>For example, the following statement sets <code>%x</code> to the literal string <code>Patriotism is the last refuge of the scoundrel</code>:</p>
| |
| <p class="code">setText %x = Patriotism is the last refuge of the scoundrel
| |
| </p>
| |
| And the following sets <code>%x</code> to the literal string <code>The sum of %x and %y is </code> followed by the sum of <code>%x</code> and <code>%y</code>:
| |
| <p class="code">setText %x = The sum of %x and %y is {%x + %y}
| |
| </p></td></tr>
| |
| </table>
| |
|
| |
| Continuations are treated in the normal way: the text continues from the first non-blank character on the next line.
| |
| <br><b>Tip</b>: if you need to include blank characters from the next line, use <code>{}</code> (a null expression) to indicate the start of the continuation. For example:
| |
| <p class="code">setText %str = Once a jolly swagman camped by:-
| |
| {} a billabong
| |
| </p>
| |
| The statement above sets <code>%str</code> to:
| |
| <p class="output">Once a jolly swagman camped by: a billabong
| |
| </p>
| |
| However, since trailing blanks before a continuation are '''not''' stripped, you can also include blank characters by putting extra blanks at the end of the first <var>SetText</var> line:
| |
| <p class="code">setText %str = Once a jolly swagman camped by: -
| |
| a billabong
| |
| </p>
| |
| If you need to terminate the string with a hyphen, add the <code>{}</code> null expression to the end of a line. For example:
| |
| <p class="code">setText %str = ------------{}
| |
| </p>
| |
| The statement above sets <code>%str</code> to:
| |
| <p class="code">------------
| |
| </p>
| |
| You can also use the <var>~noCont</var> directive to indicate that a trailing hyphen is not to be treated as a continuation character:
| |
| <p class="code">setText %str = {~nocont}------------
| |
| </p>
| |
| ===ReturnText statement===
| |
| The <var>ReturnText</var> statement works much the same as <var>AuditText</var>, <var>PrintText</var>, and <var>TraceText</var>, but instead of outputting a string, it is used to return a string value in a <var class="product">User Language</var> function or property <var>[[Methods#Method definition syntax|Get]]</var> method. The syntax of the <var>ReturnText</var> statement is:
| |
| <p class="code"><nowiki>ReturnText string
| |
| </nowiki></p>
| |
| Where:
| |
| <table>
| |
| <tr><th>string</th>
| |
| <td>A literal string which may include expressions enclosed by curly braces, just as in the <var>Text</var> statement.</td></tr>
| |
| </table>
| |
| For example, if the <code>Aphorism</code> local function is applied to the number 1 in the following fragment, the function returns the literal string <code>Patriotism is the first refuge of the scoundrel</code>:
| |
| <p class="code"> local function (float):aphorism is longstring
| |
|
| |
| if %this eq 1 then
| |
| returnText Patriotism is the first refuge of the scoundrel
| |
| end if
| |
| ...
| |
| end function
| |
| </p>
| |
| The following function returns the literal string <code>The sum of %x and %y is </code> followed by the sum of the <code>%x</code> and <code>%y</code> parameters passed to the local function:
| |
| <p class="code"> local function stringAdd(%x is float, %y is float)
| |
|
| |
| returnText The sum of %x and %y is {%x + %y}
| |
|
| |
| end function
| |
| </p>
| |
|
| |
| Continuations are treated in the normal way: the text continues from the first non-blank character on the next line.<br>
| |
| <b>Tip</b>: As shown above for <var>SetText</var>:
| |
| <ul>
| |
| <li>If you need to include blank characters from the next line, use <code>{}</code> (a null expression) to indicate the start of the continuation.
| |
| <li>If you need to terminate the string with a hyphen, add the <code>{}</code> null expression to the end of a line.
| |
| <li>You can also use the <var>~noCont</var> directive to indicate that a trailing hyphen is not to be treated as a continuation character.
| |
| </ul>
| |
|
| |
| ==Addition to COMMLOG parameter==
| |
| This version of the <var class="product">Sirius Mods</var> implements the X'04' bit of the <var>[[COMMLOG parameter|COMMLOG]]</var> User 0 parameter. This activates support for daemon login improvements when
| |
| used in conjunction with the X'02' bit.
| |
| | |
| {{Template:Content index: V7.8 Release Notes}}
| |