Directive prologue members, escapes, and retroactive syntax errors

Jeff Walden jwalden+es at MIT.EDU
Fri Oct 15 11:35:22 PDT 2010

On 10/15/2010 01:10 AM, Peter van der Zee wrote:
> The parser can simply tell the lexer whether it wants a
> token in strict mode or not. In that case the parser,
> which should know it's parsing a DirectivePrologue,
> could just turn off the strict flag in the request.

So you suggest the tokenizer should have two modes of operation, one to get a token using strict mode parsing and one to get it using normal parsing?  This is plausible, if introduced in combination with ignoring directives for the purpose of octal character escapes.  (Of course, if you didn't do that, you still have the original problem that precipitated this discussion.)

> Because the parser can clearly tell the difference
> between parsing a DirectivePrologue and a StringLiteral.
> So it can be told that whenever it's parsing a
> DirectivePrologue the strict flag should be considered
> to be false. Cases like `"a"+b` don't really apply for
> me (since they're simply not a DirectivePrologue), but I
> don't know how other parsers would handle them...

The point was that the parser can't tell the difference until it's moved past the string literal in question and processed an entire ExpressionStatement.  (And if it's not an ExpressionStatement, you need to "step backward" and detect that case.)  So again, you have to save octal-ness and check it later, which is much of my concern.  It is much simpler to make the decision to produce a syntax error when the octal escape is encountered than to defer it for later.


More information about the es5-discuss mailing list