[swift-evolution] About SE-0168 Multi-line string literals

Dany St-Amant dsa.mls at icloud.com
Thu May 18 06:12:51 CDT 2017


Hello,

 Been catching up on threads, and it seems that one thing did not come up during the really long discussions: conditional segment.

let Usage = """
    Tool X
      -i  specify input file
      -o specify output file
#if SOME_OS
      -c magic conversion
#endif
    """

Since the #if/#endif, unlike C (which is way to permissive), cannot be used everywhere, such thing is likely current impossible. The limitation of #if/#endif is so "strict" that, based on the single double quote string behaviour, to achieve the desired result one have to duplicate the immutable or convert it to a mutable (even though the content is immutable)

var Usage = """
    Tool X
      -i  specify input file
      -o specify output file
    ''""
#if SOME_OS
Usage = Usage + """
      -c magic conversion
    """
#endif

Debating over the need of supporting conditional section is likely too late in the play, but rating this point may allow provisioning to be done to allow this in the future without breaking code.

The currently accepted version of SE-0168, seems to allow the closing triple double-quote to be in the first column, which would prevent the use of #if/#endif, but for all other cases an under-indented #if/#endif line is supposed to be considered as malformed and rejected (warning raised). So, in theory it could be interpreted properly as #if/#endif

If interpreting the under-indented line for #if/#endif seems acceptable, the interpretation could be also extended to comments.

Regards,
Dany


More information about the swift-evolution mailing list