Skip to content

Commit 14b0998

Browse files
authored
Move string literal grammar into subsections (#3658)
There were subsections for the string literal varieties, but their grammar sections were all in the parent "String Literals" section.
1 parent 4b9aa5e commit 14b0998

File tree

1 file changed

+80
-79
lines changed

1 file changed

+80
-79
lines changed

spec/lex.dd

Lines changed: 80 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -293,33 +293,19 @@ $(GNAME StringLiteral):
293293
$(GLINK DelimitedString)
294294
$(GLINK TokenString)
295295
)
296-
$(GRAMMAR_LEX
297-
$(GNAME WysiwygString):
298-
$(B r") $(GLINK WysiwygCharacters)$(OPT) $(B ") $(GLINK StringPostfix)$(OPT)
299-
300-
$(GNAME AlternateWysiwygString):
301-
$(B $(BACKTICK)) $(GLINK WysiwygCharacters)$(OPT) $(B $(BACKTICK)) $(GLINK StringPostfix)$(OPT)
302-
303-
$(GNAME WysiwygCharacters):
304-
$(GLINK WysiwygCharacter)
305-
$(GLINK WysiwygCharacter) $(GSELF WysiwygCharacters)
296+
$(P
297+
A string literal is either a double quoted string, a wysiwyg quoted
298+
string, a delimited string, or a token string.
299+
)
306300

307-
$(GNAME WysiwygCharacter):
308-
$(GLINK Character)
309-
$(GLINK EndOfLine)
301+
$(P In all string literal forms, an $(GLINK EndOfLine) is regarded as a single
302+
$(D \n) character.)
310303

311-
$(GNAME DoubleQuotedString):
312-
$(B ") $(GLINK DoubleQuotedCharacters)$(OPT) $(B ") $(GLINK StringPostfix)$(OPT)
304+
$(P String literals are read only.)
313305

314-
$(GNAME DoubleQuotedCharacters):
315-
$(GLINK DoubleQuotedCharacter)
316-
$(GLINK DoubleQuotedCharacter) $(GSELF DoubleQuotedCharacters)
317-
318-
$(GNAME DoubleQuotedCharacter):
319-
$(GLINK Character)
320-
$(GLINK EscapeSequence)
321-
$(GLINK EndOfLine)
306+
$(UNDEFINED_BEHAVIOR writing to a string literal. This is not allowed in `@safe` code.)
322307

308+
$(GRAMMAR_LEX
323309
$(GNAME EscapeSequence):
324310
$(B \\')
325311
$(B \\")
@@ -345,67 +331,24 @@ $(GNAME StringPostfix):
345331
$(B c)
346332
$(B w)
347333
$(B d)
334+
)
348335

349-
$(GNAME DelimitedString):
350-
$(B q") $(GLINK Delimiter) $(GLINK WysiwygCharacters)$(OPT) $(GLINK MatchingDelimiter) $(B ") $(GLINK StringPostfix)$(OPT)
351-
$(B q"$(LPAREN)) $(GLINK ParenDelimitedCharacters)$(OPT) $(B $(RPAREN)") $(GLINK StringPostfix)$(OPT)
352-
$(B q"[) $(GLINK BracketDelimitedCharacters)$(OPT) $(B ]") $(GLINK StringPostfix)$(OPT)
353-
$(B q"{) $(GLINK BraceDelimitedCharacters)$(OPT) $(B }") $(GLINK StringPostfix)$(OPT)
354-
$(B q"<) $(GLINK AngleDelimitedCharacters)$(OPT) $(B >") $(GLINK StringPostfix)$(OPT)
355-
356-
$(GNAME Delimiter):
357-
$(GLINK Identifier)
358-
359-
$(GNAME MatchingDelimiter):
360-
$(GLINK Identifier)
361-
362-
$(GNAME ParenDelimitedCharacters):
363-
$(GLINK WysiwygCharacter)
364-
$(GLINK WysiwygCharacter) $(GSELF ParenDelimitedCharacters)
365-
$(B $(LPAREN)) $(GSELF ParenDelimitedCharacters)$(OPT) $(B $(RPAREN))
366-
367-
$(GNAME BracketDelimitedCharacters):
368-
$(GLINK WysiwygCharacter)
369-
$(GLINK WysiwygCharacter) $(GSELF BracketDelimitedCharacters)
370-
$(B [) $(GSELF BracketDelimitedCharacters)$(OPT) $(B ])
336+
$(H3 $(LNAME2 wysiwyg, Wysiwyg Strings))
337+
$(GRAMMAR_LEX
338+
$(GNAME WysiwygString):
339+
$(B r") $(GLINK WysiwygCharacters)$(OPT) $(B ") $(GLINK StringPostfix)$(OPT)
371340

372-
$(GNAME BraceDelimitedCharacters):
373-
$(GLINK WysiwygCharacter)
374-
$(GLINK WysiwygCharacter) $(GSELF BraceDelimitedCharacters)
375-
$(B {) $(GSELF BraceDelimitedCharacters)$(OPT) $(B })
341+
$(GNAME AlternateWysiwygString):
342+
$(B $(BACKTICK)) $(GLINK WysiwygCharacters)$(OPT) $(B $(BACKTICK)) $(GLINK StringPostfix)$(OPT)
376343

377-
$(GNAME AngleDelimitedCharacters):
344+
$(GNAME WysiwygCharacters):
378345
$(GLINK WysiwygCharacter)
379-
$(GLINK WysiwygCharacter) $(GSELF AngleDelimitedCharacters)
380-
$(B <) $(GSELF AngleDelimitedCharacters)$(OPT) $(B >)
381-
)
382-
$(GRAMMAR
383-
$(GNAME TokenString):
384-
$(D q{) $(GLINK TokenStringTokens)$(OPT) $(D }) $(GLINK StringPostfix)$(OPT)
385-
386-
$(GNAME TokenStringTokens):
387-
$(GLINK TokenStringToken)
388-
$(GLINK TokenStringToken) $(GSELF TokenStringTokens)
346+
$(GLINK WysiwygCharacter) $(GSELF WysiwygCharacters)
389347

390-
$(GNAME TokenStringToken):
391-
$(GLINK TokenNoBraces)
392-
$(D {) $(GLINK TokenStringTokens)$(OPT) $(D })
348+
$(GNAME WysiwygCharacter):
349+
$(GLINK Character)
350+
$(GLINK EndOfLine)
393351
)
394-
395-
$(P
396-
A string literal is either a double quoted string, a wysiwyg quoted
397-
string, a delimited string, or a token string.
398-
)
399-
400-
$(P In all string literal forms, an $(GLINK EndOfLine) is regarded as a single
401-
$(D \n) character.)
402-
403-
$(P String literals are read only.)
404-
405-
$(UNDEFINED_BEHAVIOR writing to a string literal. This is not allowed in `@safe` code.)
406-
407-
$(H3 $(LNAME2 wysiwyg, Wysiwyg Strings))
408-
409352
$(P
410353
Wysiwyg ("what you see is what you get") quoted strings can be defined
411354
using either of two syntaxes.
@@ -439,6 +382,19 @@ $(H3 $(LNAME2 wysiwyg, Wysiwyg Strings))
439382
---
440383

441384
$(H3 $(LNAME2 double_quoted_strings, Double Quoted Strings))
385+
$(GRAMMAR_LEX
386+
$(GNAME DoubleQuotedString):
387+
$(B ") $(GLINK DoubleQuotedCharacters)$(OPT) $(B ") $(GLINK StringPostfix)$(OPT)
388+
389+
$(GNAME DoubleQuotedCharacters):
390+
$(GLINK DoubleQuotedCharacter)
391+
$(GLINK DoubleQuotedCharacter) $(GSELF DoubleQuotedCharacters)
392+
393+
$(GNAME DoubleQuotedCharacter):
394+
$(GLINK Character)
395+
$(GLINK EscapeSequence)
396+
$(GLINK EndOfLine)
397+
)
442398

443399
$(P Double quoted strings are enclosed by "". $(GLINK EscapeSequence)s can be
444400
embedded in them.)
@@ -452,8 +408,41 @@ $(H3 $(LNAME2 double_quoted_strings, Double Quoted Strings))
452408
" // string is 3 characters,
453409
// 'a', 'b', and a linefeed
454410
---
455-
456411
$(H3 $(LNAME2 delimited_strings, Delimited Strings))
412+
$(GRAMMAR_LEX
413+
$(GNAME DelimitedString):
414+
$(B q") $(GLINK Delimiter) $(GLINK WysiwygCharacters)$(OPT) $(GLINK MatchingDelimiter) $(B ") $(GLINK StringPostfix)$(OPT)
415+
$(B q"$(LPAREN)) $(GLINK ParenDelimitedCharacters)$(OPT) $(B $(RPAREN)") $(GLINK StringPostfix)$(OPT)
416+
$(B q"[) $(GLINK BracketDelimitedCharacters)$(OPT) $(B ]") $(GLINK StringPostfix)$(OPT)
417+
$(B q"{) $(GLINK BraceDelimitedCharacters)$(OPT) $(B }") $(GLINK StringPostfix)$(OPT)
418+
$(B q"<) $(GLINK AngleDelimitedCharacters)$(OPT) $(B >") $(GLINK StringPostfix)$(OPT)
419+
420+
$(GNAME Delimiter):
421+
$(GLINK Identifier)
422+
423+
$(GNAME MatchingDelimiter):
424+
$(GLINK Identifier)
425+
426+
$(GNAME ParenDelimitedCharacters):
427+
$(GLINK WysiwygCharacter)
428+
$(GLINK WysiwygCharacter) $(GSELF ParenDelimitedCharacters)
429+
$(B $(LPAREN)) $(GSELF ParenDelimitedCharacters)$(OPT) $(B $(RPAREN))
430+
431+
$(GNAME BracketDelimitedCharacters):
432+
$(GLINK WysiwygCharacter)
433+
$(GLINK WysiwygCharacter) $(GSELF BracketDelimitedCharacters)
434+
$(B [) $(GSELF BracketDelimitedCharacters)$(OPT) $(B ])
435+
436+
$(GNAME BraceDelimitedCharacters):
437+
$(GLINK WysiwygCharacter)
438+
$(GLINK WysiwygCharacter) $(GSELF BraceDelimitedCharacters)
439+
$(B {) $(GSELF BraceDelimitedCharacters)$(OPT) $(B })
440+
441+
$(GNAME AngleDelimitedCharacters):
442+
$(GLINK WysiwygCharacter)
443+
$(GLINK WysiwygCharacter) $(GSELF AngleDelimitedCharacters)
444+
$(B <) $(GSELF AngleDelimitedCharacters)$(OPT) $(B >)
445+
)
457446

458447
$(P Delimited strings use various forms of delimiters.
459448
The delimiter, whether a character or identifier,
@@ -505,6 +494,18 @@ q"/foo]/" // "foo]"
505494
---
506495

507496
$(H3 $(LNAME2 token_strings, Token Strings))
497+
$(GRAMMAR
498+
$(GNAME TokenString):
499+
$(D q{) $(GLINK TokenStringTokens)$(OPT) $(D }) $(GLINK StringPostfix)$(OPT)
500+
501+
$(GNAME TokenStringTokens):
502+
$(GLINK TokenStringToken)
503+
$(GLINK TokenStringToken) $(GSELF TokenStringTokens)
504+
505+
$(GNAME TokenStringToken):
506+
$(GLINK TokenNoBraces)
507+
$(D {) $(GLINK TokenStringTokens)$(OPT) $(D })
508+
)
508509

509510
$(P Token strings open with the characters $(D q)$(CODE_LCURL) and close with
510511
the token $(CODE_RCURL). In between must be valid D tokens.

0 commit comments

Comments
 (0)