diff --git a/src/Lean/DocString.lean b/src/Lean/DocString.lean index 9b233b2da1..d9dc4ad175 100644 --- a/src/Lean/DocString.lean +++ b/src/Lean/DocString.lean @@ -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 diff --git a/src/Lean/Parser/Command.lean b/src/Lean/Parser/Command.lean index 4d41c87f68..ab20050736 100644 --- a/src/Lean/Parser/Command.lean +++ b/src/Lean/Parser/Command.lean @@ -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. -/