Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
digama0 committed Nov 2, 2022
1 parent ad5db7e commit c764cb2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
11 changes: 10 additions & 1 deletion Mathport/Syntax/Translate/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,12 @@ def push (stx : Syntax) : M Unit := do
pure f!"-- failed to format: {← e.toMessageData.toString}\n{reprint stx}")
printOutput f!"{fmt}\n\n"

def stripLastNewline : Format → Format
| .append f₁ f₂ => .append f₁ (stripLastNewline f₂)
| .text s => .text <|
let p := s.prev s.endPos; if s.get p == '\n' then s.extract p s.endPos else s
| f => f

def pushM (stx : M Syntax) : M Unit := stx >>= push

def withReplacement (name : Option Name) (x : M Unit) : M Unit :=
Expand All @@ -481,7 +487,10 @@ def withReplacement (name : Option Name) (x : M Unit) : M Unit :=
| some n => do
match (← read).config.replacementStyle with
| .skip => pure ()
| .comment => printOutput f!"#print {n} /-\n"; x; printOutput f!"-/\n"
| .comment =>
printOutput f!"#print {n} /-\n"
x
modify fun s => { s with output := stripLastNewline s.output ++ "-/\n\n" }
| .keep => x

def getNotationEntry? (n : Name) : M (Option NotationEntry) := do
Expand Down
7 changes: 3 additions & 4 deletions Mathport/Syntax/Translate/Tactic/Lean3.lean
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,9 @@ def trLoc : (loc : Location) → M (Option (TSyntax ``Parser.Tactic.location))
@[tr_tactic revert] def trRevert : TacM Syntax := do
`(tactic| revert $[$((← parse ident*).map mkIdent)]*)

def trRwRule (r : RwRule) : M (TSyntax ``Parser.Tactic.rwRule) :=
return mkNode ``Parser.Tactic.rwRule #[
mkOptionalNode $ if r.symm then some (mkAtom "←") else none,
← trExpr r.rule]
def trRwRule (r : RwRule) : M (TSyntax ``Parser.Tactic.rwRule) := do
let e ← trExpr r.rule
if r.symm then `(Parser.Tactic.rwRule| ← $e) else `(Parser.Tactic.rwRule| $e:term)

def trRwArgs : TacM (Array (TSyntax ``Parser.Tactic.rwRule) × Option (TSyntax ``Parser.Tactic.location)) := do
let q ← liftM $ (← parse rwRules).mapM trRwRule
Expand Down

0 comments on commit c764cb2

Please sign in to comment.