ECMAScript 2017:为什么EscapeSequence包含NonEscapeCharacter? [英] ECMAScript 2017: Why does EscapeSequence include NonEscapeCharacter?

查看:112
本文介绍了ECMAScript 2017:为什么EscapeSequence包含NonEscapeCharacter?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下摘录引用了 ECMAScript 2017 .

11.8.4字符串文字,注释1

字符串文字是零或多个包含在其中的Unicode代码点 单引号或双引号. Unicode代码点也可以表示 通过转义序列. ....任何代码点都可能以转义序列的形式出现.

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具有以下词汇语法产生形式:

Nonterminal symbol EscapeSequence has the following lexical grammar production:

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

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

Nonterminal symbol CharacterEscapeSequence has the following lexical grammar production:

CharacterEscapeSequence ::
    SingleEscapeCharacter
    NonEscapeCharacter

11.8.4.3静态语义:SV

包含以下描述:

DoubleStringCharacter的SV :: EscapeSequence是 转义序列

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

问题

  1. 注释1中的escape sequence是什么意思?试图了解转义序列实际上是做什么的,而不仅仅是理解其词法语法
  2. 为什么CharacterEscapeSequence包含NonEscapeCharacter?
  3. 11.8中的描述. 4.3静态语义: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? Trying to understand what an escape sequence actually does, rather than just the lexical grammar for it
  2. Why does CharacterEscapeSequence include NonEscapeCharacter?
  3. The descriptions in 11.8.4.3 Static Semantics: SV do not seem to follow the normal ECMAScript convention for lexical grammar productions. What is meant by those descriptions?
  4. Added question: Does Note 1 state that code points can be within quotes or alternatively after an escape sequence (such as backslash)? Is that what is meant by Any code points may appear in the form of an escape sequence?

推荐答案

注释1中的转义序列是什么意思?

您下一个问题中的EscapeSequence.

为什么CharacterEscapeSequence包含NonEscapeCharacter?

Why does CharacterEscapeSequence include NonEscapeCharacter?

因为无效的转义符只会忽略其反斜杠-例如,'\c' === 'c'.向后兼容性不可破坏.

Because invalid escapes just have their backslash ignored – for example, '\c' === 'c'. Backwards compatibility can't be broken.

11.8.4.3静态语义:SV包含诸如"DoubleStringCharacter :: \ EscapeSequence的SV是EscapeSequence的SV"之类的描述.这些行不遵循词汇语法产生的常规ECMAScript约定.这些描述是什么意思?

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由

It means that you should refer to the rule in the same section corresponding to the EscapeSequence. For example, if you had "\x20", the \x20 would be a DoubleStringCharacter consisting of \ and the EscapeSequence x20, which in turn is a HexEscapeSequence x HexDigit HexDigit, whose SV is given by

HexEscapeSequence :: x HexDigit HexDigit的SV是代码单位值(是第一个HexDigit的MV的16倍)加上第二个HexDigit的MV.

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.

这篇关于ECMAScript 2017:为什么EscapeSequence包含NonEscapeCharacter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆