-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
72 additions
and
4 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,2 +1,3 @@ | ||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
$DIR/../_build/install/default/bin/ppx $DIR/Shared.macros.re $1 $2 | ||
# $DIR/../_build/install/default/bin/ppx $DIR/Shared.macros.re $1 $2 | ||
$DIR/node_modules/reason-macros-bin/ppx.js $DIR/Shared.macros.re $1 $2 |
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,3 +1,65 @@ | ||
// Reason Macros! | ||
// Use templates to write your code for you. | ||
|
||
// let%macro awesome = (m: int) => 10 + eval__m; | ||
Js.log2("ok folks", [%awesome 15]); | ||
let%macro add5 = (input: ident, log: string) => { | ||
if%eval (env("node_environment") != "production") { | ||
Js.log(eval__input) | ||
}; | ||
eval__input + 5 | ||
}; | ||
|
||
|
||
let num = 15; | ||
let someNumber = [%add5 (num, "error")]; | ||
|
||
// int, string, float, bool -- constants | ||
// ident, capIdent, longIdent, longCapIdent | ||
// expression, pattern | ||
let%macro.toplevel ionicon = (name: capIdent, iconName: capIdent) => { | ||
[%str // toplevel | ||
module Eval__name = { | ||
let name = "$eval{name}"; | ||
[@bs.module] [@react.component] | ||
external make: | ||
( | ||
~className: string=?, | ||
~fontSize: string=?, | ||
~color: string=?, | ||
~onClick: 'event => unit=? | ||
) => | ||
string = | ||
"react-ionicons/lib/$eval{iconName}"; | ||
} | ||
]; | ||
}; | ||
|
||
[%%ionicon (Link, IosLink)]; | ||
[%%ionicon (Download, MdDownload)]; | ||
|
||
let%macro.let opt = (pattern, value, continuation) => | ||
switch (eval__value) { | ||
| None => None | ||
| Some(eval__pattern) => eval__continuation | ||
}; | ||
|
||
let doSomethingWithOptionals = () => { | ||
let%opt who = Some("world"); | ||
let%opt greeting = Some("Hello"); | ||
Some(greeting ++ "" ++ who); | ||
}; | ||
|
||
let json = request => Js.Promise.resolve(request); | ||
let fetch = url => Js.Promise.resolve("Hello wold"); | ||
|
||
let%macro.let async = (pattern, value, continuation) => { | ||
Js.Promise.then_( | ||
eval__pattern => eval__continuation, | ||
eval__value | ||
); | ||
}; | ||
|
||
let doSomethingAsync = () => { | ||
let%async text = fetch("Hello"); | ||
let%async more = text->json; | ||
Js.Promise.resolve(more); | ||
}; |