Double quotation marks for quoted strings
As of Sirius Mods version 7.8, the SOUL and Janus SOAP compiler accepts either a single-quotation-mark character (') or a double-quotation-mark character (") 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:
- The statements below are equivalent as of version 7.8:
%n = 'abc':stringToHex %n = "abc":stringToHex
- The hex string produced by the statements below as of version 7.8 is
818283
:printText {'abc':stringToHex} printText {"abc":stringToHex}
- The first and second statements below are equivalent as of version 7.8,
producing the string
IT'S COOL!
:printText {'It''s cool!':toUpper} printText {"It's cool!":toUpper} printText {"It''s cool!":toUpper}
The last statement in the example above produces the string
IT''S COOL!
, which demonstrates that repeating a single quotation mark does not escape it if the quoted string is delimited with double quotation marks.
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:
RESET FUNCOPTS X"00"
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 User Language 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 Hello
:
print 'Hel'lo
You can also continue the quoted region:
print 'Hel'lo' World'
This prints Hello World
.
In addition, you can quote parts of unquoted tokens:
pr'int' 'Hello World'
This also prints Hello World
.
User Language quoted string continuation and the new functionality of double quotation marks are shown in the following annotated request, which is valid in Sirius Mods version 7.8. The letter labels on the left are not part of the request but are for the commentary that follows:
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
(A) | %b'y' string len 255
|
---|---|
(B) | print %by
The %variable |
(C) | subroutine foo'bar'
|
(D) | print "here I am"
The result is: |
(E) | print 'come and 'g"et"
The result is |
(F) | print "say ""uncle"""
The result is: |
(G) | print "Bob's"Your"Uncle"
The result is: |
The following statement would produce a compilation error:
print 'say'Uncle" Bob"
" Bob"
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 Bob"
ends the quoted string and makes the
final four characters extraneous and invalid for the Print 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:
%x = foo'BAR'
This statement causes %x
to be set to the value of field FOOBAR.
However, the following statement results in %x
being set to the
value of field FOO"BAR":
%x = foo"BAR"
This is necessary to preserve backward compatibility.