- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图理解字符串文字到最终字符串值(由代码单元值组成)的翻译,遵循 ECMAScript 2017 .
相关摘录
5.1.2 词法和正则表达式语法
A lexical grammar for ECMAScript is given in clause 11. This grammar has as its terminal symbols Unicode code points that conform to the rules for SourceCharacter defined in 10.1. It defines a set of productions, starting from the goal symbol InputElementDiv, InputElementTemplateTail, or InputElementRegExp, or InputElementRegExpOrTemplateTail, that describe how sequences of such code points are translated into a sequence of input elements.
Input elements other than white space and comments form the terminal symbols for the syntactic grammar for ECMAScript and are called ECMAScript tokens. These tokens are the reserved words, identifiers, literals, and punctuators of the ECMAScript language.
When a stream of code points is to be parsed as an ECMAScript Script or Module, it is first converted to a stream of input elements by repeated application of the lexical grammar; this stream of input elements is then parsed by a single application of the syntactic grammar.
The source text of an ECMAScript Script or Module is first converted into a sequence of input elements, which are tokens, line terminators, comments, or white space. The source text is scanned from left to right, repeatedly taking the longest possible sequence of code points as the next input element.
StringLiteral ::
" DoubleStringCharacters_opt "
' SingleStringCharacters_opt '
SingleStringCharacters ::
SingleStringCharacter SingleStringCharacters_opt
SingleStringCharacter ::
SourceCharacter but not one of ' or \ or LineTerminator
\ EscapeSequence
LineContinuation
EscapeSequence ::
CharacterEscapeSequence
0 [lookahead ∉ DecimalDigit]
HexEscapeSequence
UnicodeEscapeSequence
CharacterEscapeSequence ::
SingleEscapeCharacter
NonEscapeCharacter
NonEscapeCharacter ::
SourceCharacter but not one of EscapeCharacter or LineTerminator
EscapeCharacter ::
SingleEscapeCharacter
DecimalDigit
x
u
A string literal stands for a value of the String type. The String value (SV) of the literal is described in terms of code unit values contributed by the various parts of the string literal.
The SV of SingleStringCharacter :: SourceCharacter but not one of ' or \ or LineTerminator is the UTF16Encoding of the code point value of SourceCharacter.
The SV of SingleStringCharacter :: \ EscapeSequence is the SV of the EscapeSequence.
'b\ar'
.我现在想按照上面的词汇语法和语义语法,把字符串文字变成一组代码单元值。
b\ar
被识别为 CommonToken b\ar
被进一步识别为 StringLiteral \
的 SingleStringCharacter infront 被翻译成 SourceCharacter \a
被识别为\EscapeSequence any Unicode code point
SourceCharacter, \ SourceCharacter, SourceCharacter
最佳答案
好吧,假设我们使用单个 token 'b\ar'
,也就是你所说的 StringLiteral
token 。应用 11.8.4.3 Static Semantics: SV 中定义的算法以及 10.1.1 Static Semantics: UTF16Encoding(cp) ,我们关注SV
规则:
StringLiteral::
的 SV '
SingleStringCharacters
'
是 SV
的 SingleStringCharacters
.SV
,因此打开引号就在SingleStringCharacters
部分,例如SV(b\ar)
SV
的 SingleStringCharacters::
SingleStringCharacterSingleStringCharacters
是一个或两个代码单元的序列,即 SV
的 SingleStringCharacter
后跟 SV
中的所有代码单元的 SingleStringCharacters
为了。SingleStringCharacter
调用 SV| 附加结果”。SV(b)
SV
的 SingleStringCharacter::
SourceCharacter
但不是 '
之一或 \
或 LineTerminator
是 UTF16Encoding
SourceCharacter
的码位值.\x0062
所以这里的结果本质上是一个16位单元的代码单元序列\x0062
SV(\a)
SV
的 SingleStringCharacter::
\
EscapeSequence
是 SV
的EscapeSequence
.SV(EscapeSequence)
这个SV(a)
(无 \
前缀)SV
的 EscapeSequence::
CharacterEscapeSequence
是 SV
的CharacterEscapeSequence
.SV(a)
SV
的 CharacterEscapeSequence::
NonEscapeCharacter
是 SV
的NonEscapeCharacter
.SV
的 NonEscapeCharacter::
SourceCharacter
但不是 EscapeCharacter
之一或 LineTerminator
是 UTF16Encoding
SourceCharacter 的代码点值。\x0061
, 所以这会产生一个只有 \x0061
的单单元序列. SV(r)
SV(b)
相同的步骤这会产生一个包含 \x0072
的单单元序列。 . SV(b) + SV(\a) + SV(r)
回到一起,字符串的值是 UTF16 代码单元的序列 [\x0062, \x0061, \x0072]
.该代码单元序列导致bar
. I though we should first apply the lexical grammar and end up with tokens, and then subsequently apply the SV rules?
StringLiteral
,其中的所有内容都只是有关如何解析的信息。
EscapeSequence
不是一种 token 。
SV
定义如何将 StringLiteral 标记分解为一系列代码单元。
The source text of an ECMAScript Script or Module is first converted into a sequence of input elements, which are tokens, line terminators, comments, or white space. The source text is scanned from left to right, repeatedly taking the longest possible sequence of code points as the next input element.
Assuming the order of events is right, my second questions is around SV(\a). The first escape sequence rule is applied and we are left with SV(a), which should follow the same path as SV(b) no?
SV
的 SingleStringCharacter::
\
EscapeSequence
是 SV
的EscapeSequence
. SV
的 EscapeSequence::
CharacterEscapeSequence
是 SV
的CharacterEscapeSequence
. SV
的 CharacterEscapeSequence::
NonEscapeCharacter
是 SV
的NonEscapeCharacter
. SV
的 NonEscapeCharacter::
SourceCharacter
但不是 EscapeCharacter
之一或 LineTerminator
是 UTF16Encoding
SourceCharacter 的代码点值。 function SV(parts: ["\", EscapeSequence]) {
return SV(parts[1]);
}
function SV(parts: [CharacterEscapeSequence]) {
return SV(parts[0]);
}
function SV(parts: [NonEscapeCharacter]) {
return SV(parts[0]);
}
function SV(parts: [SourceCharacter]) {
return UTF16Encoding(parts[0]);
}
SV(a)
有点像
SV("a": [CharacterEscapeSequence])
而
SV(b)
有不同的类型。
关于javascript - ECMAScript 2017 : Parsing from nonterminal StringLiteral to String values,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49641927/
我正在尝试为我的组件中声明的数组分配一个值。不幸的是,抛出了异常。 TypeError: Attempted to assign to readonly property 即使我删除了严格模式,仍然会
如果我将一个类导入到其他脚本中,我如何将参数传递给 ES6 语法中的类构造函数? 我想做这样的事情。我已经看到了各种建议,例如包装函数或使用工厂模式,但是否有更简洁、更简单的方法来做到这一点? //
我最近看了 ECMAScript 2015。 ECMAScript 2015 有类初始化器吗? 例如,我试着把类写得像一个解析器; class URLParser { parse(url) {
我目前正在尝试弄清楚为什么 JSDT 会发布类似“JavaScript error on valid regex”的错误'. 在我进行测试时,我意识到它适用于像这样的简单文件: var a = {
有一段时间我认为它们是同一回事,但我经常看到博客或此处的答案中的措辞似乎暗示两者之间存在差异。即使 SO 有两个不同的标签,但它们的描述并没有显示出任何明显的区别。 我四处搜索了一下,这只会增加困惑,
我最近使用了最新的 Laravel 5.3。在 gulp.js文件,有较新的 ES6 箭头函数语法: elixir(mix => { mix.sass('app.scss') .
在 block 作用域函数方面,ES6 相对于 ES5 有哪些优势?我的意思是,在这两种情况下,该 block 看起来非常相似,那么它有什么区别,性能方面哪种方法更好? ES6 block {
所以,我知道在 GWT 中我可以编写纯 javascript 代码的 JSNI 代码。但是,不幸的是,如果我在其中使用 ES6 代码,JSNI 代码将无法编译。 这意味着,例如,我不能做这样的事情:
所以,我知道在 GWT 中我可以编写纯 javascript 代码的 JSNI 代码。但是,不幸的是,如果我在其中使用 ES6 代码,JSNI 代码将无法编译。 这意味着,例如,我不能做这样的事情:
如何在 Visual Studio Code 中编写 ECMAScript 代码??我尝试编写 jsconfig.json 但不确定如何运行该文件。我什至尝试更改 tasks.json 但即使那样也无
尽管事实是const不能在 ECMAScript 2015 中赋值,如果对象没有被卡住,可以修改 Object.freeze . 自 const应该是不可变的,添加 Object.freeze 有意义
当我打开我的项目 .js 文件时,会出现以下警告: File watcher 'Babel' is available for this file. Description: 'Transpiles
我接受了 JavaScript 前端开发人员职位的面试。我失败了,因为我不知道一些高级问题。请帮助我至少理解这一点。 我的问题在于 ECMAScript 6 知识,而不是 ECMAScript 5 中
本文介绍ECMAScript 6即将带给我们新的数组操作方法,以及在怎样在现有浏览器应用这些新的数组特性。 Note: 我将使用交替使用构造器(constructor)和类(class)两个术语。
我指的是 https://tc39.es/ecma262/#sec-regexp-regular-expression-objects 中定义的 ECMAScript 正则表达式语法. 我通过几个在线
我有多个名为 PageX 的文件, PageY , PageZ等等 每一个都有一个 export default SETUP { path:'blah_X', component:X } . 在我的
也许这是一个基本问题,但是两者之间有什么区别: -在ES3支持下开发的一个Web项目, -在ES5支持下开发的Web项目? 换句话说,如果您支持ES5,则可以在项目中添加哪些增强功能? 最佳答案 在这
这个问题在这里已经有了答案: One-liner to take some properties from object in ES 6 (12 个答案) 关闭 6 年前。 是否有一个我正在空白的单
一段时间以来,我一直在使用 ES6 提供的模块。虽然我(本能地)知道最好使用它们,但我很难解释为什么。 带模块; 我可以做依赖声明(不是注入(inject))。我不必为我加载的每个 javascrip
从不可变映射中获取多个值的最佳方法是什么? const example = new Map({ id: 1, first: 'John', last: 'Smith',
我是一名优秀的程序员,十分优秀!