lean4-htt/tests/lean/run/tacticDocAllNonmod.lean
David Thrane Christiansen 9fbbe6554d
fix: make first token detection work in modules (#12047)
This PR makes the automatic first token detection in tactic docs much
more robust, in addition to making it work in modules and other contexts
where builtin tactics are not in the environment. It also adds the
ability to override the tactic's first token as the user-visible name.

Previously, first token detection would look up the parser descriptor in
the environment and process its syntax. This would be incorrect for
builtin parsers, as well as for modules in which the definition is not
loaded. Now, it instead consults the Pratt parsing table for the
`tactic` syntax category. Tests are added that ensure this keeps working
in modules, and also that the first token of all tactics that ship with
Lean are either detected unambiguously or annotated to remove ambiguity.

Closes #12038.
2026-01-20 11:12:05 +00:00

23 lines
820 B
Text

import Lean.Elab.Tactic.Doc
/-!
This test checks that the first tokens are found for the tactics that ship with Lean when not in a
module.
In the past, the first token detection code attempted to process the descriptor in the environment;
this failed in modules because the parser was not loaded. This test, along with tacticDocAllModule,
check that the code works correctly both in and out of modules.
-/
open Lean.Elab.Tactic.Doc
#guard_msgs in
open Lean in
#eval do
let docs ← allTacticDocs
let userNames := docs.map TacticDoc.userName
if userNames.size < 50 then
throwError "Implausibly few user names found: {userNames}"
for n in userNames do
if n.startsWith "Lean.Parser.Tactic" && n ≠ "Lean.Parser.Tactic.nestedTactic" then
logError "Didn't find a first token for tactic parser {n}"