Double quotation marks for quoted strings: Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
 
Line 1: Line 1:
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.
As of <var class="product">Sirius Mods</var> version 7.8, the <var class="product">[[SOUL]]</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
Prior to this version, only a single-quotation-mark character (also called an
''apostrophe'') could be such a delimiter.
''apostrophe'') could be such a delimiter.
Line 6: Line 6:
<ol>
<ol>
<li>The statements below are equivalent as of version 7.8:
<li>The statements below are equivalent as of version 7.8:
<p class="code"> %n = 'abc':stringToHex
<p class="code">%n = 'abc':stringToHex  
%n = "abc":stringToHex
%n = "abc":stringToHex
</p>
</p>
<li>The hex string produced by the statements below as of version 7.8 is
<li>The hex string produced by the statements below as of version 7.8 is
<code>818283</code>:
<code>818283</code>:
<p class="code"> printText {'abc':stringToHex}
<p class="code">printText {'abc':stringToHex}  
printText {"abc":stringToHex}
printText {"abc":stringToHex}
</p>
</p>
<li>The first and second statements below are equivalent as of version 7.8,
<li>The first and second statements below are equivalent as of version 7.8,
producing the string <code>IT'S COOL!</code>:
producing the string <code>IT'S COOL!</code>:
<p class="code"><nowiki> printText {'It''s cool!':toUpper}
<p class="code"><nowiki>printText {'It''s cool!':toUpper}  
printText {"It's cool!":toUpper}  
printText {"It's cool!":toUpper}
printText {"It''s cool!":toUpper}</nowiki>
printText {"It''s cool!":toUpper}</nowiki>
</p>
</p>
The last statement in the example above produces the string <code><nowiki>IT''S COOL!</nowiki></code>,
The last statement in the example above produces the string <code><nowiki>IT''S COOL!</nowiki></code>,
Line 28: Line 24:
single quotation mark does not escape it if the quoted string is delimited with double quotation marks.
single quotation mark does not escape it if the quoted string is delimited with double quotation marks.
</ol>
</ol>
'''Note:'''
<p class="note">'''Note:'''
Since this double quotation mark feature is restricted to the compiler, it does not affect command parsing,
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>
and the following command is still '''''invalid''''':
<p class="code"> RESET FUNCOPTS X"00"
<p class="code"> RESET FUNCOPTS X"00"
</p>
</p>
Line 41: Line 36:
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.
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>:
So, the following statement prints <code>Hello</code>:
<p class="code"> print 'Hel'lo
<p class="code">print 'Hel'lo
</p>
</p>
   
   
You can also continue the quoted region:
You can also continue the quoted region:
<p class="code"> print 'Hel'lo' World'
<p class="code">print 'Hel'lo' World'
</p>
</p>
This prints <code>Hello World</code>.
This prints <code>Hello World</code>.
In addition, you can quote parts of unquoted tokens:
In addition, you can quote parts of unquoted tokens:
<p class="code"> pr'int' 'Hello World'
<p class="code">pr'int' 'Hello World'
</p>
</p>
   
   
Line 58: Line 53:
The letter labels on the left
The letter labels on the left
are not part of the request but are for the commentary that follows:
are not part of the request but are for the commentary that follows:
<p class="code">       Begin
<p class="code">     Begin
(A)  %b'y' string len 255
(A)  %b'y' string len 255
      %b'y' = 'abc'
      %b'y' = 'abc'
      print  %b'y'
      print  %b'y'
(B)  print  %by
(B)  print  %by
      call foobar
      call foobar
(C)  subroutine foo'bar'
(C)  subroutine foo'bar'
(D)      print "here I am"
(D)      print "here I am"
(E)      print 'come and 'g"et"
(E)      print 'come and 'g"et"
(F)      print "say ""uncle"""
(F)      print "say ""uncle"""
(G)      print "Bob's"Your"Uncle"
(G)      print "Bob's"Your"Uncle"
      end subroutine
      end subroutine
      end
      end
</p>
</p>
<table>
<table>
Line 112: Line 107:
   
   
The following statement would produce a compilation error:
The following statement would produce a compilation error:
<p class="code"> print 'say'Uncle" Bob"
<p class="code">print 'say'Uncle" Bob"
</p>
</p>
   
   
Line 124: Line 119:
quotation mark character is allowed to produce a quoted piece of the token.
quotation mark character is allowed to produce a quoted piece of the token.
For example, the following statement is valid:
For example, the following statement is valid:
<p class="code"> %x = foo'BAR'
<p class="code">%x = foo'BAR'
</p>
</p>
   
   
Line 130: Line 125:
However, the following statement results in <code>%x</code> being set to the
However, the following statement results in <code>%x</code> being set to the
value of field FOO"BAR":
value of field FOO"BAR":
<p class="code"> %x = foo"BAR"
<p class="code">%x = foo"BAR"
</p>
</p>
   
   

Latest revision as of 16:07, 26 June 2014

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.