Skip to content

Commit 7701a42

Browse files
committed
Update Contributing Docs for Reason Syntax
Summary:Updates old docs, and removes some redundancy. First step towards cleaning up the Reason repo. Test Plan: Reviewers: CC:
1 parent b1e6f16 commit 7701a42

File tree

7 files changed

+99
-145
lines changed

7 files changed

+99
-145
lines changed

README.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,32 @@ Simple, fast & type safe code that leverages the JavaScript & OCaml ecosystems.
99

1010
[![native esy package on npm][reason-badge]](https://www.npmjs.com/package/@esy-ocaml/reason)
1111

12-
## [Getting Started](https://reasonml.github.io/docs/en/installation)
12+
## User Documentation
1313

14-
## [Community](https://reasonml.github.io/docs/en/community.html)
14+
**The Reason user docs live online at [https://reasonml.github.io](https://reasonml.github.io)**.
15+
The repo for those Reason docs lives at [github.com/reasonml/reasonml.github.io](https://github.com/reasonml/reasonml.github.io)
1516

16-
## [Roadmap & Contribution](https://reasonml.github.io/docs/en/roadmap)
17+
Docs links for new users:
1718

18-
### Documentations
19+
- [Getting Started](https://reasonml.github.io/docs/en/installation)
1920

20-
Go to https://github.com/reasonml/reasonml.github.io to contribute to the Reason documentation.
21+
- [Community](https://reasonml.github.io/docs/en/community.html)
2122

22-
### Codebase
23+
### Contributing:
2324

24-
See the [src folder's README](https://github.com/facebook/reason/tree/master/src/README.md).
25+
```sh
26+
npm install -g esy@next
27+
git clone https://github.com/facebook/reason.git
28+
cd reason
29+
esy
30+
esy test # Run the tests
31+
```
32+
33+
### Contributor Documentation:
34+
35+
The [`docs/`](./docs/) directory in this repo contains documentation for
36+
contributors to Reason itself (this repo).
2537

26-
## Programmatically Using Reason Parser From JavaScript:
27-
See [USING_PARSER_PROGRAMMATICALLY.md](https://github.com/facebook/reason/tree/master/USING_PARSER_PROGRAMMATICALLY.md)
2838

2939
## License
3040

bspacks/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ to that version first:
5454
opam switch 4.02.3
5555
```
5656

57-
Build / install the main Reason repo. Follow the instructions in https://github.com/facebook/reason/blob/master/src/README.md#contributor-setup.
57+
Build / install the main Reason repo. Follow the instructions in https://github.com/facebook/reason/blob/master/docs/GETTING_STARTED_CONTRIBUTING.md#contributor-setup.
5858

5959
Then, install the dependencies:
6060

Lines changed: 58 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,91 @@
11
# Core Reason
22

3-
**See a list of easy tasks [here](https://github.com/facebook/reason/labels/GOOD%20FIRST%20TASK)**
4-
5-
## Code of Conduct
6-
The code of conduct is described in [`CODE_OF_CONDUCT.md`](../CODE_OF_CONDUCT.md)
7-
83
## Contributor Setup
94

10-
Thanks for considering contributing to Reason! Here's the setup you need:
115

12-
### With opam
6+
### With esy
137

148
```sh
15-
# On OSX, install opam via Homebrew:
16-
brew update
17-
brew install opam
18-
# On Linux, see here (you will need opam >= 1.2.2): http://opam.ocaml.org/doc/Install.html
19-
20-
opam init
21-
# Add this to your ~/.bashrc (or ~/.zshrc), then do `source ~/.bashrc`
22-
# eval $(opam config env)
23-
24-
opam update
25-
opam switch 4.04.2
26-
eval $(opam config env)
9+
# Make sure you have the latest esy
10+
npm install -g esy@next
2711
git clone https://github.com/facebook/reason.git
2812
cd reason
29-
opam pin add -y reason .
30-
opam pin add -y rtop .
13+
esy
3114
```
3215

33-
### With esy
3416

35-
[`esy`](https://github.com/esy/esy) is an `npm`-like workflow for developing and consuming
36-
opam packages. It is still experimental, but if you're more familiar with `npm` than `opam`,
37-
`esy` will likely be an easier way to contribute to Reason.
38-
**Please file issues regarding `esy` at the [esy project](https://github.com/esy/esy) itself.**
17+
#### Testing:
18+
19+
**Test Suite:**
3920

4021
```sh
41-
# Make sure you have the latest esy
42-
npm remove -g esy
43-
npm install -g esy@next
44-
git clone https://github.com/facebook/reason.git
45-
cd reason
46-
esy install
47-
esy build
22+
esy test # Run tests
4823
```
4924

50-
##### Editors
51-
- To use VSCode, just open the Reason project root, and `ocaml-language-server` automatically
52-
works with `esy` projects, loading all the right dependencies.
53-
- To use Vim/Emacs, start your editor using `esy vim` or `esy emacs`.
25+
**One Off Tests:**
5426

55-
##### Running tests
27+
Start up the `rtop` top level with your changes:
5628

57-
You can run commands as if you had installed Reason by prefixing commands with `esy x` ("esy execute").
58-
For example `esy x make test-once-installed`
59-
29+
```sh
30+
esy x rtop
31+
```
6032

33+
Pipe some text to `refmt` with your changes:
6134

62-
For more, see the [esy documentation](https://github.com/esy-ocaml/esy).
35+
```sh
36+
echo "let a = 1" | esy x refmt
37+
```
6338

64-
### Troubleshooting
6539

66-
- Is the previous pinning unsuccessful? We might have updated a dependency; try `opam update` then `opam upgrade`.
67-
- During the last `opam pin` step, make sure your local repo is clean. In particular, remove artifacts and `node_modules`. Otherwise the pinning might go stale or stall due to the big `node_modules`.
40+
> **`esy` tips:**
41+
> - `esy x your command` will run one command `your command` in an environment
42+
> where the projects are built/installed. `esy x which refmt` will build the
43+
> packages and install them for the duration of one command - `which refmt`.
44+
> This will print the location of the built `refmt` binary.
45+
> - For more, see the [esy documentation](https://github.com/esy-ocaml/esy).
6846
69-
### Build
7047

71-
`esy x refmt --help`. **If this fails on your machine but master passes**, it means your setup wasn't right. Could you check if you followed the above installation steps? In particular, make sure you did `eval $(opam config env)` and sourced your shell environment (if you don't know how, just open a new shell tab and it'll be sourced usually).
48+
> All the built binaries are in `esy echo '#{self.target_dir}/install/default/bin'`.
7249
73-
The generated artifacts are in `esy echo '#{self.target_dir}/default/`. All the binaries are in `esy echo '#{self.target_dir}/install/default/bin`.
7450

75-
### Test
51+
### With opam
7652

77-
To do some one-off tests, try `echo "let a = 1" | esy x refmt`
53+
```sh
54+
# On OSX, install opam via Homebrew:
55+
brew update
56+
brew install opam
57+
# On Linux, see here (you will need opam >= 1.2.2): http://opam.ocaml.org/doc/Install.html
7858

79-
`esy x make test-once-installed` (make sure to follow the repo pinning instructions above!). The tests will output the difference between the expected syntax formatting and the actual one, if any.
59+
opam init
60+
# Add this to your ~/.bashrc (or ~/.zshrc), then do `source ~/.bashrc`
61+
# eval $(opam config env)
62+
63+
opam update
64+
opam switch 4.04.2
65+
eval $(opam config env)
66+
git clone https://github.com/facebook/reason.git
67+
cd reason
68+
opam pin add -y reason .
69+
opam pin add -y rtop .
70+
```
71+
> **Opam Troubleshooting:**
72+
> - Is the previous pinning unsuccessful? We might have updated a dependency;
73+
> try `opam update` then `opam upgrade`.
74+
> - During the last `opam pin` step, make sure your local repo is clean. In
75+
> particular, remove artifacts and `node_modules`. Otherwise the pinning
76+
> might go stale or stall due to the big `node_modules`.
8077
81-
Small exception: testing your changes in `rtop` is a little complicated, but you usually don't need to test it. If you do, you might have seen that your changes of the parser or printer don't affect `rtop` when you run it. Instead, you need to do `opam pin add -y reason .` and _then_ run `rtop` to see the Reason changes reflected.
8278

8379
## Repo Walkthrough
8480

8581
![reason_-_bucklescript_in_ocaml](https://user-images.githubusercontent.com/1909539/31158768-0c7e9d04-a879-11e7-9cfb-19780a599231.png)
8682
(_Click to see a larger version_)
8783

88-
We're that orange part! The core of the codebase is a parser + a printer, plus other miscellaneous utilities we expose.
84+
Reason is the orange part. The core of the codebase is a parser + a printer, plus other miscellaneous utilities we expose.
8985

9086
Throughout the codebase, you might see mentions of "migrate-parsetree", `Ast_404`, etc. These refer to https://github.com/let-def/ocaml-migrate-parsetree. It's a library that allows you to convert between different versions of the OCaml AST. This way, the Reason repo can be written in OCaml 4.04's AST data structures, while being usable on OCaml 4.02's libraries (BuckleScript's on 4.02 too).
9187

92-
Our lexer & parser use [Menhir](http://gallium.inria.fr/~fpottier/menhir/), a library that helps us with parsing (it's a "parser generator"). We **highly recommend** you to read about Menhir [here](https://realworldocaml.org/v1/en/html/parsing-with-ocamllex-and-menhir.html).
88+
The Reason lexer & parser use [Menhir](http://gallium.inria.fr/~fpottier/menhir/), a library that generates parsers. You can read more about Menhir [here](https://realworldocaml.org/v1/en/html/parsing-with-ocamllex-and-menhir.html).
9389

9490
### Core Files
9591

@@ -100,7 +96,7 @@ Our lexer & parser use [Menhir](http://gallium.inria.fr/~fpottier/menhir/), a li
10096
- `src/reason-parser/reason_pprint_ast.ml`: the pretty-printer! This is the reverse of parsing: it takes in the AST (abstract syntax tree) and prints out the nicely formatted code text.
10197

10298
- `src/reason-parser/reason_parser.messages.checked-in`: this is the huge table of mostly generated, sometimes hand-written, syntax error messages. When the parser ends up at an invalid parsing state (aka ends up with a syntax error), it'd refer to that file's content and see if that case has a specific error message assigned to it. For an example fix, see [this PR](https://github.com/facebook/reason/pull/1018) and the [follow-up](https://github.com/facebook/reason/pull/1033). To add a syntax error message see the "Add a Menhir Error Message" section below.
103-
- When running `make build`, and a new `reason_parser.messages` file is generated, do a `mv reason_parser.messages reason_parser.messages.checked-in` to persist the updated messages.
99+
- When running `esy`, and a new `reason_parser.messages` file is generated, do a `mv reason_parser.messages reason_parser.messages.checked-in` to persist the updated messages.
104100

105101
- `src/reason-parser/reason_oprint.ml`: the "outcome printer" used by Merlin, rtop and terminal, that prints the errors in Reason syntax. More info in the file itself.
106102

@@ -112,7 +108,7 @@ Our lexer & parser use [Menhir](http://gallium.inria.fr/~fpottier/menhir/), a li
112108

113109
- `*.mllib`: related: see the [OCaml extensions list](https://reasonml.github.io/docs/en/faq.html#i-m-seeing-a-weird-cmi-cmx-cmj-cma-file-referenced-in-a-compiler-error-where-do-these-files-come-from-). These are generated file from `pkg/build.ml`, which describes the package we distribute. No need to worry about them.
114110

115-
- `src/reason-parser/reason_config.ml`: global configuration that says whether our parser should run in "recoverable" mode. Merlin has a neat feature which lets it continue diagnosing e.g. type errors even when the file is syntactically invalid (at the expense of the accuracy of those type error reports' quality). Searching `reason_config` in our codebase will show you how this is used.
111+
- `src/reason-parser/reason_config.ml`: global configuration that says whether the parser should run in "recoverable" mode. Merlin has a neat feature which lets it continue diagnosing e.g. type errors even when the file is syntactically invalid (at the expense of the accuracy of those type error reports' quality). Searching `reason_config` in the codebase will show you how this is used.
116112

117113
- `src/refmttype/reason_format_type.ml`, `reason_type_of_ocaml_type.ml`: again, see `pkg/build.ml`. These produce the `refmttype` binary, used by [BetterErrors](refmttype) to output compiler errors in Reason syntax rather than the OCaml one.
118114

@@ -122,11 +118,11 @@ Our lexer & parser use [Menhir](http://gallium.inria.fr/~fpottier/menhir/), a li
122118

123119
- `src/rtop/reason_utop.ml`, `src/rtop/reason_toploop.ml`, `src/rtop/rtop_init.ml`: Reason's [Utop](https://github.com/diml/utop) integration. Utop's the terminal-based REPL you see when executing `utop` (in Reason's case, the wrapper `rtop`).
124120

125-
- `*.sh`: some of our binaries' entries.
121+
- `*.sh`: some of the binaries' entries.
126122

127123
- `src/rtop/reason_util.ml`, `reason_syntax_util.ml`: utils.
128124

129-
- `src/reason-parser/reactjs_jsx_ppx_v2.ml`: our ReactJS interop that translates [Reason JSX](https://reasonml.github.io/docs/en/jsx.html) into something that ReactJS understands. See the comments in the file and the description in [ReasonReact](https://reasonml.github.io/reason-react/#reason-react-jsx).
125+
- `src/reason-parser/reactjs_jsx_ppx_v2.ml`: the ReactJS interop that translates [Reason JSX](https://reasonml.github.io/docs/en/jsx.html) into something that ReactJS understands. See the comments in the file and the description in [ReasonReact](https://reasonml.github.io/reason-react/#reason-react-jsx).
130126

131127
- `src/reason-parser-tests/testOprint.ml`: unit tests for the outcome printer mentioned above. See the file for more info on how outcome printing is tested.
132128

@@ -135,12 +131,11 @@ Our lexer & parser use [Menhir](http://gallium.inria.fr/~fpottier/menhir/), a li
135131
Here's a recommended workflow:
136132

137133
- First put your code in the current master syntax in a file `test.re`
138-
- `make build`
139134
- `esy x refmt --print ast test.re`
140135
- look closely at the ast, spot the thing you need
141136
- Search for your item in `reason_parser.mly`
142137
- Change the logic
143-
- `esy x make test-once-installed`
138+
- `esy test`
144139

145140
Lexer helpers doc: http://caml.inria.fr/pub/docs/manual-ocaml/libref/Lexing.html
146141
Parser helper docs: http://caml.inria.fr/pub/docs/manual-ocaml/libref/Parsetree.html
@@ -178,7 +173,9 @@ Random Stack Overflow answer: https://stackoverflow.com/questions/9897358/ocaml-
178173

179174
### Debugging Grammar Conflicts
180175

181-
Run the main parser through Menhir with the `--explain` flag to have it print out details about the conflict. `menhir --explain src/reason-parser/reason_parser.mly`. The debug information can be found at `src/reason-parser/reason_parser.conflicts`.
176+
Run the main parser through Menhir with the `--explain` flag to have it print
177+
out details about the conflict. `esy menhir --explain src/reason-parser/reason_parser.mly`.
178+
The debug information can be found at `src/reason-parser/reason_parser.conflicts`.
182179

183180
### Debugging the Parser State at Runtime
184181

@@ -193,7 +190,6 @@ export OCAMLRUNPARAM='p'
193190
To add a Menhir error message, you first need to know the error code. To find the error code, you can run the following commands from the Reason project root:
194191

195192
```
196-
make
197193
esy x refmt --parse re foo.re
198194
```
199195

@@ -223,7 +219,6 @@ In some situations, Reason might report errors in a different place than where i
223219
Before digging into Reason parser, make sure this isn't actually caused by some PPX. Otherwise, run:
224220

225221
```
226-
make
227222
esy x refmt --parse re --print ast test.re
228223
```
229224

@@ -264,70 +259,3 @@ esy x refmt --parse my_old_syntax_file.re --print binary_reason | ./refmt_impl -
264259
```
265260

266261
Basically, turn your old syntax into an AST (which is resilient to syntax changes), then turn it back into the new, textual code. If you're reverting to an old enough version, the old binary's flags and/or the old build instructions might be different. In that case, see `esy x refmt --help` and/or the old README.
267-
268-
## Cutting a release
269-
270-
### OPAM Releases
271-
272-
Reason exists on OCaml's package manager OPAM.
273-
274-
- Make sure local changes are properly committed
275-
- Update remote:
276-
277-
```sh
278-
git fetch;
279-
git reset --hard origin/master
280-
```
281-
282-
- Prerelease:
283-
284-
```sh
285-
env version=x.y.z make pre_release
286-
```
287-
288-
- Check everything is ok locally
289-
- Release!
290-
291-
```sh
292-
env version=x.y.z make release
293-
```
294-
295-
- Use [opam-publish](https://github.com/ocaml/opam-publish) to publish the latest version to opam.
296-
297-
#### Releasing to OPAM manually
298-
299-
Typically Reason will be released to NPM first (through Esy). To manually release
300-
to OPAM, simply:
301-
302-
1. Copy the `.opam` file(s) in this repo
303-
2. Add a `url` clause ([example](https://github.com/ocaml/opam-repository/blob/a55812366d555a5d2ba45cba01fbdab49e459515/packages/reason/reason.3.2.0/opam#L28-L31)) with the place where to find the release tarball.
304-
3. Submit a PR to the [OPAM repository](https://github.com/ocaml/opam-repository) under e.g.
305-
`packages/reason/reason.X.Y.Z/opam`.
306-
307-
### Esy Releases
308-
309-
Cutting a release of esy versions is a good way to get packages out there for
310-
testing before submitting to opam. This lets you catch bugs quickly without
311-
having to go through the whole process of re-releasing to opam.
312-
313-
```sh
314-
esy install
315-
esy build
316-
esy make esy-prepublish
317-
```
318-
319-
Then follow the instructions. You should also probably `cd` into each
320-
`_release/xxxx/package` and try `esy install && esy build` to make sure
321-
everything builds correctly before publishing esy packages. If each of the
322-
individual packages builds correctly, then `rm` the `_release` directory
323-
and re-prepare the release by reruning `esy make esy-prepublish`. There's no
324-
need to test that each package builds correctly - you already did that.
325-
326-
Note `esy` packages are "published to npm" but that is different than the
327-
following workflow for publishing to npm.
328-
329-
### NPM
330-
331-
Reason's also on npm, albeit for a different purpose. The `refmt.js` file is distributed there, for use-cases where the native `refmt` doesn't suffice (e.g. using it on the web).
332-
333-
To publish to npm, get https://github.com/sindresorhus/np and run `np`.

docs/README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
1-
### Hello!
1+
### Documentation
22

3-
**The Reason docs can be read at [https://reasonml.github.io](https://reasonml.github.io)**
3+
> This directory is not the Reason _User_ documentation. This directory is for
4+
> Reason contributor documentation. **The Reason user docs live online at
5+
> [https://reasonml.github.io](https://reasonml.github.io)**. The repo for
6+
> those Reason docs lives at
7+
> [github.com/reasonml/reasonml.github.io](https://github.com/reasonml/reasonml.github.io)
8+
9+
**Inside of this directory:**
10+
11+
12+
**Getting Started Contributing:**
13+
14+
[`GETTING_STARTED_CONTRIBUTING.md`](./GETTING_STARTED_CONTRIBUTING.md).
15+
16+
**Releasing:**
17+
[`RELEASING.md`](./RELEASING.md)
18+
19+
**Programmatically Using Reason Parser From JavaScript:**
20+
[`USING_PARSER_PROGRAMMATICALLY.md`](./USING_PARSER_PROGRAMMATICALLY.md)
421

5-
**You can contribute to those docs in [this separate repo](https://github.com/reasonml/reasonml.github.io)**
File renamed without changes.
File renamed without changes.

src/refmt/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ This package provides support for using Reason with native OCaml compilers.
1616

1717
Go to https://github.com/reasonml/reasonml.github.io to contribute to the Reason documentation.
1818

19-
### Codebase
19+
### Contributing
2020

21-
See the [src folder's README](https://github.com/facebook/reason/tree/master/src/README.md).
21+
See the [docs folder's `GETTING_STARTED_CONTRIBUTING.md`](../docs/GETTING_STARTED_CONTRIBUTING.md).

0 commit comments

Comments
 (0)