"where both a division and a RegularExpressionLiteral are permitted"
a = a /a/
this will cause syntax error instead of
a = a; /a/
,
Eric Suen
----- Original Message ---
Eric Suen wrote:
a = a /a/
this will cause syntax error instead of
a = a; /a/
Yes, it will. Are you saying that this is a counterexample? AFAICS it is not: in this example there is no context where both a DivisionPunctuator and a RegularExpressionLiteral are permitted as the next token.
Note that the first '/' is in a context where a division is permitted (and a RegularExpressionLiteral is not). Therefore there is no possibility of a semicolon being inserted there, since there is no syntax error at that point. (In fact this is precisely the kind of example that was covered by the last part of note [*1] in my previous post.)
At the risk of belabouring this point, semicolon insertion never involves backtracking (and thank foo for that; it's complicated enough without it). If some prefix of the token stream, in this case
a = a /
could be extended with any suffix to make a syntactically valid stream (for example, 'a = a / 1 ;'), then no semicolon will be inserted before the end of that prefix, even if there is a syntax error later in the actual token stream. This is an implicit consequence of the wording "as the program is parsed from left to right" in section 7.9.1.
Section 7 (Lexical Conventions):
Note that contexts exist in the syntactic grammar where both a division
and a RegularExpressionLiteral are permitted by the syntactic grammar;
[...]
I believe this statement is incorrect [*1]. If I'm wrong, what is an example of such a context?
[*1] A DivisionPunctuator must be preceded by an expression. A RegularExpressionLiteral is itself an expression. Therefore, for there to exist syntactic contexts in which either a DivisionPunctuator or a RegularExpressionLiteral could occur, it would have to be possible for an expression to immediately follow [*2] another expression with no intervening operator. The only case in which that can occur is where a semicolon is automatically inserted between the two expressions. Assume that case: then the second expression cannot begin with [*2] a token whose first character is '/', because that would have been interpreted as a DivisionPunctuator, and so no semicolon insertion would have occurred (because semicolon insertion only occurs where there would otherwise have been a syntax error); contradiction.
[*2] Ignoring comments and whitespace.