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:
__dir__
/`__args__
syntax for config settings
- Loading branch information
Showing
6 changed files
with
82 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/- | ||
Copyright (c) 2021 Mac Malone. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Mac Malone | ||
-/ | ||
import Lean.Elab.ElabRules | ||
import Lake.DSL.Extensions | ||
|
||
namespace Lake.DSL | ||
open Lean Elab Term | ||
|
||
/-- | ||
A dummy default constant for `__dir__` to make it type check | ||
outside Lakefile elaboration (e.g., when editing). | ||
-/ | ||
constant dummyDir : System.FilePath | ||
|
||
/-- | ||
A dummy default constant for `__args__` to make it type check | ||
outside Lakefile elaboration (e.g., when editing). | ||
-/ | ||
constant dummyArgs : List String | ||
|
||
/-- | ||
A macro that expands to the path of package's directory | ||
during the Lakefile's elaboration. | ||
-/ | ||
scoped elab stx:"__dir__" : term <= expectedType? => do | ||
let exp := | ||
if let some dir := dirExt.getState (← getEnv) then | ||
let str := Syntax.mkStrLit dir.toString (SourceInfo.fromRef stx) | ||
Syntax.mkApp (mkCIdentFrom stx ``System.FilePath.mk) #[str] | ||
else | ||
-- `id` app forces Lean to show macro's doc rather than the constant's | ||
Syntax.mkApp (mkCIdentFrom stx ``id) #[mkCIdentFrom stx ``dummyDir] | ||
withMacroExpansion stx exp <| elabTerm exp expectedType? | ||
|
||
/-- | ||
A macro that expands to the configuration arguments passed | ||
via the Lake command line during the Lakefile's elaboration. | ||
-/ | ||
scoped elab stx:"__args__" : term <= expectedType? => do | ||
let exp := | ||
if let some args := argsExt.getState (← getEnv) then | ||
quote args | ||
else | ||
-- `id` app forces Lean to show macro's doc rather than the constant's | ||
Syntax.mkApp (mkCIdentFrom stx ``id) #[mkCIdentFrom stx ``dummyArgs] | ||
withMacroExpansion stx exp <| elabTerm exp expectedType? |
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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
import Lake | ||
open Lake DSL | ||
|
||
#eval show IO _ from do | ||
IO.println s!"elaborating configuration in {__dir__} with args {__args__}" | ||
|
||
package io (dir) (args) do | ||
IO.println s!"computing io package in {dir} with args {args} ..." | ||
return {name := `io} |