subscript 7.1.0 → 7.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,22 +62,20 @@ Default literals:
|
|
|
62
62
|
* `"abc"` strings
|
|
63
63
|
* `1.2e+3` numbers
|
|
64
64
|
|
|
65
|
-
Everything else can be extended via `unary
|
|
65
|
+
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.
|
|
66
66
|
|
|
67
67
|
```js
|
|
68
|
-
import script, { compile
|
|
68
|
+
import script, { compile } from './subscript.js'
|
|
69
69
|
|
|
70
70
|
// add ~ unary operator with precedence 15
|
|
71
|
-
|
|
71
|
+
script.set('~', 15, a => ~a)
|
|
72
72
|
|
|
73
73
|
// add === binary operator with precedence 9
|
|
74
|
-
|
|
74
|
+
script.set('===', 9, (a, b) => a===b)
|
|
75
75
|
|
|
76
76
|
// add literals
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
script(`true === false`)() // false
|
|
77
|
+
script.set('true', 20, [a => ['',true], a => ctx => a[1]])
|
|
78
|
+
script.set('false', 20, [a => ['',false], a => ctx => a[1]])
|
|
81
79
|
```
|
|
82
80
|
|
|
83
81
|
See [subscript.js](subscript.js) or [justin.js](./justin.js) for examples.
|