leanprover-community / leanprover-community/mathlib4
Subscript and superscript parsers should produce round-tripping `Syntax`
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 4.1k
- Forks
- 1.7k
- PR merge metrics
- No merged PRs in 30d
Description
MWE:
import Mathlib.Util.Superscript
local syntax:arg term:max noWs superscript(term) : term
local macro_rules | `($a:term$b:superscript) => `($a ^ $b)
set_option pp.raw true
set_option pp.raw.showInfo true
set_option trace.Elab.command true
#guard 2⁽¹⁺¹⁾ = 4
-- Current output:
/-
[Elab.command] ✅️ (Command.guardCmd
"#guard"
(«term_=_»
(_private._stdin.0.term___
(num "":339:"2":340:"")
(Mathlib.Tactic.superscript
(Term.paren
(Term.hygienicLParen "":340:"(":343:"" (hygieneInfo "":343:`[anonymous]:343:""))
(«term_+_» (num "":343:"1":345:"") "":345:"+":348:"" (num "":348:"1":350:""))
"":350:")":353:" ")))
"":354:"=":355:" "
(num "4")))
-/
-- Possible correct output:
/-
[Elab.command] ✅️ (Command.guardCmd
"#guard"
(«term_=_»
(_private._stdin.0.term___
(num "":339:"2":340:"")
(Mathlib.Tactic.superscript
(Mathlib.Tactic.superscript.body
(Term.paren
(Term.hygienicLParen "":340:"⁽":343:"" (hygieneInfo "":343:`[anonymous]:343:""))
(«term_+_» (num "":343:"¹":345:"") "":345:"⁺":348:"" (num "":348:"¹":350:""))
"":350:"⁾":353:" "))))
"":354:"=":355:" "
(num "4")))
-/
Possible workaround: Make the parser retain the original source tokens and define a macro that converts the body of the sub- or superscript to the form that is accepted by the elaborator.
Discovered while auto-formatting all of Mathlib.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Mathlib.Util.Superscript and reproduce the provided MWE, including the raw Syntax output and auto-formatting context. Investigate how the subscript and superscript parsers represent their source tokens. Done means the resulting Syntax preserves the original delimiters and body tokens and matches the proposed round-tripping output.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100