W3C home > Mailing lists > Public > public-qt-comments@w3.org > January 2016

[Bug 29360] New: Extending string literal syntax

From: <bugzilla@jessica.w3.org>
Date: Wed, 06 Jan 2016 19:48:35 +0000
To: public-qt-comments@w3.org
Message-ID: <bug-29360-523@http.www.w3.org/Bugs/Public/>

            Bug ID: 29360
           Summary: Extending string literal syntax
           Product: XPath / XQuery / XSLT
           Version: Working drafts
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Requirements for Future Versions
          Assignee: jim.melton@acm.org
          Reporter: benito@benibela.de
        QA Contact: public-qt-comments@w3.org
  Target Milestone: ---

The current ways to concat strings and to escape characters in XPath can be
surprisingly complicated to use. It would be useful, if there were strings, in
which you can directly include variables or escaped entities. Such new string
literals could be distinguished with a prefix letter/marker from the older

Here are some examples, in descending order of usefulness and importance:

x"Bring {$foo} to {$bar} xxx {$zzz}" -> Like the direct element constructor,
i.e. the example is the same as <temp>Bring {$foo} to {$bar} xxx
{$zzz}</temp>/data(), but these strings would also be usable in XPath. Because
using concat can be cumbersome if you have larger texts and many things to
insert. Just compare the example to concat("Bring ",$foo," to ",$bar,"
xxx",$zzz) or ("Bring "||$foo||" to "||$bar||" xxx"||$zzz)

e"Foo &amp; bar"  --> An always entity-resolving string, in XPath and XQuery.
I.e. the example is like xpath's "Foo & bar" and xquery's "Foo &amp; bar".
Currently it is quite hard to escape things in XPath, when you pass a XPath
expression to an interpreter that you call as shell command. You can only use "
strings in the command, since ' is used to separate the expression from the
other command line arguments (or the other way around, but " in bash evaluates
$foobar which causes trouble with XPath's variables ) and then people get
confused how to use ' in the "-strings (One solution is to close the outer
quotes and open new ones, so without it  '$somefunc(e"&apos;")' has to be
written as  '$somefunc("'"'"'")' which is extremely hard too read ). 

u"Foo &amp; bar"  --> Always unescaped without entity resolving, in either
language. I.e. xpath's "Foo &amp; bar" and xquery's "Foo &amp;amp; bar".
Useful, when you have an URL u"http://www.example.com/?request=a&b=c&d=e&..."
in XQuery.

q{foo bar string} or q/foo bar string/  or q〠foo bar string〠 -> Here you do not
use " or ' as separator, but whatever character follows next to the q, similar
to Perl's single quoted strings. This is also helpful when passing XQuery
expressions to shell programs, since you can always choose a separator that
does not collide with whatever separators your shell is using. The variant
q{something} is also similar to the namespace Q{something}, so the syntax is
already familiar to XQuery users. 

“string”, 「string」 , «string»  -> Unicode quoted strings. Unicode has a lot of
different quotes. XQuery is all designed around Unicode, so it is strange that
it only uses ascii quotes for strings. These also help with the shell, since
they usually ignore non-ascii quotes.

let $i := 21 return f"the %1;o$i street" ->  Format strings, like the format-*.
In the example "The 21st street". % would mark the begin of a format and the
variable marks the type. So f"the %1;o$i street" becomes concat"the ",
format-integer($i, "1;o"), " street"). (Having the picture before the variable
makes it easier to decide where the picture and variable end) 

l"Hello" --> A localized string. First you load an i18n file (Perhaps with a
static directive like declare translation-file "foobar.ts"; ). Then l"Hello" is
"Hello" on an English system, but "Hallo" on an German system, or "你好" on a
Chinese system.  This could also be combined with the format strings. 

i"http://www.example.org" --> An include string. Like
unparsed-text("http://example.org"), but evaluated statically, before the
evaluation of the query. In case you need to have some big block of text, like
a heredoc.

j"Foo \n b\u0061r xyz\""    -> JSON like strings, with the backslash escapes
allowed in JSON. Very useful now that XQuery is getting more JSON
interoperability features. You could copy+paste a string from a JSON file into
the XQuery, after just adjusting it by adding a j. 

c"Foo \n b\x61r \n xyx\""  -> C like strings with the backslash escapes of C.

p"Foo "#10" b"#$61"r "#10" xyz"""  -> Pascal like strings. Also uses ' or " as
separators, but # to escape character codepoints.

-> Brainfuck like strings. Evaluates the string as brain fuck program and the
literal becomes the output of this evaluation. Although it is probably a bad
idea to use < and > here. Perhaps replace it with { and } ? But then it is no
longer Brainfuck. This is getting too weird.

`echo foobar` --> Executes some program and returns the result. No prefix, but
a different kind of quotes. Bash has these, so they have to be useful for

You are receiving this mail because:
You are the QA Contact for the bug.
Received on Wednesday, 6 January 2016 19:48:44 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 16:57:57 UTC