leanprover / leanprover/lean4

Declaring literal syntax kind as keyword breaks precedence parsing

Open
#2,395 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

When indexing the parser tables with the next token (ignoring extended identifier behavior for this issue), we do one of two things:

  • If the next token is an naked atom s (i.e. a symbol or keyword), we use s as the index
  • If the next token is a node (i.e. a literal) of kind k, we use k as the index

These two categories are reasonably disjoint in Lean code, but that is unfortunately not true for embedded languages!

import Lean

declare_syntax_cat cat
syntax char : cat
syntax "char" : cat

elab "test" c:cat : command =>
  IO.println c

-- (choice (catChar "char") (cat_ "char"))
test char

Here the keyword char and the literal kind charKind = `char overlap

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 embedded-language example in the issue and inspect how parser tables index an atom versus a literal node. The issue provides no file or test entry point; done means the char keyword and literal kind no longer overlap in a way that breaks precedence parsing.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.