Standardize on only double quotes for string literals
This commit is contained in:
Родитель
74391e4540
Коммит
a9e636432a
|
@ -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 @@
|
|||
  <a name="BinaryDigit"></a>*BinaryDigit* **:** **one of** `` 0 `` `` 1 ``
|
||||
|
||||
  <a name="StringLiteral"></a>*StringLiteral* **:**
|
||||
   <a name="StringLiteral-82ecb3d9"></a>`` ' `` *[SingleStringCharacters](#SingleStringCharacters)*<sub>opt</sub> `` ' ``
|
||||
   <a name="StringLiteral-15d8b1f1"></a>`` " `` *[DoubleStringCharacters](#DoubleStringCharacters)*<sub>opt</sub> `` " ``
|
||||
   <a name="StringLiteral-01e5f820"></a>`` ` `` *[BacktickStringCharacters](#BacktickStringCharacters)*<sub>opt</sub> `` ` ``
|
||||
   <a name="StringLiteral-557c08bf"></a>`` " `` *[StringCharacters](#StringCharacters)*<sub>opt</sub> `` " ``
|
||||
|
||||
  <a name="SingleStringCharacters"></a>*SingleStringCharacters* **:**
|
||||
   <a name="SingleStringCharacters-17d28457"></a>*[SingleStringCharacter](#SingleStringCharacter)* *[SingleStringCharacters](#SingleStringCharacters)*<sub>opt</sub>
|
||||
  <a name="StringCharacters"></a>*StringCharacters* **:**
|
||||
   <a name="StringCharacters-7568b390"></a>*[StringCharacter](#StringCharacter)* *[StringCharacters](#StringCharacters)*<sub>opt</sub>
|
||||
|
||||
  <a name="SingleStringCharacter"></a>*SingleStringCharacter* **:**
|
||||
   <a name="SingleStringCharacter-20af69b8"></a>*[SourceCharacter](#SourceCharacter)* **but not** **one of** `` ' `` **or** `` \ ``
|
||||
   <a name="SingleStringCharacter-3b4c2a4a"></a>`` \ `` *[EscapeCharacter](#EscapeCharacter)*
|
||||
  <a name="StringCharacter"></a>*StringCharacter* **:**
|
||||
   <a name="StringCharacter-50b66e4c"></a>*[SourceCharacter](#SourceCharacter)* **but not** **one of** `` " `` **or** `` \ ``
|
||||
   <a name="StringCharacter-3b4c2a4a"></a>`` \ `` *[EscapeCharacter](#EscapeCharacter)*
|
||||
|
||||
  <a name="DoubleStringCharacters"></a>*DoubleStringCharacters* **:**
|
||||
   <a name="DoubleStringCharacters-17d28457"></a>*[SingleStringCharacter](#SingleStringCharacter)* *[SingleStringCharacters](#SingleStringCharacters)*<sub>opt</sub>
|
||||
|
||||
  <a name="DoubleStringCharacter"></a>*DoubleStringCharacter* **:**
|
||||
   <a name="DoubleStringCharacter-50b66e4c"></a>*[SourceCharacter](#SourceCharacter)* **but not** **one of** `` " `` **or** `` \ ``
|
||||
   <a name="DoubleStringCharacter-3b4c2a4a"></a>`` \ `` *[EscapeCharacter](#EscapeCharacter)*
|
||||
|
||||
  <a name="BacktickStringCharacters"></a>*BacktickStringCharacters* **:**
|
||||
   <a name="BacktickStringCharacters-17d28457"></a>*[SingleStringCharacter](#SingleStringCharacter)* *[SingleStringCharacters](#SingleStringCharacters)*<sub>opt</sub>
|
||||
|
||||
  <a name="BacktickStringCharacter"></a>*BacktickStringCharacter* **:**
|
||||
   <a name="BacktickStringCharacter-4610ad0d"></a>*[SourceCharacter](#SourceCharacter)* **but not** **one of** `` ` `` **or** `` \ ``
|
||||
   <a name="BacktickStringCharacter-3b4c2a4a"></a>`` \ `` *[EscapeCharacter](#EscapeCharacter)*
|
||||
|
||||
  <a name="EscapeCharacter"></a>*EscapeCharacter* **:** **one of** `` ' `` `` " `` `` ` `` `` r `` `` n `` `` t `` `` \ ``
|
||||
  <a name="EscapeCharacter"></a>*EscapeCharacter* **:** **one of** `` " `` `` r `` `` n `` `` t `` `` \ ``
|
||||
|
||||
  <a name="Punctuator"></a>*Punctuator* **:** **one of** `` | `` `` : `` `` , `` `` ; `` `` . `` `` < `` `` > `` `` ( `` `` ) `` `` { `` `` } `` `` [ `` `` ] `` `` @ `` `` ... ``
|
||||
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче