Standardize on only double quotes for string literals

This commit is contained in:
Nick Guerrera 2021-01-25 11:46:23 -08:00
Родитель 74391e4540
Коммит a9e636432a
5 изменённых файлов: 17 добавлений и 57 удалений

Просмотреть файл

@ -478,9 +478,7 @@ export class Scanner {
this.next(Kind.BarEquals, 2) :
this.next(Kind.Bar);
case CharacterCodes.singleQuote:
case CharacterCodes.doubleQuote:
case CharacterCodes.backtick:
return this.scanString();
default:
@ -821,18 +819,12 @@ export class Scanner {
case CharacterCodes.t:
result += '\t';
break;
case CharacterCodes.singleQuote:
result += '\'';
break;
case CharacterCodes.doubleQuote:
result += '"';
break;
case CharacterCodes.backslash:
result += '\\';
break;
case CharacterCodes.backtick:
result += '`';
break;
default:
this.error(messages.InvalidEscapeSequence);
result += String.fromCharCode(ch);

Просмотреть файл

@ -95,36 +95,20 @@ BinaryDigits :
BinaryDigit :
one of `0` `1`
StringLiteral :
`'` SingleStringCharacters? `'`
`"` DoubleStringCharacters? `"`
``` BacktickStringCharacters? ```
// TODO: triple-quoted strings not specified yet, tricky to express.
SingleStringCharacters :
SingleStringCharacter SingleStringCharacters?
StringLiteral :
`"` StringCharacters? `"`
SingleStringCharacter :
SourceCharacter but not one of `'` or `\`
`\` EscapeCharacter
StringCharacters :
StringCharacter StringCharacters?
DoubleStringCharacters :
SingleStringCharacter SingleStringCharacters?
DoubleStringCharacter :
StringCharacter :
SourceCharacter but not one of `"` or `\`
`\` EscapeCharacter
BacktickStringCharacters :
SingleStringCharacter SingleStringCharacters?
BacktickStringCharacter :
SourceCharacter but not one of ``` or `\`
`\` EscapeCharacter
EscapeCharacter :
one of `'` `"` ``` `r` `n` `t` `\`
one of `"` `r` `n` `t` `\`
Punctuator :
one of `|` `:` `,` `;` `.` `<` `>` `(` `)` `{` `}` `[` `]` `@` `...`

Просмотреть файл

@ -90,32 +90,16 @@
&emsp;&emsp;<a name="BinaryDigit"></a>*BinaryDigit* **:** **one of** `` 0 ``&emsp;`` 1 ``
&emsp;&emsp;<a name="StringLiteral"></a>*StringLiteral* **:**
&emsp;&emsp;&emsp;<a name="StringLiteral-82ecb3d9"></a>`` ' ``&emsp;*[SingleStringCharacters](#SingleStringCharacters)*<sub>opt</sub>&emsp;`` ' ``
&emsp;&emsp;&emsp;<a name="StringLiteral-15d8b1f1"></a>`` " ``&emsp;*[DoubleStringCharacters](#DoubleStringCharacters)*<sub>opt</sub>&emsp;`` " ``
&emsp;&emsp;&emsp;<a name="StringLiteral-01e5f820"></a>`` ` ``&emsp;*[BacktickStringCharacters](#BacktickStringCharacters)*<sub>opt</sub>&emsp;`` ` ``
&emsp;&emsp;&emsp;<a name="StringLiteral-557c08bf"></a>`` " ``&emsp;*[StringCharacters](#StringCharacters)*<sub>opt</sub>&emsp;`` " ``
&emsp;&emsp;<a name="SingleStringCharacters"></a>*SingleStringCharacters* **:**
&emsp;&emsp;&emsp;<a name="SingleStringCharacters-17d28457"></a>*[SingleStringCharacter](#SingleStringCharacter)*&emsp;*[SingleStringCharacters](#SingleStringCharacters)*<sub>opt</sub>
&emsp;&emsp;<a name="StringCharacters"></a>*StringCharacters* **:**
&emsp;&emsp;&emsp;<a name="StringCharacters-7568b390"></a>*[StringCharacter](#StringCharacter)*&emsp;*[StringCharacters](#StringCharacters)*<sub>opt</sub>
&emsp;&emsp;<a name="SingleStringCharacter"></a>*SingleStringCharacter* **:**
&emsp;&emsp;&emsp;<a name="SingleStringCharacter-20af69b8"></a>*[SourceCharacter](#SourceCharacter)* **but not** **one of** `` ' `` **or** `` \ ``
&emsp;&emsp;&emsp;<a name="SingleStringCharacter-3b4c2a4a"></a>`` \ ``&emsp;*[EscapeCharacter](#EscapeCharacter)*
&emsp;&emsp;<a name="StringCharacter"></a>*StringCharacter* **:**
&emsp;&emsp;&emsp;<a name="StringCharacter-50b66e4c"></a>*[SourceCharacter](#SourceCharacter)* **but not** **one of** `` " `` **or** `` \ ``
&emsp;&emsp;&emsp;<a name="StringCharacter-3b4c2a4a"></a>`` \ ``&emsp;*[EscapeCharacter](#EscapeCharacter)*
&emsp;&emsp;<a name="DoubleStringCharacters"></a>*DoubleStringCharacters* **:**
&emsp;&emsp;&emsp;<a name="DoubleStringCharacters-17d28457"></a>*[SingleStringCharacter](#SingleStringCharacter)*&emsp;*[SingleStringCharacters](#SingleStringCharacters)*<sub>opt</sub>
&emsp;&emsp;<a name="DoubleStringCharacter"></a>*DoubleStringCharacter* **:**
&emsp;&emsp;&emsp;<a name="DoubleStringCharacter-50b66e4c"></a>*[SourceCharacter](#SourceCharacter)* **but not** **one of** `` " `` **or** `` \ ``
&emsp;&emsp;&emsp;<a name="DoubleStringCharacter-3b4c2a4a"></a>`` \ ``&emsp;*[EscapeCharacter](#EscapeCharacter)*
&emsp;&emsp;<a name="BacktickStringCharacters"></a>*BacktickStringCharacters* **:**
&emsp;&emsp;&emsp;<a name="BacktickStringCharacters-17d28457"></a>*[SingleStringCharacter](#SingleStringCharacter)*&emsp;*[SingleStringCharacters](#SingleStringCharacters)*<sub>opt</sub>
&emsp;&emsp;<a name="BacktickStringCharacter"></a>*BacktickStringCharacter* **:**
&emsp;&emsp;&emsp;<a name="BacktickStringCharacter-4610ad0d"></a>*[SourceCharacter](#SourceCharacter)* **but not** **one of** `` ` `` **or** `` \ ``
&emsp;&emsp;&emsp;<a name="BacktickStringCharacter-3b4c2a4a"></a>`` \ ``&emsp;*[EscapeCharacter](#EscapeCharacter)*
&emsp;&emsp;<a name="EscapeCharacter"></a>*EscapeCharacter* **:** **one of** `` ' ``&emsp;`` " ``&emsp;`` ` ``&emsp;`` r ``&emsp;`` n ``&emsp;`` t ``&emsp;`` \ ``
&emsp;&emsp;<a name="EscapeCharacter"></a>*EscapeCharacter* **:** **one of** `` " ``&emsp;`` r ``&emsp;`` n ``&emsp;`` t ``&emsp;`` \ ``
&emsp;&emsp;<a name="Punctuator"></a>*Punctuator* **:** **one of** `` | ``&emsp;`` : ``&emsp;`` , ``&emsp;`` ; ``&emsp;`` . ``&emsp;`` < ``&emsp;`` > ``&emsp;`` ( ``&emsp;`` ) ``&emsp;`` { ``&emsp;`` } ``&emsp;`` [ ``&emsp;`` ] ``&emsp;`` @ ``&emsp;`` ... ``

Просмотреть файл

@ -48,7 +48,7 @@ describe('syntax', () => {
// parses as if it were `@foo('prop-1') : number`
`model Car {
@foo()
'prop-1': number;
"prop-1": number;
}`,
`

Просмотреть файл

@ -149,13 +149,13 @@ describe('scanner', () => {
it('scans strings single-line strings with escape sequences', () => {
scanString(
'"Hello world \\r\\n \\t \\\' \\" \\` \\\\ !"',
'Hello world \r\n \t \' " ` \\ !');
'"Hello world \\r\\n \\t \\" \\\\ !"',
'Hello world \r\n \t " \\ !');
});
it('scans multi-line strings', () => {
scanString(
'`More\r\nthan\r\none\r\nline`',
'"More\r\nthan\r\none\r\nline"',
'More\nthan\none\nline');
});