Hi Thomas,
thanks for your reply and poiting out section 7.
Thomas 'PointedEars' Lahn wrote:
However, to spare you the search here, the InputElementRegExp goal symbol
which this boils down to is orphaned in the grammar, indeed. *Section 7,
"Lexical Conventions", appears to explain why; it also points out that a
standalone RegExp literal is not safe per se (which I found rather
surprising, but it does make sense).
To my view, it's not really orphaned. In that sense InputElementDiv
would be orphaned, too. Section 7, that you are referring to, explains
that both symbols are used as goal symbols during the lexical analysis
depending on the context; the context being defined by the
*syntactical* grammar. InputElementDiv in cases where a division
punctuator is allowed and expected, InputElementRegExp for the
remaining cases.
We have a production from InputElementRegExp to
RegularExpressionLiteral for the lexical analysis. So in the lexical
analysis, regular expressions are detected and properly tokenized. But
the RegularExpressionLiteral symbol is only used for the lexical
analysis. There is no direct way of producing anything equivalent to
the RegularExpressionLiteral when using the syntactical grammar. What
comes closest in the syntactical grammar would be what is described in
A.7 Regular Expressions, more precisely the Pattern symbol. However,
in the syntactical grammar, we don't have a production that would get
us to Pattern. Also, thanks to your help, I'm seeing it a bit more
clearly now. My earlier question pointed at
>"7.8.5 RegularExpressionLiterals
A regular expression literal is an input element that is converted to
a RegExp object (section 15.10) when it is scanned."
This clause would according to my understanding still be the only way
to explain how we can have regular expressions in the syntactical
analysis, and that is - by replacing them with something else. If we
assume that /...someRegExp.../ gets converted to
new RegExp("...someRegExp...")
then we can get from
CallExpression
to
MemberExpression
, then to
new MemberExpression Arguments
which matches
new Regexp("...someRegExp...")
(I know, the top down approach again, hope you bear with me. I'm using
it just for the purpose of explaining my point)
To conclude, 7.8.5 seems to me the only way to explain that the
initial example
if (1) /a/.test("a");
is valid according to the ECMAScript grammar. Or in other words,
during the lexical analysis, after the closing bracket of the if
statement, the scanner must be in a mode where it's looking to fulfil
a InputElementRegExp goal symbol.
Again, thank you for giving some important clues that helped me to
understand this issue,
best regards,
Dominik