Skip to content

Commit

Permalink
try to use the published npm
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredly committed Jul 30, 2019
1 parent 30d058d commit 382da29
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 4 deletions.
1 change: 1 addition & 0 deletions try-bs/bsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"error": "+8"
},
"ppx-flags": ["./ppx.sh"],
"// ppx-flags": ["reason-macros-bin/ppx.js"],
"// ppx-flags": ["../_esy/default/build/install/default/bin/ppx --some-arg"],
"sources": [
{"dir": "src"}
Expand Down
3 changes: 3 additions & 0 deletions try-bs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion try-bs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"clean": "bsb -clean-world"
},
"dependencies": {
"bs-platform": "5.0.4"
"bs-platform": "5.0.4",
"reason-macros-bin": "file:../publish-npm"
}
}
3 changes: 2 additions & 1 deletion try-bs/ppx.sh
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
66 changes: 64 additions & 2 deletions try-bs/src/Hello.re
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);
};

0 comments on commit 382da29

Please sign in to comment.