Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: preserve trailing whitespace after embedded example terms #7

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading