Skip to content

Commit

Permalink
fix: preserve trailing whitespace after embedded example terms
Browse files Browse the repository at this point in the history
  • Loading branch information
david-christiansen committed Mar 20, 2024
1 parent cd4d0a3 commit 7d742a8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/examples/SubVerso/Examples.lean
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,23 @@ scoped syntax "%example" ("(" &"config" " := " term")")? ident command command*
example : TermElabM Unit := logError "foo"

partial def extractExamples (stx : Syntax) : StateT (NameMap Syntax) Id Syntax := do
if let `(term|%ex { $n:ident }{ $tm:term }) := stx then
if let `(term|%ex { $n:ident }{ $tm:term }%$tk) := stx then
let next ← extractExamples tm
-- Save the erased version in case there's nested examples
let next := augmentTrailing next tk
modify fun st => st.insert n.getId next
pure next
else
match stx with
| .node info kind args => pure <| .node info kind (← args.mapM extractExamples)
| _ => pure stx
where
getTrailing (stx : Syntax) : String :=
match stx.getTailInfo with
| .original _ _ t _ => t.toString
| _ => ""
augmentTrailing (stx tok : Syntax) : Syntax :=
stx.updateTrailing (getTrailing stx ++ getTrailing tok).toSubstring

private def contents (message : Message) : IO String := do
let head := if message.caption != "" then message.caption ++ ":\n" else ""
Expand Down

0 comments on commit 7d742a8

Please sign in to comment.