@@ -10,56 +10,11 @@ import Lake.DSL.DeclUtil
10
10
namespace Lake.DSL
11
11
open Lean Parser Command
12
12
13
- syntax packageDeclWithBinders :=
14
- (ppSpace "(" Term.simpleBinder ")" )? -- dir
15
- (ppSpace "(" Term.simpleBinder ")" )? -- args
16
- (declValSimple <|> declValStruct <|> declValDo)
17
-
18
- syntax packageDeclSpec :=
19
- ident (Command.whereStructInst <|> declValTyped <|> packageDeclWithBinders)?
20
-
21
- def expandPackageBinders
22
- : Option SimpleBinder → Option SimpleBinder → MacroM (Bool × SimpleBinder × SimpleBinder)
23
- | none, none => do let hole ← `(Term.hole|_); return (false , hole, hole)
24
- | some dir, none => return (true , dir, ← `(Term.hole|_))
25
- | none, some args => return (true , ← `(Term.hole|_), args)
26
- | some dir, some args => return (true , dir, args)
27
-
28
- def mkSimplePackageDecl
29
- (doc? : Option DocComment) (attrs : Array AttrInstance) (id : Ident) (defn : Term)
30
- (dir? : Option SimpleBinder) (args? : Option SimpleBinder) (wds? : Option WhereDecls) : MacroM Syntax := do
31
- let (hasBinders, dir, args) ← expandPackageBinders dir? args?
32
- if hasBinders then
33
- `($[$doc?]? @[$attrs,*] def $id : Packager :=
34
- (fun $dir $args => $defn) $[$wds?]?)
35
- else
36
- `($[$doc?]? @[$attrs,*] def $id : PackageConfig := $defn $[$wds?]?)
37
-
38
13
/-- The name given to the definition created by the `package` syntax. -/
39
14
def packageDeclName := `_package
40
15
41
- def mkPackageDecl (doc? : Option DocComment) (attrs : Array AttrInstance) : Macro
42
- | `(packageDeclSpec| $id:ident) =>
43
- `($[$doc?]? @[$attrs,*] def $(mkIdentFrom id packageDeclName) : PackageConfig :=
44
- {name := $(quote id.getId)})
45
- | `(packageDeclSpec| $id:ident where $ds;* $[$wds?]?) =>
46
- `($[$doc?]? @[$attrs,*] def $(mkIdentFrom id packageDeclName) : PackageConfig where
47
- name := $(quote id.getId); $ds;* $[$wds?]?)
48
- | `(packageDeclSpec| $id:ident : $ty := $defn $[$wds?]?) =>
49
- `($[$doc?]? @[$attrs,*] def $(mkIdentFrom id packageDeclName) : $ty := $defn $[$wds?]?)
50
- | `(packageDeclSpec| $id:ident $[($dir?)]? $[($args?)]? := $defn $[$wds?]?) =>
51
- mkSimplePackageDecl doc? attrs (mkIdentFrom id packageDeclName) defn dir? args? wds?
52
- | `(packageDeclSpec| $id:ident $[($dir?)]? $[($args?)]? { $[$fs $[,]?]* } $[$wds?]?) => do
53
- let defn ← `({ name := $(quote id.getId), $fs,* })
54
- mkSimplePackageDecl doc? attrs (mkIdentFrom id packageDeclName) defn dir? args? wds?
55
- | `(packageDeclSpec| $id:ident $[($dir?)]? $[($args?)]? do $seq $[$wds?]?) => do
56
- let (_, dir, args) ← expandPackageBinders dir? args?
57
- `($[$doc?]? @[$attrs,*] def $(mkIdentFrom id packageDeclName) : IOPackager :=
58
- (fun $dir $args => do $seq) $[$wds?]?)
59
- | stx => Macro.throwErrorAt stx "ill-formed package declaration"
60
-
61
16
/--
62
- Command that declares the configuration of a Lake package. Has many forms:
17
+ Defines the configuration of a Lake package. Has many forms:
63
18
64
19
```lean
65
20
package «pkg-name»
@@ -68,12 +23,13 @@ package «pkg-name» where /- config opts -/
68
23
package «pkg-name» : PackageConfig := /- config -/
69
24
```
70
25
71
- There can only be one package configuration per lakefile .
26
+ There can only be one ` package` declaration per Lake configuration file .
72
27
The defined package configuration will be available for reference as `_package`.
73
28
-/
74
29
scoped macro (name := packageDecl)
75
30
doc?:optional(docComment) attrs?:optional(Term.attributes)
76
- "package " spec:packageDeclSpec : command => do
31
+ "package " sig:structDeclSig : command => do
77
32
let attr ← `(Term.attrInstance| «package »)
33
+ let ty := mkCIdentFrom (← getRef) ``PackageConfig
78
34
let attrs := #[attr] ++ expandAttrs attrs?
79
- mkPackageDecl doc? attrs spec
35
+ mkConfigStructDecl packageDeclName doc? attrs ty sig
0 commit comments