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

Replace itt example with modern js example #147

Merged
merged 1 commit into from
Oct 19, 2020
Merged
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
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,10 @@ Keywords can also have **individual types**.
lexer.next() // -> { type: 'name', value: 'foo' }
```

You can use [itt](https://github.com/nathan/itt)'s iterator adapters to make constructing keyword objects easier:
You can use `Object.fromEntries` to easily construct keyword objects:

```js
itt(['class', 'def', 'if'])
.map(k => ['kw-' + k, k])
.toObject()
Object.fromEntries(['class', 'def', 'if'].map(k => ['kw-' + k, k]))
```


Expand Down Expand Up @@ -350,10 +348,10 @@ Create an array of tokens.
let tokens = Array.from(lexer);
```

Use [itt](https://github.com/nathan/itt)'s iteration tools with Moo.
Use [itt](https://www.npmjs.com/package/itt)'s iteration tools with Moo.

```js
for (let [here, next] = itt(lexer).lookahead()) { // pass a number if you need more tokens
for (let [here, next] of itt(lexer).lookahead()) { // pass a number if you need more tokens
// enjoy!
}
```
Expand Down