如何在这里实现JavaScript / ECMAScript“no LineTerminator” JavaCC中的规则? [英] How to implement JavaScript/ECMAScript "no LineTerminator here" rule in JavaCC?
问题描述
我继续处理我的 ECMAScript 5.1 的JavaCC语法。它实际上相当顺利,我想我现在已经涵盖了大部分表达式。
I continue working on my JavaCC grammar for ECMAScript 5.1. It actually goes quite well, I think I've covered most of the expressions now.
我现在有两个问题,它们都与自动分号插入有关( §7.9.1)。这是其中之一。
I have now two questions, both of them are related to the automatic semicolon insertion (§7.9.1). This is one of them.
规范定义了以下产品:
PostfixExpression :
LeftHandSideExpression
LeftHandSideExpression [no LineTerminator here] ++
LeftHandSideExpression [no LineTerminator here] --
如何在这里实施可靠的禁止LineTerminator检查?
记录我的 LINE_TERMINATOR
目前是这样的:
For the record my LINE_TERMINATOR
is at the moment something like:
SPECIAL_TOKEN :
{
<LINE_TERMINATOR: <LF> | <CR> | <LS> | <PS> >
| < #LF: "\n" > /* Line Feed */
| < #CR: "\r" > /* Carriage Return */
| < #LS: "\u2028" > /* Line separator */
| < #PS: "\u2029" > /* Paragraph separator */
}
我读过词汇状态,但我不确定这是不是是一个正确的方向。我已经检查了一些我找到的其他JavaScript语法,但没有找到任何类似的规则。 (当我试图从这些语法中取代某些东西时,我实际上觉得自己是总货物祸害。)
I have read about lexical states, but I am not sure if this is a right direction. I've checked a few other JavaScript grammars I have found, but did not find any similar rules there. (I actually feel myself a total cargo culter when I try to overtake something from these grammars.)
我很感激指针,提示或只是正确搜索方向的关键字。
I'd be grateful for a pointer, a hint or just a keyword for the right search direction.
推荐答案
我认为对于限制性制作你可以这样做
I think for the "restricted productions" you can do this
void PostfixExpression() :
{} {
LeftHandSideExpression()
(
LOOKAHEAD( "++", {getToken(0).beginLine == getToken(1).beginLine})
"++"
|
LOOKAHEAD( "--", {getToken(0).beginLine == getToken(1).beginLine})
"--"
|
{}
)
}
这篇关于如何在这里实现JavaScript / ECMAScript“no LineTerminator” JavaCC中的规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!