-
Notifications
You must be signed in to change notification settings - Fork 7
/
schemas.dhall
95 lines (78 loc) · 2.63 KB
/
schemas.dhall
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
let Format = < YAML | JSON | Raw >
let Install = < Symlink | Write | None >
let Options =
{ Type = { destination : Text }, default.destination = "generated" }
let HeaderBracket = { prefix : Text, linePrefix : Text, suffix : Text }
let HeaderType =
-- Ignore: Bool is a hack to distinguish this case in `dhall-to-json`,
-- with no associated value it serializes as the string "Ignore",
-- which is the same type as Prefix
< Ignore : Bool | Prefix : Text | Bracket : HeaderBracket >
let Header =
{ Type = HeaderType
, ignore = HeaderType.Ignore False
, raw = HeaderType.Prefix ""
, hash = HeaderType.Prefix "# "
, doubleSlash = HeaderType.Prefix "// "
, doubleDash = HeaderType.Prefix "-- "
, multiLineC =
HeaderType.Bracket { prefix = "/*", suffix = "*/", linePrefix = " " }
, html =
HeaderType.Bracket
{ prefix = "<!--", suffix = "-->", linePrefix = " " }
}
let Metadata =
{ format : Format
, install : Install
, executable : Bool
, path : Optional Text
, header :
-- header is deprecated
-- (headerLines lets you specify a format-independent header,
-- and pair it with a format-sepcific headerFormat)
Optional Text
, headerLines : List Text
, headerFormat : Header.Type
}
let defaultHeader =
[ "**NOTE**: this file is generated by `dhall-render`."
, "You should NOT edit it manually, your changes will be lost."
]
let defaultMetadata =
{ install = Install.Symlink
, header = None Text
, headerLines = defaultHeader
, headerFormat =
-- Hash matches the most target formats (yaml & most script types)
Header.hash
, path = None Text
, executable = False
}
let File =
-- base File type with contents of type T
\(T : Type) ->
{ Type = Metadata //\\ { contents : T }, default = defaultMetadata }
let withFormat =
-- File with a specific format
\(format : Format) ->
\(headerFormat : Header.Type) ->
\(T : Type) ->
let file = File T
in file // { default = file.default // { format, headerFormat } }
let TextFile = withFormat Format.Raw Header.hash Text
let YAMLFile = withFormat Format.YAML Header.hash
let JSONFile = withFormat Format.JSON Header.ignore
let MarkdownFile = TextFile with default.headerFormat = Header.html
let Executable = TextFile with default.executable = True
in { File
, Format
, Header
, TextFile
, Executable
, YAMLFile
, JSONFile
, MarkdownFile
, Install
, Metadata
, Options
}