Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correction to the ASI generation #18

Merged
merged 3 commits into from
Aug 7, 2018

Conversation

metatoaster
Copy link
Member

Turns out the production rules in the parser relating to ASI (with auto_semi) were implemented incorrectly. The correct way is to create a specific token for this purpose and update those production rules to consume this token, so that no incorrect production from the confusion of this generated token versus the actual tokens can occur. Through this the actual generation relating to this can be cleaned up and the hack that stops the infinite loop for the ASI generation may be removed. Also this means that the incorrect production of statements that require a semi-colon will no longer occur (e.g. (function(){if (true)}); should now result in a parsing error).

This fixes rspivak/slimit#29 for real and rspivak/slimit#101.

- Drop the extraneous auto_semi rule, as it turns out that rule is
  **never** hit due to it being effectively replicates the unmatched
  production condition (through auto_semi then error).
- However, on the case where the SEMI is produced through the error
  handler after an error condition that is actually an error, if the
  production stack is just that freshly generated SEMI, it will be
  immediately consumed and used by the empty_statement production rule,
  then the previously erroring token is yielded again, restarting the
  cycle thus that's the real cause behind the infinite loop as reported
  in rspivak/slimit#29.
- However, if the auto generated SEMI tokens are correctly marked, and
  update the existing rules to make use of that token, the immediate
  consumption of the token cannot happen if an empty statement does NOT
  include the auto generated SEMI token (which has been done by creating
  a new AUTOSEMI token type), the condition which the immediate
  consumption of a token to result in the error token can no longer
  occur.
- Removed the seen before token hack.
- Moved all the conditions for which AUTOSEMI token is generated to the
  lexer auto_semi method.
- This also completely eliminates the incorrect production of statements
  that only has SEMIs but not the ASI equivalent, such as the case with
  ``if`` or ``for`` statements as per 7.9.2 of the ECMA-262 5.1 spec,
  which is reported in rspivak/slimit#101.
- Also include a reference to the previous fix.
@metatoaster metatoaster added this to the 1.1.0 milestone Aug 7, 2018
@metatoaster metatoaster merged commit feb4bbc into calmjs:master Aug 7, 2018
@metatoaster metatoaster added the bug label Aug 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid semicolon causes infinite loop
1 participant