ECMAScript 2017:为什么 EscapeSequence 包含 NonEscapeCharacter?

ECMAScript 2017: Why does EscapeSequence include NonEscapeCharacter?

以下摘录参考ECMAScript 2017.

11.8.4 字符串文字,注释 1

A string literal is zero or more Unicode code points enclosed in single or double quotes. Unicode code points may also be represented by an escape sequence. .... Any code points may appear in the form of an escape sequence.

11.8.4 字符串文字,语法

非终结符号EscapeSequence具有以下词法语法产生式:

EscapeSequence ::
    CharacterEscapeSequence
    0 [lookahead ∉ DecimalDigit]
    HexEscapeSequence
    UnicodeEscapeSequence

非终结符号CharacterEscapeSequence具有以下词法语法产生式:

CharacterEscapeSequence ::
    SingleEscapeCharacter
    NonEscapeCharacter

11.8.4.3 静态语义:SV

包含如下描述:

The SV of DoubleStringCharacter :: \ EscapeSequence is the SV of the EscapeSequence

问题

  1. 注1中的escape sequence是什么意思?试图了解转义序列的实际作用,而不仅仅是它的词汇语法
  2. 为什么 CharacterEscapeSequence 包括 NonEscapeCharacter
  3. 11.8.4.3 Static Semantics: SV 中的描述似乎没有遵循词法语法产品的正常 ECMAScript 约定。这些描述是什么意思?
  4. 添加的问题:注释 1 是否声明代码点可以在引号内或在转义序列(例如反斜杠)之后? Any code points may appear in the form of an escape sequence是这个意思吗?
  1. What is meant by escape sequence in Note 1?

    下一个问题的EscapeSequence

  2. Why does CharacterEscapeSequence include NonEscapeCharacter?

    因为无效的转义只是忽略了它们的反斜杠——例如,'\c' === 'c'。不能破坏向后兼容性。

  3. 11.8.4.3 Static Semantics: SV contains descriptions such as “The SV of DoubleStringCharacter :: \ EscapeSequence is the SV of the EscapeSequence”. Those lines do not follow the normal ECMAScript convention for lexical grammar productions. What is meant by those descriptions?

    意思是你应该参考EscapeSequence对应的同一节中的规则。例如,如果您有 "\x20"\x20 将是一个由 \ 和 EscapeSequence x20 组成的 DoubleStringCharacter,后者又是一个 HexEscapeSequence x HexDigit HexDigit,其SV由

    给出

    The SV of HexEscapeSequence :: x HexDigit HexDigit is the code unit value that is (16 times the MV of the first HexDigit) plus the MV of the second HexDigit.