Delimited strings

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Feb 14 16:38:42 PST 2012


I've finally got my lexer to the point where it can successfully
tokenize /usr/include/d2/4.3.2/std/*.d. Yay! :-) Now I'm going back to
fill in the gaps that still haven't been implemented yet. Among which
are delimited strings.

According to the online specs, delimited strings start with q" followed
by the delimiter, whether a character or an identifier. There are some
ambiguities here:

1) Does this:

	q"abca"

represent the string "bc"? Is it the same as:

	q"a
	bc
	a"

?

What do delimiter characters refer to? Are they restricted to
non-identifier symbols, like this:

	q"%abc%"

representing "abc"?


2) Among the possible delimiters are "nesting delimiters", so you can
write stuff like:

	q"(abc)"

which is the same as "abc". Now it's a bit confusing that the specs use
this as an example:

	q"(foo(xxx))"

as though the '(' and ')' inside the string matter. So does this mean
that you can write:

	q"(foo(q"(xxx)"))"

and have it represent the string

	foo(q"(xxx)")

? If not, then why are these called "nested delimiters", since any ')'
not immediately followed by " is obviously not the end of the literal?
For example, this:

	q"(a)b)"

obviously is equal to "a)b" since the first ) can't possibly terminate
the literal.


T

-- 
"I speak better English than this villain Bush" -- Mohammed Saeed
al-Sahaf, Iraqi Minister of Information


More information about the Digitalmars-d-learn mailing list