inequality-grammar 1.1.0 → 1.2.0
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 +38 -38
- package/dist/inequality-grammar.js +1 -2097
- package/package.json +40 -36
package/README.md
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
# Inequality grammar
|
|
2
|
-
|
|
3
|
-
A grammar to parse linear-text maths and boolean expressions, and produce an AST
|
|
4
|
-
that [Inequality](https://github.com/isaacphysics/inequality) can digest.
|
|
5
|
-
|
|
6
|
-
## Usage
|
|
7
|
-
|
|
8
|
-
npm i --save inequality-grammar
|
|
9
|
-
|
|
10
|
-
```javascript
|
|
11
|
-
import { parseMathsExpression } from 'inequality-grammar';
|
|
12
|
-
|
|
13
|
-
// Use parseBooleanExpression for Boolean algebra.
|
|
14
|
-
try {
|
|
15
|
-
const output = parseMathsExpression(this.mathInput);
|
|
16
|
-
enjoy(output);
|
|
17
|
-
} catch (error) {
|
|
18
|
-
// Handle error
|
|
19
|
-
}
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
## Documentation
|
|
23
|
-
|
|
24
|
-
This parser turns linear-text maths and boolean expressions into the
|
|
25
|
-
left-to-right AST format used by [Inequality](https://github.com/isaacphysics/inequality).
|
|
26
|
-
For more information on the AST, please refer to Inequality's documentation.
|
|
27
|
-
|
|
28
|
-
This parser is based on [nearley.js](https://nearley.js.org/), a parser toolkit
|
|
29
|
-
for JavaScript. Nearley uses the [Earley algorithm](https://en.wikipedia.org/wiki/Earley_parser)
|
|
30
|
-
plus clever optimizations to process expressions with high efficiency and low
|
|
31
|
-
computational effort -- if the grammar rules are specified the right way.
|
|
32
|
-
|
|
33
|
-
The two grammars are found in the `assets` folders and contain inline
|
|
34
|
-
documentation. Some of the processing functions may seem complicated but this is
|
|
35
|
-
primarily due to the left-to-right nature of the AST they need to produce.
|
|
36
|
-
Keeping track of the tokens produced by each rule is essential to understand
|
|
37
|
-
the processing functions, but not the easiest thing. Take it slowly and
|
|
38
|
-
everything will eventually make sense.
|
|
1
|
+
# Inequality grammar
|
|
2
|
+
|
|
3
|
+
A grammar to parse linear-text maths and boolean expressions, and produce an AST
|
|
4
|
+
that [Inequality](https://github.com/isaacphysics/inequality) can digest.
|
|
5
|
+
|
|
6
|
+
## Usage
|
|
7
|
+
|
|
8
|
+
npm i --save inequality-grammar
|
|
9
|
+
|
|
10
|
+
```javascript
|
|
11
|
+
import { parseMathsExpression } from 'inequality-grammar';
|
|
12
|
+
|
|
13
|
+
// Use parseBooleanExpression for Boolean algebra.
|
|
14
|
+
try {
|
|
15
|
+
const output = parseMathsExpression(this.mathInput);
|
|
16
|
+
enjoy(output);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
// Handle error
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Documentation
|
|
23
|
+
|
|
24
|
+
This parser turns linear-text maths and boolean expressions into the
|
|
25
|
+
left-to-right AST format used by [Inequality](https://github.com/isaacphysics/inequality).
|
|
26
|
+
For more information on the AST, please refer to Inequality's documentation.
|
|
27
|
+
|
|
28
|
+
This parser is based on [nearley.js](https://nearley.js.org/), a parser toolkit
|
|
29
|
+
for JavaScript. Nearley uses the [Earley algorithm](https://en.wikipedia.org/wiki/Earley_parser)
|
|
30
|
+
plus clever optimizations to process expressions with high efficiency and low
|
|
31
|
+
computational effort -- if the grammar rules are specified the right way.
|
|
32
|
+
|
|
33
|
+
The two grammars are found in the `assets` folders and contain inline
|
|
34
|
+
documentation. Some of the processing functions may seem complicated but this is
|
|
35
|
+
primarily due to the left-to-right nature of the AST they need to produce.
|
|
36
|
+
Keeping track of the tokens produced by each rule is essential to understand
|
|
37
|
+
the processing functions, but not the easiest thing. Take it slowly and
|
|
38
|
+
everything will eventually make sense.
|