Skip to content

Commit 6a39d7f

Browse files
committed
RFC: Multi-line String
This RFC adds a new lexed token, the multi-line string, similar to that found in Python and Scala. A multi-line string starts and ends with a triple-quote: ``` """This is a triple-quoted string and it can contain multiple lines""" ``` Multi-line strings are useful for typing literal bodies of text where new lines should be interpretted literally. In fact, the only escape sequence used is `\"""` and `\` is otherwise allowed unescaped. This is beneficial when writing documentation within strings which may reference the back-slash often: ``` """ In a multi-line string \n and C:\\ are unescaped. """ ``` The primary value of multi-line strings are to write long-form input directly in query text, in tools like GraphiQL, and as a prerequisite to another pending RFC to allow docstring style documentation in the Schema Definition Language.
1 parent 7cada52 commit 6a39d7f

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

spec/Appendix B -- Grammar Summary.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,18 @@ ExponentIndicator :: one of `e` `E`
6969
Sign :: one of + -
7070

7171
StringValue ::
72-
- `""`
73-
- `"` StringCharacter+ `"`
72+
- `"` StringCharacter* `"`
73+
- `"""` MultiLineStringCharacter* `"""`
7474

7575
StringCharacter ::
7676
- SourceCharacter but not `"` or \ or LineTerminator
7777
- \u EscapedUnicode
7878
- \ EscapedCharacter
7979

80+
MultiLineStringCharacter ::
81+
- SourceCharacter but not `"""` or `\"""`
82+
- `\"""`
83+
8084
EscapedUnicode :: /[0-9A-Fa-f]{4}/
8185

8286
EscapedCharacter :: one of `"` \ `/` b f n r t

spec/Section 2 -- Language.md

+29-7
Original file line numberDiff line numberDiff line change
@@ -694,14 +694,18 @@ The two keywords `true` and `false` represent the two boolean values.
694694
### String Value
695695

696696
StringValue ::
697-
- `""`
698-
- `"` StringCharacter+ `"`
697+
- `"` StringCharacter* `"`
698+
- `"""` MultiLineStringCharacter* `"""`
699699

700700
StringCharacter ::
701701
- SourceCharacter but not `"` or \ or LineTerminator
702702
- \u EscapedUnicode
703703
- \ EscapedCharacter
704704

705+
MultiLineStringCharacter ::
706+
- SourceCharacter but not `"""` or `\"""`
707+
- `\"""`
708+
705709
EscapedUnicode :: /[0-9A-Fa-f]{4}/
706710

707711
EscapedCharacter :: one of `"` \ `/` b f n r t
@@ -714,16 +718,34 @@ Note: Unicode characters are allowed within String value literals, however
714718
GraphQL source must not contain some ASCII control characters so escape
715719
sequences must be used to represent these characters.
716720

717-
**Semantics**
721+
**Multi-line Strings**
718722

719-
StringValue :: `""`
723+
Multi-line strings are sequences of characters wrapped in triple-quotes (`"""`).
724+
White space, line terminators, and quote and backslash characters may all be
725+
used unescaped, enabling freeform text. Characters must all be valid
726+
{SourceCharacter} to ensure printable source text. If non-printable ASCII
727+
characters need to be used, escape sequences must be used within standard
728+
double-quote strings.
720729

721-
* Return an empty Unicode character sequence.
730+
**Semantics**
722731

723-
StringValue :: `"` StringCharacter+ `"`
732+
StringValue :: `"` StringCharacter* `"`
724733

725734
* Return the Unicode character sequence of all {StringCharacter}
726-
Unicode character values.
735+
Unicode character values (which may be empty).
736+
737+
StringValue :: `"""` MultiLineStringCharacter* `"""`
738+
739+
* Return the Unicode character sequence of all {MultiLineStringCharacter}
740+
Unicode character values (which may be empty).
741+
742+
MultiLineStringCharacter :: SourceCharacter but not `"""` or `\"""`
743+
744+
* Return the character value of {SourceCharacter}.
745+
746+
MultiLineStringCharacter :: `\"""`
747+
748+
* Return the character sequence `"""`.
727749

728750
StringCharacter :: SourceCharacter but not `"` or \ or LineTerminator
729751

0 commit comments

Comments
 (0)