Double quotation marks for quoted strings

From m204wiki
Jump to navigation Jump to search

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:

  1. The statements below are equivalent as of version 7.8:

    %n = 'abc':stringToHex %n = "abc":stringToHex

  2. The hex string produced by the statements below as of version 7.8 is 818283:

    printText {'abc':stringToHex} printText {"abc":stringToHex}

  3. 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

'y' is a quoted region that is a continuation of the %variable name.

(B) print %by

The %variable %by is the same as the %variable %b'y'.

(C) subroutine foo'bar'

'bar' is a quoted region that is a continuation of the subroutine name; the name is the same as the name foobar.

(D) print "here I am"

The result is: here I am, because of the new feature. Prior to this version, this statement was invalid.

(E) print 'come and 'g"et"

The result is come and g"et", 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.

(F) print "say ""uncle"""

The result is: say "uncle", because within a quoted region started by a double quotation mark, two consecutive double quotation marks are folded into one.

(G) print "Bob's"Your"Uncle"

The result is: Bob'sYourUncle, because "Uncle" is a quoted region which continues the string literal that was started by the initial double quotation mark.

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.