Skip to content

Commit

Permalink
Spec for \" in interpolated strings
Browse files Browse the repository at this point in the history
  • Loading branch information
lrytz committed Mar 8, 2021
1 parent 7d95201 commit 7c81006
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 10 additions & 7 deletions spec/01-lexical-syntax.md
Expand Up @@ -503,8 +503,9 @@ not processed, except for Unicode escapes (this is deprecated since 2.13.2).
#### Interpolated string

```ebnf
interpolatedString ::= alphaid ‘"’ {printableChar \ (‘"’ | ‘$’) | escape} ‘"’
| alphaid ‘"""’ {[‘"’] [‘"’] char \ (‘"’ | ‘$’) | escape} {‘"’} ‘"""’
interpolatedString ::= alphaid ‘"’ {[‘\’] interpolatedStringPart | ‘\\’ | ‘\"’} ‘"’
| alphaid ‘"""’ {[‘"’] [‘"’] char \ (‘"’ | ‘$’) | escape} {‘"’} ‘"""’
interpolatedStringPart ::= printableChar \ (‘"’ | ‘$’ | ‘\’) | escape
escape ::= ‘$$’
| ‘$’ id
| ‘$’ BlockExpr
Expand All @@ -513,16 +514,18 @@ alphaid ::= upper idrest
```

An interpolated string consist of an identifier starting with a letter immediately
An interpolated string consists of an identifier starting with a letter immediately
followed by a string literal. There may be no whitespace characters or comments
between the leading identifier and the opening quote `` of the string.
between the leading identifier and the opening quote `"` of the string.
The string literal in an interpolated string can be standard (single quote)
or multi-line (triple quote).

Inside an interpolated string none of the usual escape characters are interpreted
no matter whether the string literal is normal
(enclosed in single quotes) or multi-line (enclosed in triple quotes).
Instead, there are two new forms of dollar sign escape.
no matter whether the string literal is normal (enclosed in single quotes) or
multi-line (enclosed in triple quotes). Note that the sequence `\"` does not
close a normal string literal (enclosed in single quotes).

There are two forms of dollar sign escape.
The most general form encloses an expression in `${` and `}`, i.e. `${expr}`.
The expression enclosed in the braces that follow the leading `$` character is of
syntactical category BlockExpr. Hence, it can contain multiple statements,
Expand Down
4 changes: 3 additions & 1 deletion spec/13-syntax-summary.md
Expand Up @@ -61,8 +61,10 @@ stringElement ::= charNoDoubleQuoteOrNewline
multiLineChars ::= {[‘"’] [‘"’] charNoDoubleQuote} {‘"’}
interpolatedString
::= alphaid ‘"’ {printableChar \ (‘"’ | ‘\$’) | escape} ‘"’
::= alphaid ‘"’ {[‘\’] interpolatedStringPart | ‘\\’ | ‘\"’} ‘"’
| alphaid ‘"""’ {[‘"’] [‘"’] char \ (‘"’ | ‘\$’) | escape} {‘"’} ‘"""’
interpolatedStringPart
::= printableChar \ (‘"’ | ‘$’ | ‘\’) | escape
escape ::= ‘\$\$’
| ‘\$’ id
| ‘\$’ BlockExpr
Expand Down

0 comments on commit 7c81006

Please sign in to comment.