Skip to content

Commit b3668eb

Browse files
committed
More istring spec work.
1 parent fcc7438 commit b3668eb

File tree

2 files changed

+68
-15
lines changed

2 files changed

+68
-15
lines changed

spec/istring.dd

+61-13
Original file line numberDiff line numberDiff line change
@@ -10,49 +10,97 @@ string, but can contain values that are passed directly to a function that is
1010
able to accept them. It is transformed into a $(I Sequence) of expressions that
1111
can be overloaded or handled by template functions.)
1212

13+
$(H2 $(LNAME2 ies, IES Literals))
14+
1315
$(GRAMMAR
1416
$(GNAME InterpolationExpressionSequence):
17+
$(GLINK InterpolatedDoubleQuotedLiteral)
18+
$(GLINK InterpolatedWysiwygLiteral)
19+
$(GLINK InterpolatedTokenLiteral)
20+
)
21+
22+
$(P An Interpolation Expression sequence can either wysiwyg quoted, double
23+
quoted, or a token literal. Only double quoted literals can have escapes in
24+
them.)
25+
26+
$(P Unlike string literals, IES literals cannot have a suffix defining the
27+
width of the character type for the string expressions.)
28+
29+
$(H3 $(LNAME2 ies_doublequoted, Double Quoted IES Literals))
30+
31+
$(GRAMMAR
32+
$(GNAME InterpolatedDoubleQuotedLiteral):
1533
$(B i") $(GLINK InterpolatedDoubleQuotedCharacters)$(OPT) $(B ")
16-
$(B $(BACKTICK)) $(GLINK InterpolatedWysiwygCharacters)$(OPT) $(B $(BACKTICK))
17-
$(D q{) $(GLINK InterpolatedTokenStringTokens)$(OPT) $(D })
1834

1935
$(GNAME InterpolatedDoubleQuotedCharacters):
2036
$(GLINK InterpolatedDoubleQuotedCharacter)
2137
$(GLINK InterpolatedDoubleQuotedCharacter) $(GSELF InterpolatedDoubleQuotedCharacters)
2238

2339
$(GNAME InterpolatedDoubleQuotedCharacter):
24-
$(GLINK DoubleQuotedCharacter)
40+
$(GLINK2 lexical, DoubleQuotedCharacter)
2541
$(GLINK InterpolationEscapeSequence)
2642
$(GLINK InterpolationExpression)
2743

2844
$(GNAME InterpolationEscapeSequence):
2945
$(GLINK EscapeSequence)
3046
$(B \\\$)
3147

48+
$(GNAME InterpolationExpression):
49+
$(B \$$(LPAREN)) $(GLINK AssignExpression) $(B $(RPAREN))
50+
)
51+
52+
$(P Like $(GLINK2 lexical, DoubleQuotedString), double-quoted IES literals can
53+
have escape characters in them. Added to the normal escapes is the ability to
54+
escape a literal $)
55+
56+
$(P A $ followed by any other chraracter other than a left parenthesis is
57+
treated as a literal $ in the expression, there is no need to escape it.)
58+
59+
$(P The expression inside an $(GLINK InterpolationExpression) is a full D
60+
expression, and escapes are not needed inside that part of the expression.)
61+
62+
$(H3 $(LNAME2 ies_wysiwyg, Wysiwyg IES Literals))
63+
64+
$(GRAMMAR
65+
$(GNAME InterpolatedWysiwygLiteral):
66+
$(B i$(BACKTICK)) $(GLINK InterpolatedWysiwygCharacters)$(OPT) $(B $(BACKTICK))
67+
3268
$(GNAME InterpolatedWysiwygCharacters):
3369
$(GLINK InterpolatedWysiwygCharacter)
3470
$(GLINK InterpolatedWysiwygCharacter) $(GSELF InterpolatedWysiwygCharacters)
3571

3672
$(GNAME InterpolatedWysiwygCharacter):
37-
$(GLINK WysiwygCharacter)
73+
$(GLINK2 lexical, WysiwygCharacter)
3874
$(GLINK InterpolationExpression)
75+
)
76+
77+
$(P Wysiwyg ("what you see is what you get") IES literals are defined like
78+
$(GLINK2 lexical, WysiwygString) strings, but only support backquote syntax. No
79+
escapes are recognized inside these literals.)
80+
81+
$(H3 $(LNAME2 ies_token, Token IES Literals))
82+
83+
$(GRAMMAR
84+
$(GNAME InterpolatedTokenLiteral):
85+
$(D iq{) $(GLINK InterpolatedTokenStringTokens)$(OPT) $(D })
3986

4087
$(GNAME InterpolatedTokenStringTokens):
4188
$(GLINK InterpolatedTokenStringTokenNoBraces)
4289
$(GLINK InterpolatedTokenStringToken) $(GSELF InterpolatedTokenStringTokens)
4390

4491
$(GNAME InterpolatedTokenStringToken):
4592
$(GLINK InterpolatedTokenNoBraces)
46-
(D {) $(GSELF InterpolatedTokenStringTokens)$(OPT) $(D })
93+
$(B {) $(GSELF InterpolatedTokenStringTokens)$(OPT) $(B })
4794

4895
$(GNAME InterpolatedTokenNoBraces):
49-
$(GLINK TokenNoBraces)
50-
$(GLINK InterpolationExpression);
51-
52-
$(GNAME InterpolationExpression):
53-
$(B $ (LPAREN)) $(GLINK AssignExpression) $(B $(RPAREN))
96+
$(GLINK2 lexical, TokenNoBraces)
97+
$(GLINK InterpolationExpression)
5498
)
5599

100+
$(P Like $(GLINK2 lexical, TokenString), IES Token literals must contain only
101+
valid D tokens, with the exception of $(GLINK InterpolationExpression). No
102+
escapes are recognized.)
103+
56104
$(H2 $(LNAME2 expression_translation, Expression Translation))
57105

58106
$(P When the lexer encounters an Interpolation Expression Sequence, the token
@@ -64,7 +112,7 @@ $(D core.interpolation.InterpolationFooter()))
64112
$(P Each part $(D str) of the token which is literal string data is translated
65113
into the expression $(D core.interpolation.InterpolatedLiteral!(str)))
66114

67-
$(P Each part $(D $$(LPAREN)expr$(RPAREN)) of the token which is an $(GLINK
115+
$(P Each part $(D \$$(LPAREN)expr$(RPAREN)) of the token which is an $(GLINK
68116
InterpolationExpression) is translated into the sequence $(D
69117
core.interpolation.InterpolatedExpression!(expr)$(COMMA) expr).)
70118

@@ -154,7 +202,7 @@ alias result = processIES!i"Here is a type: $(int)";
154202
$(H2 $(LNAME2 tostring, Converting to a String))
155203

156204
$(P In many cases, it is desirable to convert an IES to a $(D string). The
157-
Phobos function $(D std.conv.text) can convert the IES to a $(D string) for use
205+
Phobos function $(REF text, std.conv) can convert the IES to a $(D string) for use
158206
in any context where a string is needed, for instance to assign to a string
159207
variable, or call a function that accepts a string.)
160208

@@ -177,4 +225,4 @@ $(SPEC_SUBNAV_PREV_NEXT lex, Lexical, grammar, Grammar)
177225

178226
Macros:
179227
CHAPTER = 3
180-
TITLE = Interpolation Expression Sequences
228+
TITLE = Interpolation Expression Sequence

spec/lex.dd

+7-2
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ $(GNAME WysiwygCharacter):
350350
// 'a', '"', 'b', '\', 'n'
351351
---
352352

353+
$(P See also $(GLINK2 istring, InterpolatedWysiwygLiteral))
354+
353355
$(H3 $(LNAME2 double_quoted_strings, Double Quoted Strings))
354356
$(GRAMMAR_LEX
355357
$(GNAME DoubleQuotedString):
@@ -377,6 +379,9 @@ $(GNAME DoubleQuotedCharacter):
377379
" // string is 3 characters,
378380
// 'a', 'b', and a linefeed
379381
---
382+
383+
$(P See also $(GLINK2 istring, InterpolatedDoubleQuotedLiteral))
384+
380385
$(H3 $(LNAME2 delimited_strings, Delimited Strings))
381386
$(GRAMMAR_LEX
382387
$(GNAME DelimitedString):
@@ -493,6 +498,8 @@ $(GNAME TokenStringToken):
493498
// __EOF__ is not a token, it's end of file
494499
---
495500

501+
$(P See also $(GLINK2 istring, InterpolatedTokenLiteral))
502+
496503
$(H3 $(LNAME2 hex_strings, Hex Strings))
497504
$(GRAMMAR
498505
$(GNAME HexString):
@@ -655,8 +662,6 @@ $(UL
655662
$(P Otherwise, it resolves to the type with the smallest size it
656663
will fit into.)
657664

658-
$(P For Interpolation Expression Sequences, see $(GLINK2 istring, InterpolationExpressionSequence).)
659-
660665
$(H2 $(LNAME2 integerliteral, Integer Literals))
661666

662667
$(GRAMMAR_LEX

0 commit comments

Comments
 (0)