Merge pull request #2190 from tree-sitter/fix-docs
chore(docs): fix misprint repetitions and remove dangling spaces
This commit is contained in:
commit
9ccfd648c9
3 changed files with 10 additions and 10 deletions
|
|
@ -46,7 +46,7 @@ npm install --save nan
|
|||
npm install --save-dev tree-sitter-cli
|
||||
```
|
||||
|
||||
The last command will install the CLI into the `node_modules` folder in your working directory. An executable program called `tree-sitter` will be created inside of `node_modules/.bin/`. You may want to follow the Node.js convention of adding that folder to your your `PATH` so that you can easily run this program when working in this directory.
|
||||
The last command will install the CLI into the `node_modules` folder in your working directory. An executable program called `tree-sitter` will be created inside of `node_modules/.bin/`. You may want to follow the Node.js convention of adding that folder to your `PATH` so that you can easily run this program when working in this directory.
|
||||
|
||||
```sh
|
||||
# In your shell profile script
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ The `tree-sitter` CLI's most important feature is the `generate` subcommand. Thi
|
|||
|
||||
### Parsing a Grammar
|
||||
|
||||
First, Tree-sitter must must evaluate the JavaScript code in `grammar.js` and convert the grammar to a JSON format. It does this by shelling out to `node`. The format of the grammars is formally specified by the JSON schema in [grammar-schema.json](https://github.com/tree-sitter/tree-sitter/blob/master/cli/src/generate/grammar-schema.json). The parsing is implemented in [parse_grammar.rs](https://github.com/tree-sitter/tree-sitter/blob/master/cli/src/generate/parse_grammar.rs).
|
||||
First, Tree-sitter must evaluate the JavaScript code in `grammar.js` and convert the grammar to a JSON format. It does this by shelling out to `node`. The format of the grammars is formally specified by the JSON schema in [grammar-schema.json](https://github.com/tree-sitter/tree-sitter/blob/master/cli/src/generate/grammar-schema.json). The parsing is implemented in [parse_grammar.rs](https://github.com/tree-sitter/tree-sitter/blob/master/cli/src/generate/parse_grammar.rs).
|
||||
|
||||
### Grammar Rules
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ WebAssembly bindings to the [Tree-sitter](https://github.com/tree-sitter/tree-si
|
|||
|
||||
### Setup
|
||||
|
||||
You can download the the `tree-sitter.js` and `tree-sitter.wasm` files from [the latest GitHub release](https://github.com/tree-sitter/tree-sitter/releases/latest) and load them using a standalone script:
|
||||
You can download the `tree-sitter.js` and `tree-sitter.wasm` files from [the latest GitHub release](https://github.com/tree-sitter/tree-sitter/releases/latest) and load them using a standalone script:
|
||||
|
||||
```html
|
||||
<script src="/the/path/to/tree-sitter.js"/>
|
||||
|
|
@ -116,7 +116,7 @@ First install `tree-sitter-cli` and the tree-sitter language for which to genera
|
|||
npm install --save-dev tree-sitter-cli tree-sitter-javascript
|
||||
```
|
||||
|
||||
Then just use tree-sitter cli tool to generate the `.wasm`.
|
||||
Then just use tree-sitter cli tool to generate the `.wasm`.
|
||||
|
||||
```sh
|
||||
npx tree-sitter build-wasm node_modules/tree-sitter-javascript
|
||||
|
|
@ -147,13 +147,13 @@ const Parser = require('web-tree-sitter');
|
|||
|
||||
##### Loading the .wasm file
|
||||
|
||||
`web-tree-sitter` needs to load the `tree-sitter.wasm` file. By default, it assumes that this file is available in the
|
||||
`web-tree-sitter` needs to load the `tree-sitter.wasm` file. By default, it assumes that this file is available in the
|
||||
same path as the JavaScript code. Therefore, if the code is being served from `http://localhost:3000/bundle.js`, then
|
||||
the wasm file should be at `http://localhost:3000/tree-sitter.wasm`.
|
||||
|
||||
For server side frameworks like NextJS, this can be tricky as pages are often served from a path such as
|
||||
For server side frameworks like NextJS, this can be tricky as pages are often served from a path such as
|
||||
`http://localhost:3000/_next/static/chunks/pages/index.js`. The loader will therefore look for the wasm file at
|
||||
`http://localhost:3000/_next/static/chunks/pages/tree-sitter.wasm`. The solution is to pass a `locateFile` function in
|
||||
`http://localhost:3000/_next/static/chunks/pages/tree-sitter.wasm`. The solution is to pass a `locateFile` function in
|
||||
the `moduleOptions` argument to `Parser.init()`:
|
||||
|
||||
```javascript
|
||||
|
|
@ -164,15 +164,15 @@ await Parser.init({
|
|||
});
|
||||
```
|
||||
|
||||
`locateFile` takes in two parameters, `scriptName`, i.e. the wasm file name, and `scriptDirectory`, i.e. the directory
|
||||
`locateFile` takes in two parameters, `scriptName`, i.e. the wasm file name, and `scriptDirectory`, i.e. the directory
|
||||
where the loader expects the script to be. It returns the path where the loader will look for the wasm file. In the NextJS
|
||||
case, we want to return just the `scriptName` so that the loader will look at `http://localhost:3000/tree-sitter.wasm`
|
||||
and not `http://localhost:3000/_next/static/chunks/pages/tree-sitter.wasm`.
|
||||
|
||||
##### `Can't resolve 'fs' in 'node_modules/web-tree-sitter'`
|
||||
|
||||
Most bundlers will notice that the `tree-sitter.js` file is attempting to import `fs`, i.e. node's file system library.
|
||||
Since this doesn't exist in the browser, the bundlers will get confused. For webpack you can fix this by adding the
|
||||
Most bundlers will notice that the `tree-sitter.js` file is attempting to import `fs`, i.e. node's file system library.
|
||||
Since this doesn't exist in the browser, the bundlers will get confused. For webpack you can fix this by adding the
|
||||
following to your webpack config:
|
||||
|
||||
```javascript
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue