Skip to content
This repository was archived by the owner on Oct 25, 2023. It is now read-only.

Commit 6c495e8

Browse files
committed
refactor: remove dead package DSL code
1 parent 1929d4a commit 6c495e8

File tree

3 files changed

+39
-79
lines changed

3 files changed

+39
-79
lines changed

Diff for: Lake/DSL/DeclUtil.lean

+30-7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ instance : Coe SimpleBinder FunBinder where
3232

3333
---
3434

35+
def expandAttrs (attrs? : Option Attributes) : Array AttrInstance :=
36+
if let some attrs := attrs? then
37+
match attrs with
38+
| `(Term.attributes| @[$attrs,*]) => attrs
39+
| _ => #[]
40+
else
41+
#[]
42+
3543
syntax structVal :=
3644
"{" manyIndent(group(Term.structInstField ", "?)) "}"
3745

@@ -50,10 +58,25 @@ syntax declValOptTyped :=
5058
syntax simpleDeclSig :=
5159
ident Term.typeSpec declValSimple
5260

53-
def expandAttrs (attrs? : Option Attributes) : Array AttrInstance :=
54-
if let some attrs := attrs? then
55-
match attrs with
56-
| `(Term.attributes| @[$attrs,*]) => attrs
57-
| _ => #[]
58-
else
59-
#[]
61+
syntax structDeclSig :=
62+
ident (Command.whereStructInst <|> declValOptTyped <|> declValStruct)?
63+
64+
def fixName (id : Ident) : Option Name → Ident
65+
| some n => mkIdentFrom id n
66+
| none => id
67+
68+
def mkConfigStructDecl (name? : Option Name)
69+
(doc? : Option DocComment) (attrs : Array AttrInstance) (ty : Term)
70+
: (spec : Syntax) → MacroM Syntax
71+
| `(structDeclSig| $id:ident) =>
72+
`($[$doc?]? @[$attrs,*] def $(fixName id name?) : $ty :=
73+
{name := $(quote id.getId)})
74+
| `(structDeclSig| $id:ident where $ds;* $[$wds?]?) =>
75+
`($[$doc?]? @[$attrs,*] def $(fixName id name?) : $ty where
76+
name := $(quote id.getId); $ds;* $[$wds?]?)
77+
| `(structDeclSig| $id:ident $[: $ty?]? := $defn $[$wds?]?) =>
78+
`($[$doc?]? @[$attrs,*] def $(fixName id name?) : $(ty?.getD ty) := $defn $[$wds?]?)
79+
| `(structDeclSig| $id:ident { $[$fs $[,]?]* } $[$wds?]?) => do
80+
let defn ← `({ name := $(quote id.getId), $fs,* })
81+
`($[$doc?]? @[$attrs,*] def $(fixName id name?) : $ty := $defn $[$wds?]?)
82+
| stx => Macro.throwErrorAt stx "ill-formed configuration syntax"

Diff for: Lake/DSL/Package.lean

+5-49
Original file line numberDiff line numberDiff line change
@@ -10,56 +10,11 @@ import Lake.DSL.DeclUtil
1010
namespace Lake.DSL
1111
open Lean Parser Command
1212

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-
3813
/-- The name given to the definition created by the `package` syntax. -/
3914
def packageDeclName := `_package
4015

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-
6116
/--
62-
Command that declares the configuration of a Lake package. Has many forms:
17+
Defines the configuration of a Lake package. Has many forms:
6318
6419
```lean
6520
package «pkg-name»
@@ -68,12 +23,13 @@ package «pkg-name» where /- config opts -/
6823
package «pkg-name» : PackageConfig := /- config -/
6924
```
7025
71-
There can only be one package configuration per lakefile.
26+
There can only be one `package` declaration per Lake configuration file.
7227
The defined package configuration will be available for reference as `_package`.
7328
-/
7429
scoped macro (name := packageDecl)
7530
doc?:optional(docComment) attrs?:optional(Term.attributes)
76-
"package " spec:packageDeclSpec : command => do
31+
"package " sig:structDeclSig : command => do
7732
let attr ← `(Term.attrInstance| «package»)
33+
let ty := mkCIdentFrom (← getRef) ``PackageConfig
7834
let attrs := #[attr] ++ expandAttrs attrs?
79-
mkPackageDecl doc? attrs spec
35+
mkConfigStructDecl packageDeclName doc? attrs ty sig

Diff for: Lake/DSL/Targets.lean

+4-23
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,6 @@ open Lean Parser Command
1616
-- # Lean Library & Executable Targets
1717
--------------------------------------------------------------------------------
1818

19-
syntax targetDeclSpec :=
20-
ident (Command.whereStructInst <|> declValOptTyped <|> declValStruct)?
21-
22-
def mkTargetDecl
23-
(doc? : Option DocComment) (attrs : Array AttrInstance) (ty : Term)
24-
: (spec : Syntax) → MacroM Syntax
25-
| `(targetDeclSpec| $id:ident) =>
26-
`($[$doc?]? @[$attrs,*] def $id : $ty :=
27-
{name := $(quote id.getId)})
28-
| `(targetDeclSpec| $id:ident where $ds;* $[$wds?]?) =>
29-
`($[$doc?]? @[$attrs,*] def $id : $ty where
30-
name := $(quote id.getId); $ds;* $[$wds?]?)
31-
| `(targetDeclSpec| $id:ident $[: $ty?]? := $defn $[$wds?]?) =>
32-
`($[$doc?]? @[$attrs,*] def $id : $(ty?.getD ty) := $defn $[$wds?]?)
33-
| `(targetDeclSpec| $id:ident { $[$fs $[,]?]* } $[$wds?]?) => do
34-
let defn ← `({ name := $(quote id.getId), $fs,* })
35-
`($[$doc?]? @[$attrs,*] def $id : $ty := $defn $[$wds?]?)
36-
| stx => Macro.throwErrorAt stx "ill-formed target declaration"
37-
3819
/--
3920
Define a new Lean library target for the package.
4021
Can optionally be provided with a configuration of type `LeanLibConfig`.
@@ -49,11 +30,11 @@ lean_lib «target-name» := /- config -/
4930
-/
5031
scoped macro (name := leanLibDecl)
5132
doc?:optional(docComment) attrs?:optional(Term.attributes)
52-
"lean_lib " spec:targetDeclSpec : command => do
33+
"lean_lib " sig:structDeclSig : command => do
5334
let attr ← `(Term.attrInstance| leanLib)
5435
let ty := mkCIdentFrom (← getRef) ``LeanLibConfig
5536
let attrs := #[attr] ++ expandAttrs attrs?
56-
mkTargetDecl doc? attrs ty spec
37+
mkConfigStructDecl none doc? attrs ty sig
5738

5839
/--
5940
Define a new Lean binary executable target for the package.
@@ -69,11 +50,11 @@ lean_exe «target-name» := /- config -/
6950
-/
7051
scoped macro (name := leanExeDecl)
7152
doc?:optional(docComment) attrs?:optional(Term.attributes)
72-
"lean_exe " spec:targetDeclSpec : command => do
53+
"lean_exe " sig:structDeclSig : command => do
7354
let attr ← `(Term.attrInstance| leanExe)
7455
let ty := mkCIdentFrom (← getRef) ``LeanExeConfig
7556
let attrs := #[attr] ++ expandAttrs attrs?
76-
mkTargetDecl doc? attrs ty spec
57+
mkConfigStructDecl none doc? attrs ty sig
7758

7859
--------------------------------------------------------------------------------
7960
-- # External Library Target

0 commit comments

Comments
 (0)