lean4-htt/tests/elab/parseEnd.lean
Garmelon 08eb78a5b2
chore: switch to new test/bench suite (#12590)
This PR sets up the new integrated test/bench suite. It then migrates
all benchmarks and some related tests to the new suite. There's also
some documentation and some linting.

For now, a lot of the old tests are left alone so this PR doesn't become
even larger than it already is. Eventually, all tests should be migrated
to the new suite though so there isn't a confusing mix of two systems.
2026-02-25 13:51:53 +00:00

59 lines
1.5 KiB
Text

import Lean.Elab.Command
open Lean Elab Command Parser
declare_syntax_cat balanced
syntax "!" : balanced
syntax "(" balanced* ")" : balanced
elab d:docComment "test" : command => do
let some ⟨pos, endPos⟩ := d.raw[1].getRange? (canonicalOnly := true)
| throwErrorAt d "Docstring doesn't have a canonical position"
let p := Parser.categoryParser `balanced 0
let p := andthenFn whitespace p.fn
let text ← getFileMap
let input := text.source
let endPos := input.prev <| input.prev endPos
if h : endPos ≤ input.rawEndPos then
let ictx := mkInputContext input (← getFileName) (endPos := endPos) (endPos_valid := h)
let env ← getEnv
let s := { mkParserState input with pos }
let s := p.run ictx { env, options := {} } (getTokenTable env) s
if !s.allErrors.isEmpty then
for (pos, _, err) in s.allErrors do
logMessage {
fileName := (← getFileName )
pos := text.toPosition pos
endPos := some (text.toPosition endPos)
data := s!"{err.toString}"
}
else if ictx.atEnd s.pos then
logInfo s.stxStack.back
else
let pos := s.pos
logMessage {
fileName := (← getFileName )
pos := text.toPosition pos
endPos := some (text.toPosition endPos)
data := s!"expected end of input"
}
else
throwError "Out of bounds"
/-- info: (!!(!)) -/
#guard_msgs in
/--
( ! ! (!) )
-/
test
/-- error: unexpected end of input; expected ')' -/
#guard_msgs in
/--
(
-/
test