fix: Format.align always prints whitespace

This commit is contained in:
Gabriel Ebner 2022-12-12 16:43:13 -08:00
parent d3c852a3b1
commit 0d598dcfdf
9 changed files with 22 additions and 20 deletions

View file

@ -42,7 +42,7 @@ inductive Format where
if the current group does not fit within the allotted column width. -/
| line : Format
/-- `align` tells the formatter to pad with spaces to the current indent,
or else add a newline if we are already past the indent. For example:
or else add a newline if we are already at or past the indent. For example:
```
nest 2 <| "." ++ align ++ "a" ++ line ++ "b"
```
@ -122,7 +122,7 @@ private def spaceUptoLine : Format → Bool → Int → Nat → SpaceResult
| line, flatten, _, _ => if flatten then { space := 1 } else { foundLine := true }
| align force, flatten, m, w =>
if flatten && !force then {}
else if w m then
else if w < m then
{ space := (m - w).toNat }
else
{ foundLine := true }
@ -236,7 +236,7 @@ private partial def be (w : Nat) [Monad m] [MonadPrettyFormat m] : List WorkGrou
be w (gs' is)
else
let k ← currColumn
if k i.indent then
if k < i.indent then
pushOutput ("".pushn ' ' (i.indent - k).toNat)
endTags i.activeTags
be w (gs' is)

View file

@ -337,9 +337,9 @@ macro_rules
section
open Lean.Parser.Tactic
syntax cdotTk := patternIgnore("·" <|> ".")
syntax cdotTk := patternIgnore("· " <|> ". ")
/-- `· tac` focuses on the main goal and tries to solve it using `tac`, or else fails. -/
syntax cdotTk ppSpace sepBy1IndentSemicolon(tactic) : tactic
syntax cdotTk sepBy1IndentSemicolon(tactic) : tactic
macro_rules
| `(tactic| $cdot:cdotTk $tacs*) => `(tactic| {%$cdot $tacs* }%$cdot)
end

View file

@ -191,7 +191,7 @@ The structure type can be specified if not inferable:
`{ x := 1, y := 2 : Point }`.
-/
@[builtin_term_parser] def structInst := leading_parser
"{" >> withoutPosition (ppHardSpace >> optional (atomic (sepBy1 termParser ", " >> " with "))
"{ " >> withoutPosition (optional (atomic (sepBy1 termParser ", " >> " with "))
>> sepByIndent (structInstFieldAbbrev <|> structInstField) ", " (allowTrailingSep := true)
>> optEllipsis
>> optional (" : " >> termParser)) >> " }"

View file

@ -126,8 +126,7 @@ def pushLine : FormatterM Unit :=
pushWhitespace Format.line
def pushAlign (force : Bool) : FormatterM Unit :=
-- don't reset leadWord because .align may introduce zero space
push (.align force)
pushWhitespace (.align force)
/-- Execute `x` at the right-most child of the current node, if any, then advance to the left. -/
def visitArgs (x : FormatterM Unit) : FormatterM Unit := do

View file

@ -3,7 +3,8 @@ fun x => do
let scp ← getCurrMacroScope
let mainModule ← getMainModule
pure
{ raw :=
{
raw :=
Syntax.node2 info `term👉__ (Syntax.atom info "👉")
x.raw } : (x : TSyntax [`ident, `token._]) → ?m x (TSyntax `term)
true
@ -13,7 +14,8 @@ fun x => do
let scp ← getCurrMacroScope
let mainModule ← getMainModule
pure
{ raw :=
{
raw :=
Syntax.node2 info `termBarBazBoing (Syntax.atom info "bar")
x.raw } : (x : TSyntax [`token.baz, `token.boing]) → ?m x (TSyntax `term)
true

View file

@ -1,4 +1,4 @@
653.lean:4:14-4:32: error: function expected at
{ }
{ }
term has type
Color ?m ?m ?m

View file

@ -32,23 +32,22 @@ do
t✝
else
e✝
def foo✝ := by
def foo✝ := by
· skip; skip
· skip; skip
skip
(skip; skip)
( skip; skip
try skip; skip
try
try
skip
skip
skip)
by
try
try
skip
skip
by
try
by try
skip
skip
by try skip

View file

@ -15,7 +15,8 @@
let scp ← Lean.getCurrMacroScope
let mainModule ← Lean.getMainModule
pure
{ raw :=
{
raw :=
Lean.Syntax.node2 info `Lean.Parser.Term.app
(Lean.Syntax.ident info (String.toSubstring' "Nat.add") (Lean.addMacroScope mainModule `Nat.add scp)
[Lean.Syntax.Preresolved.decl `Nat.add [], Lean.Syntax.Preresolved.namespace `Nat.add])
@ -63,7 +64,8 @@
let _ ← Lean.getCurrMacroScope
let _ ← Lean.getMainModule
pure
{ raw :=
{
raw :=
Lean.Syntax.node2 info `Lean.Parser.Term.app
(Lean.Syntax.node3 info `term_+++_ lhs.raw (Lean.Syntax.atom info "+++") rhs.raw)
(Lean.Syntax.node info `null (Array.append #[] (Lean.TSyntaxArray.raw moreArgs))) }.raw

View file

@ -2,7 +2,7 @@
True
[Elab.step.result] True
[Elab.step] expected type: True, term
by
by
skip
trivial
[Elab.step.result] ?m
@ -15,7 +15,7 @@
[Elab.step] skip
[Elab.step] trivial
[Elab.step] (apply And.intro✝) <;> trivial
[Elab.step] focus
[Elab.step] focus
apply And.intro✝
with_annotate_state"<;>" skip
all_goals trivial