forked from leanprover/lean4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormat.lean
71 lines (54 loc) · 1.71 KB
/
Format.lean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/-
Copyright (c) 2018 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
-/
import Lean.Data.Options
universe u v
namespace Std
namespace Format
open Lean
def getWidth (o : Options) : Nat := o.get `format.width defWidth
def getIndent (o : Options) : Nat := o.get `format.indent defIndent
def getUnicode (o : Options) : Bool := o.get `format.unicode defUnicode
register_builtin_option format.width : Nat := {
defValue := defWidth
descr := "indentation"
}
register_builtin_option format.unicode : Bool := {
defValue := defUnicode
descr := "unicode characters"
}
register_builtin_option format.indent : Nat := {
defValue := defIndent
descr := "indentation"
}
def pretty' (f : Format) (o : Options := {}) : String :=
pretty f (format.width.get o)
end Format
end Std
namespace Lean
open Std
export Std
(Format ToFormat Format.nest Format.nil Format.joinSep Format.line
Format.sbracket Format.bracket Format.group Format.tag Format.pretty
Format.fill Format.paren Format.join Format.align)
export ToFormat (format)
instance : ToFormat Name where
format n := n.toString
instance : ToFormat DataValue where
format
| DataValue.ofString v => format (repr v)
| DataValue.ofBool v => format v
| DataValue.ofName v => "`" ++ format v
| DataValue.ofNat v => format v
| DataValue.ofInt v => format v
| DataValue.ofSyntax v => format v
instance : ToFormat (Name × DataValue) where
format
| (n, v) => format n ++ " := " ++ format v
open Std.Format
def formatKVMap (m : KVMap) : Format :=
sbracket (Format.joinSep m.entries ", ")
instance : ToFormat KVMap := ⟨formatKVMap⟩
end Lean