Skip to content

Commit 80521c9

Browse files
authored
Merge pull request #6 from cknitt/feature/refmt-api
Upgrade to Reason 3.2.0 and directly use Reason parser api
2 parents cbcf7dc + 4223317 commit 80521c9

File tree

5 files changed

+29
-233
lines changed

5 files changed

+29
-233
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ os:
66
- osx
77
install:
88
- npm install --global esy
9-
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then npm install --global reason-cli@3.1.0-linux; fi
10-
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then npm install --global reason-cli@3.1.0-darwin; fi
119
- esy install
1210
script:
1311
- esy build

bin/Extract.re

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,19 @@ let iterator =
2020

2121
let extractMessages = ast => iterator.structure(iterator, Obj.magic(ast));
2222

23-
let readMessagesFromChannel = channel =>
24-
switch (Ast_io.from_channel(channel)) {
25-
| Result.Ok((_, Ast_io.Impl((module Version), ast))) =>
26-
module Convert = Convert(Version, OCaml_406);
27-
let converted = Obj.magic(Convert.copy_structure(ast));
28-
extractMessages(converted);
29-
| Result.Ok((_, Ast_io.Intf(_, _))) => Printf.eprintf("Interface AST not supported, only implementation AST\n")
30-
| Result.Error(Not_a_binary_ast(_)) => Printf.eprintf("Error: input is not a binary AST\n")
31-
| Result.Error(Unknown_version(v)) => Printf.eprintf("Error: unknown AST version: %s\n", v)
32-
};
33-
3423
let processReasonFile = filename => {
35-
let channel = Unix.open_process_in("refmt -p binary " ++ filename);
36-
readMessagesFromChannel(channel);
37-
Unix.close_process_in(channel) |> ignore;
24+
let channel = open_in_bin(filename);
25+
let lexbuf = Lexing.from_channel(channel);
26+
let ast = Reason_toolchain.RE.implementation(lexbuf);
27+
close_in(channel);
28+
extractMessages(ast);
3829
};
3930

4031
let rec processDirectory = dir =>
4132
Sys.readdir(dir)
4233
|> Array.iter(filename => {
4334
let path = Filename.concat(dir, filename);
35+
4436
if (Sys.is_directory(path)) {
4537
processDirectory(path);
4638
} else if (Filename.extension(filename) == ".re") {
@@ -55,6 +47,7 @@ let outputJson = () => {
5547
|> List.map(((_id, message)) => message)
5648
|> List.sort(Message.compare)
5749
|> List.map(Message.toJson);
50+
5851
Yojson.Basic.pretty_to_channel(stdout, `List(sortedJsonObjects));
5952
print_newline();
6053
};

esy.lock

Lines changed: 20 additions & 214 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/jbuild

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
((name lib)
55
(flags (-w -40 -w +26))
66
(public_name bs-react-intl-extractor)
7-
(libraries (ocaml-migrate-parsetree yojson unix))))
7+
(libraries (reason yojson unix))))

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
},
1515
"dependencies": {
1616
"@esy-ocaml/esy-installer": "^0.0.0",
17+
"@esy-ocaml/reason": "^3.2.0",
1718
"@opam/jbuilder": "^1.0.0-beta14",
18-
"@opam/ocaml-migrate-parsetree": "^1.0.10",
19-
"@opam/reason": "^3.0.0",
2019
"@opam/yojson": "^1.4.1",
2120
"refmterr": "^3.0.4"
2221
},

0 commit comments

Comments
 (0)