Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
dy committed Apr 11, 2022
1 parent 1af2417 commit d3fec85
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,20 @@ Default literals:
* `"abc"` strings
* `1.2e+3` numbers

Everything else can be extended via `unary`, `binary` or `nary` for operators, or via `token(str, prec, parse, compile)` for custom tokens.
Everything else can be extended via `subscript.set(str, prec, fn)` for unary, binary or n-ary operators (detected by number of arguments in `fn`), or via `subscript.set(str, prec, [parse, compile])` for custom tokens.

```js
import script, { compile, unary, nary, binary, token } from './subscript.js'
import script, { compile } from './subscript.js'

// add ~ unary operator with precedence 15
unary('~', 15, a => ~a)
script.set('~', 15, a => ~a)

// add === binary operator with precedence 9
binary('===', 9, (a, b) => a===b)
script.set('===', 9, (a, b) => a===b)

// add literals
token('true', 20, a => ['',true], a => ctx => a[1])
token('false', 20, a => ['',false], a => ctx => a[1])

script(`true === false`)() // false
script.set('true', 20, [a => ['',true], a => ctx => a[1]])
script.set('false', 20, [a => ['',false], a => ctx => a[1]])
```

See [subscript.js](subscript.js) or [justin.js](./justin.js) for examples.
Expand Down

0 comments on commit d3fec85

Please sign in to comment.