Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Pp_ast ppxlib to this repo #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
.merlin
node_modules
_esy
_release
*.byte
*.native
*.install
*.native
_build
.esy
.merlin
_opam
_release
dist
node_modules
ast_explorer_refmt.bc.js
1 change: 1 addition & 0 deletions .ocamlformat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
profile=default
62 changes: 62 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
project_name = astexplorer-refmt

DUNE = opam exec -- dune
opam_file = $(project_name).opam

.PHONY: help
help:
@echo "";
@echo "List of available make commands";
@echo "";
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}';
@echo "";

.PHONY: build-dev
dev:
$(DUNE) build -w

.PHONY: build-prod
prod:
yarn install
$(DUNE) build
mkdir -p dist
chmod -R 777 dist
yarn build:prod

.PHONY: clean
clean: ## Clean artifacts
$(DUNE) clean

.PHONY: exec
exec: ## Run the project
$(DUNE) exec $(demo)

.PHONY: format
format:
DUNE_CONFIG__GLOBAL_LOCK=disabled $(DUNE) build @fmt --auto-promote

.PHONY: format-check
format-check:
$(DUNE) build @fmt

.PHONY: create-switch
create-switch: ## Create opam switch
opam switch create . 5.2.1 --deps-only --with-dev-setup -y

.PHONY: install
install:
yarn install
$(DUNE) build @install
opam install . --deps-only --with-test

.PHONY: init
init: create-switch install

.PHONY: demo
demo:
yarn install
$(DUNE) build
mkdir -p src/example/dist
chmod -R 777 src/example/dist
cp _build/default/src/ast_explorer_refmt.bc.js ./src/example/dist/ast_explorer_refmt.bc.js
yarn serve -p 3030 src/example
46 changes: 24 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,48 @@ JavaScript wrapper for [refmt](https://github.com/facebook/reason/tree/master/sr

Not intended to be used as a library.

## Conversion from OCaml to JavaScript for astexplorer

- Record -> Object
- Tuple -> Array
- Variant -> Object with property `type` the name of the constructor, and then other properties with names that help understand the function of each variant argument

## Development

The project requires esy to be built, you can install it using [npm](https://nodejs.org/en/download/):

% npm install -g esy
The project requires `opam` and `yarn` to build, and it uses `make` to run the project.

Install the project dependencies using:
```
make init
```

% esy install
You can run the watch mode to automatically build the project when you make changes:

Build the project dependencies along with the project itself:
```
make dev
```

% esy build
To build the project as production mode:
(The output bundle will be stored in the `./dist` folder)

To test the compiled JS executable, open `index.html` in your browser.
```
make prod
```

To generate the production build (without sourcemaps, and minified) run:
To run an example, you can use the `demo` command:

% yarn run build:prod
```
make demo
```

The output bundle will be stored in the `./dist` folder.

### Running with astexplorer

- `yarn link` in the project root folder
- Clone [`astexplorer`](https://github.com/fkling/astexplorer/) locally.
- In `website` folder of `astexplorer`, call `yarn link astexplorer-refmt`.
- In `website` folder of `astexplorer`, call `yarn link <path-to-astexplorer-refmt>`.

### Running without astexplorer

Add some logging in `AstExplorerRefmt.re`, for example:
Edit the code variable in `src/example/example.js` to parse some code.
```js
let code = "let x = 1";

```reason
log("parse", parseReason("let f = a => \"1\"; /* Comment */ let a = 2;"));
let ast = window.parseReason(code);
window.document.querySelector("#app").innerHTML = ast;
```

Then open `src/index.html` to see the parsed JavaScript object in the console.
Then run `make demo` and open `http://localhost:3030/` in your browser.
40 changes: 40 additions & 0 deletions astexplorer-refmt.opam
100755 → 100644
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis: "OCaml AST explorer for Reason and OCaml"
maintainer: [
"Javier Chávarri <[email protected]>"
"Pedro Lisboa <[email protected]>"
]
authors: ["Javier Chávarri <[email protected]>"]
license: "ISC"
homepage: "https://github.com/jchavarri/astexplorer-refmt"
bug-reports: "https://github.com/jchavarri/astexplorer-refmt/issues"
depends: [
"dune" {>= "3.8"}
"ocaml" {>= "5.0.0"}
"reason" {>= "3.14.0"}
"js_of_ocaml-ppx" {>= "5.9.0"}
"js_of_ocaml" {>= "5.9.0"}
"ppxlib" {> "0.23.0"}
"ocamlformat" {= "0.26.2" & with-dev-setup}
"ocaml-lsp-server" {with-dev-setup}
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/jchavarri/astexplorer-refmt.git"
pin-depends: [
["ppxlib.dev" "git+https://github.com/ocaml-ppx/ppxlib.git#a60d33c91ef1b87056d97482fda568a6f1c849fc"]
]
3 changes: 3 additions & 0 deletions astexplorer-refmt.opam.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pin-depends: [
["ppxlib.dev" "git+https://github.com/ocaml-ppx/ppxlib.git#a60d33c91ef1b87056d97482fda568a6f1c849fc"]
]
1 change: 1 addition & 0 deletions dune
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(dirs src)
43 changes: 42 additions & 1 deletion dune-project
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
(lang dune 1.0)
(lang dune 3.8)

(using melange 0.1)

(generate_opam_files true)

(implicit_transitive_deps false)

(name astexplorer-refmt)

(source
(github jchavarri/astexplorer-refmt))

(license ISC)

(maintainers "Javier Chávarri <[email protected]>" "Pedro Lisboa <[email protected]>")

(authors "Javier Chávarri <[email protected]>")

(package
(name astexplorer-refmt)
(synopsis "OCaml AST explorer for Reason and OCaml")
(allow_empty)
(depends
(ocaml
(>= 5.0.0))
(reason
(>= 3.14.0))
(js_of_ocaml-ppx
(>= 5.9.0))
; Library dependencies
(js_of_ocaml
(>= 5.9.0))
(ppxlib
(> 0.23.0))
; Dev dependencies
(ocamlformat
(and
(= 0.26.2)
:with-dev-setup))
; We use ocamlformat on the tests
(ocaml-lsp-server :with-dev-setup)))
36 changes: 0 additions & 36 deletions esy.json

This file was deleted.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
},
"homepage": "https://github.com/jchavarri/astexplorer-refmt",
"license": "MIT",
"main": "dist/AstExplorerRefmt.bc.js",
"main": "dist/ast_explorer_refmt.bc.js",
"scripts": {
"build:prod": "esy build:prod && esy cp '#{self.target_dir}/default/src/AstExplorerRefmt.bc.js' ./dist"
"build:prod": "mkdir -p dist && cp _build/default/src/ast_explorer_refmt.bc.js ./dist/ast_explorer_refmt.bc.js"
},
"devDependencies": {
"serve": "^14.2.4"
}
}
Loading