leanprover / leanprover/lean4

Longest match parser combinator or `<|>` variant

Open
#1,347 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature P-low
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

We currently use the longest match parser combinator only when processing syntax categories. During the ICERM after-party hackton, users created fake "syntax category" to get the longest match behavior. BTW, they were also confused by the following example:

syntax case1 := ident " : " term
syntax case2 := ident " ∈ " term 

syntax "foo " (case1 <|> case2) : term

#check foo x ∈ /- parser error at ∈ -/ Fin 10 

The problem is that <|> only backtracks if no token has been consumed. One has to use atomic here or hoist out the ident, but this is not natural to new users.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the case1 <|> case2 example from the issue and compare its behavior with atomic and the existing longest-match parser combinator. Then locate the parser-combinator entry points and determine the intended semantics for a longest-match variant; done should include a documented resolution of the example and matching tests.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.