feat: add add_decl_doc command

This commit is contained in:
Leonardo de Moura 2022-07-27 09:30:32 -07:00
parent 0d43684956
commit 2c0de29dfd
2 changed files with 13 additions and 11 deletions

View file

@ -11,20 +11,20 @@ namespace Lean
private builtin_initialize builtinDocStrings : IO.Ref (NameMap String) ← IO.mkRef {}
private builtin_initialize docStringExt : MapDeclarationExtension String ← mkMapDeclarationExtension `docstring
private def findLeadingSpacesSize (s : String) : Nat :=
private def findLeadingSpacesSize (s : String) : Nat :=
let it := s.iter
let it := it.find (· == '\n') |>.next
let (min, it) := it.foldUntil 0 fun num c => if c == ' ' || c == '\t' then some (num + 1) else none
findNextLine it min
where
findNextLine it min
where
consumeSpaces (it : String.Iterator) (curr min : Nat) : Nat :=
if it.atEnd then min
else if it.curr == ' ' || it.curr == '\t' then consumeSpaces it.next (curr + 1) min
else findNextLine it.next (Nat.min curr min)
findNextLine (it : String.Iterator) (min : Nat) : Nat :=
if it.atEnd then min
else if it.curr == '\n' then consumeSpaces it.next 0 min
else findNextLine it.next min
else if it.curr == '\n' then consumeSpaces it.next 0 min
else findNextLine it.next min
private def removeNumLeadingSpaces (n : Nat) (s : String) : String :=
consumeSpaces n s.iter ""
@ -33,18 +33,18 @@ where
match n with
| 0 => saveLine it r
| n+1 =>
if it.atEnd then r
else if it.curr == ' ' || it.curr == '\t' then consumeSpaces n it.next r
if it.atEnd then r
else if it.curr == ' ' || it.curr == '\t' then consumeSpaces n it.next r
else saveLine it r
saveLine (it : String.Iterator) (r : String) : String :=
if it.atEnd then r
else if it.curr == '\n' then consumeSpaces n it.next (r.push '\n')
else saveLine it.next (r.push it.curr)
termination_by
consumeSpaces n it r => (it, 1)
else saveLine it.next (r.push it.curr)
termination_by
consumeSpaces n it r => (it, 1)
saveLine it r => (it, 0)
private def removeLeadingSpaces (s : String) : String :=
private def removeLeadingSpaces (s : String) : String :=
let n := findLeadingSpacesSize s
if n == 0 then s else removeNumLeadingSpaces n s

View file

@ -137,6 +137,8 @@ def initializeKeyword := leading_parser "initialize " <|> "builtin_initialize "
@[builtinCommandParser] def «in» := trailing_parser withOpen (" in " >> commandParser)
@[builtinCommandParser] def addDocString := leading_parser docComment >> "add_decl_doc" >> ident
/--
This is an auxiliary command for generation constructor injectivity theorems for inductive types defined at `Prelude.lean`.
It is meant for bootstrapping purposes only. -/