有人知道 ECMAScript for XML(E4X;ECMA-357 2º 版)并阅读过它的规范吗?弃用了,我知道。要开始我的问题,请让我先指出一些事情:
E4X 允许像 <x/>
这样的表达式,从而扩展 PrimaryExpression
与 XMLInitialiser | XMLListInitialiser
制作。
但是,他们说:
The syntactic grammar for XML initialisers processes input elements produced by the lexical grammar goal symbols InputElementXMLTag and InputElementXMLContent. These input elements are described in section 8.3.
(对于 XML 列表也是如此。)
所以,不是 XMLInitialiser
还应该处理 InputElementRegExp
?规范试图拒绝这一点。请检查这些定义:
XMLInitialiser
:
-
XMLMarkup
-
XMLElement
XMLElement
:
- <
XMLTagContent
XMLWhitespace
选择 />
还有,
InputElementXMLContent
::
- 还有更多...
它们都使 < 可用,但是如何解析其他需要 InputElementRegExp
的表达式? ?
最佳答案
So, isn't XMLInitialiser supposed to also process InputElementRegExp?
是的,XMLInitialiser
(或 XMLListInitialiser
)会消耗 XMLMarkup
InputElementRegExp
匹配的元素.
The specification tries to reject that.
怎么会这样?
They all make < available, but then how would one parse other expressions that need InputElementRegExp? [In comment:] ... it'd cause a conflict for scanning an
InputElementRegExp
as well as anInputElementXMLContent
, this is because the<
symbol comes first inXMLInitialiser
orXMLListInitialiser
.
如果您说 InputElementRegExp
之间存在冲突和 InputElementXMLContent
因为它们都派生出“<”:不,这不是冲突,因为这两个符号永远不会在输入中的同一点使用。见第 8 节第三段:
“InputElementXMLContent
用于那些允许 XML 元素的文字内容的句法上下文。InputElementRegExp
符号用于所有其他句法语法上下文。”
也就是说,在任何给定的句法上下文中,应该只使用一个词汇目标符号 (InputElementSomething
)。
另一方面,如果您说 XMLInitiliser
之间存在冲突和 XMLListInitialiser
因为他们都派生出以 <
开头的句子: 嗯,是的,这对 LL(1) 解析器来说是个问题,但我相信 LL(2) 或 LR(1) 解析器可以处理它。
I believe the < production in the InputElementXMLContent was a mistake.
我不这么认为。考虑这个例子 <A><B/></A>
.在<A>
之后, 句法解析器期待 XMLElementContent
或 </
,这意味着词法分析器必须使用 InputElementXMLContent
作为目标符号。所以后者必须能够匹配<
为了使此解析成功。
[from comment:]
XMLElement
starts with a<
terminal and may nest other elements, thus, it should beInputElementRegExp
IMO.
再次参见第 8 节。我上面引用的两个句子表明,在看到 <A>
之后, 你必须使用 InputElementXMLContent
获取下一个输入元素。
关于javascript - E4X规范有误吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47003302/