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

feat: custom error recovery in parser #3413

Merged

Conversation

david-christiansen
Copy link
Contributor

Adds a simple error-recovery mechanism to Lean's parser, similar to those used in other combinator parsing libraries.

Lean itself isn't very amenable to error recovery with this mechanism, as it requires global knowledge of the grammar in question to write recovery rules that don't break backtracking or <|>. I only found a few opportunities.

But for DSLs, this is really important. In particular, Verso parse errors interacted very badly with Lean parse errors in a way that required frequent "restart file" commands, but this mechanism allows me to both recover from Verso parse errors and to have Lean skip the rest of the file rather than repeatedly trying to parse it as Lean commands.

@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Feb 20, 2024
@leanprover-community-mathlib4-bot
Copy link
Collaborator

leanprover-community-mathlib4-bot commented Feb 20, 2024

Mathlib CI status (docs):

  • ❗ Std/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. (2024-02-20 10:27:00)
  • ✅ Mathlib branch lean-pr-testing-3413 has successfully built against this PR. (2024-02-20 13:36:13) View Log
  • 🟡 Mathlib branch lean-pr-testing-3413 build against this PR was cancelled. (2024-02-20 14:56:44) View Log
  • ✅ Mathlib branch lean-pr-testing-3413 has successfully built against this PR. (2024-02-20 17:16:04) View Log

@david-christiansen
Copy link
Contributor Author

!bench

@leanprover-bot
Copy link
Collaborator

Here are the benchmark results for commit 253dda4.
There were no significant changes against commit 0e0ed9c.

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Feb 20, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Feb 20, 2024
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Feb 20, 2024
@david-christiansen david-christiansen added the awaiting-review Waiting for someone to review the PR label Feb 20, 2024
Copy link
Member

@Kha Kha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parser framework changes look great. For the grammar changes it would be nice to have a less manual approach as discussed but this is a good start.

src/Lean/Parser/Command.lean Outdated Show resolved Hide resolved
src/Lean/Parser/Command.lean Outdated Show resolved Hide resolved
src/Lean/Parser/Module.lean Outdated Show resolved Hide resolved
src/Lean/Parser/Module.lean Outdated Show resolved Hide resolved
src/Lean/Parser/Module.lean Show resolved Hide resolved
tests/lean/parserRecovery.lean Show resolved Hide resolved
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Feb 20, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Feb 20, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Feb 20, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Feb 20, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Feb 20, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Feb 20, 2024
@david-christiansen david-christiansen added this pull request to the merge queue Feb 21, 2024
Merged via the queue into leanprover:master with commit 74e7886 Feb 21, 2024
10 checks passed
github-merge-queue bot pushed a commit that referenced this pull request Mar 1, 2024
Adds the missing RELEASES.md from #3413. Apologies for the oversight!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review Waiting for someone to review the PR builds-mathlib CI has verified that Mathlib builds against this PR toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants