This repository has been archived by the owner on Oct 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: syntax for defining extra lib & exe targets
- Loading branch information
Showing
9 changed files
with
121 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/- | ||
Copyright (c) 2022 Mac Malone. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Mac Malone | ||
-/ | ||
import Lake.DSL.DeclUtil | ||
import Lake.DSL.Attributes | ||
import Lake.Config.Targets | ||
|
||
namespace Lake.DSL | ||
open Lean Parser Command | ||
|
||
syntax targetDeclSpec := | ||
ident (Command.whereStructInst <|> declValOptTyped <|> declValStruct)? | ||
|
||
def mkTargetDecl | ||
(doc? : Option Syntax) (attrs : Array Syntax) (ty : Syntax) | ||
: (spec : Syntax) → MacroM Syntax | ||
| `(targetDeclSpec| $id:ident) => | ||
`($[$doc?:docComment]? @[$attrs,*] def $id : $ty := | ||
{name := $(quote id.getId)}) | ||
| `(targetDeclSpec| $id:ident where $[$ds]*) => | ||
`($[$doc?:docComment]? @[$attrs,*] def $id : $ty where | ||
name := $(quote id.getId) $[$ds]*) | ||
| `(targetDeclSpec| $id:ident $[: $ty?]? := $defn $[$wds?]?) => | ||
`($[$doc?:docComment]? @[$attrs,*] def $id : $(ty?.getD ty) := $defn $[$wds?]?) | ||
| `(targetDeclSpec| $id:ident { $[$fs $[,]?]* } $[$wds?]?) => do | ||
let defn ← `({ name := $(quote id.getId), $[$fs]* }) | ||
`($[$doc?:docComment]? @[$attrs,*] def $id : $ty := $defn $[$wds?]?) | ||
| stx => Macro.throwErrorAt stx "ill-formed target declaration" | ||
|
||
/-- | ||
Define a new Lean library target for the package. | ||
Can optionally be provided with a configuration of type `LeanLibConfig`. | ||
-/ | ||
scoped macro (name := leanLibDecl) | ||
doc?:optional(docComment) attrs?:optional(Term.attributes) | ||
"lean_lib " spec:targetDeclSpec : command => do | ||
let ty := mkCIdentFrom (← getRef) ``LeanLibConfig | ||
let attrs := expandAttrs attrs? |>.push <| ← `(Term.attrInstance| leanLib) | ||
mkTargetDecl doc? attrs ty spec | ||
|
||
/-- | ||
Define a new Lean binary executable target for the package. | ||
Can optionally be provided with a configuration of type `LeanExeConfig`. | ||
-/ | ||
scoped macro (name := leanExeDecl) | ||
doc?:optional(docComment) attrs?:optional(Term.attributes) | ||
"lean_exe " spec:targetDeclSpec : command => do | ||
let ty := mkCIdentFrom (← getRef) ``LeanExeConfig | ||
let attrs := expandAttrs attrs? |>.push <| ← `(Term.attrInstance| leanExe) | ||
mkTargetDecl doc? attrs ty spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters