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

bpo-42997: Improve error message for missing : before suites #24292

Merged
merged 10 commits into from Feb 2, 2021

Conversation

@pablogsal
Copy link
Member

@pablogsal pablogsal commented Jan 22, 2021

  • Add to the peg generator a new directive ('&&') that allows to expect
    a token and hard fail the parsing if the token is not found. This
    allows to quickly emit syntax errors for missing tokens.

  • Use the new grammar element to hard-fail if the ':' is missing before
    suites.

See #24293 for a simpler (but more verbose) approach

https://bugs.python.org/issue42997

Copy link
Contributor

@lysnikolaou lysnikolaou left a comment

Some nitpicking here and there. Feel free to ignore.

Parser/pegen.c Outdated Show resolved Hide resolved
Tools/peg_generator/pegen/c_generator.py Outdated Show resolved Hide resolved
Tools/peg_generator/pegen/c_generator.py Outdated Show resolved Hide resolved
Grammar/python.gram Outdated Show resolved Hide resolved
Grammar/python.gram Outdated Show resolved Hide resolved
@pablogsal pablogsal requested a review from lysnikolaou Jan 28, 2021
@pablogsal pablogsal marked this pull request as ready for review Jan 31, 2021
pablogsal and others added 4 commits Jan 22, 2021
* Add to the peg generator a new directive ('&&') that allows to expect
  a token and hard fail the parsing if the token is not found. This
  allows to quickly emmit syntax errors for missing tokens.

* Use the new grammar element to hard-fail if the ':' is missing before
  suites.
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
@pablogsal pablogsal force-pushed the pablogsal:bpo-42997 branch from b6f866a to 9ff270a Jan 31, 2021
@pablogsal
Copy link
Member Author

@pablogsal pablogsal commented Jan 31, 2021

I have added a new section to the highlighting code in the grammar docs so the new symbol do not appear

@pablogsal pablogsal requested a review from gvanrossum Jan 31, 2021
Lib/test/test_syntax.py Outdated Show resolved Hide resolved
Tools/peg_generator/pegen/c_generator.py Outdated Show resolved Hide resolved
pablogsal added 4 commits Feb 1, 2021
Copy link
Contributor

@lysnikolaou lysnikolaou left a comment

This is such a long-awaited improvement! 🚀 Really good job! After this we can think about using the forced-expect operator in other places as well.

@pablogsal pablogsal merged commit 58fb156 into python:master Feb 2, 2021
11 checks passed
11 checks passed
Docs
Details
Check for source changes
Details
Check if generated files are up to date
Details
Windows (x86)
Details
Windows (x64)
Details
macOS
Details
Ubuntu
Details
Azure Pipelines PR #20210201.15 succeeded
Details
Travis CI - Pull Request Build Passed
Details
bedevere/issue-number Issue number 42997 found
Details
bedevere/news News entry found in Misc/NEWS.d
ncoghlan added a commit to ncoghlan/cpython that referenced this pull request Feb 8, 2021
…H-24292)

* Add to the peg generator a new directive ('&&') that allows to expect
  a token and hard fail the parsing if the token is not found. This
  allows to quickly emmit syntax errors for missing tokens.

* Use the new grammar element to hard-fail if the ':' is missing before
  suites.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants