ohm-js 17.0.3 → 17.1.0-pre
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 +14 -14
- package/dist/ohm-extras.cjs +5370 -2
- package/dist/ohm-extras.js +5370 -2
- package/dist/ohm.cjs +3 -2
- package/dist/ohm.cjs.map +1 -1
- package/dist/ohm.js +4 -3
- package/dist/ohm.min.js +1 -1
- package/extras/extractExamples.js +160 -0
- package/extras/index.d.ts +15 -0
- package/extras/index.mjs +1 -0
- package/extras/ohm-with-examples.ohm +46 -0
- package/package.json +27 -26
- package/src/Semantics.js +1 -1
- package/src/main.js +4 -0
- package/src/ohm-cmd.js +0 -0
- package/src/version.js +1 -1
- package/LICENSE +0 -21
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# [Ohm](https://ohmjs.org/) · [](https://www.npmjs.com/package/ohm-js)  · [](https://www.npmjs.com/package/ohm-js)  [](https://discord.gg/KwxY5gegRQ)
|
|
2
2
|
|
|
3
3
|
Ohm is a parsing toolkit consisting of a library and a domain-specific language. You can use it to parse custom file formats or quickly build parsers, interpreters, and compilers for programming languages.
|
|
4
4
|
|
|
@@ -31,10 +31,10 @@ The easiest way to get started with Ohm is to use the [interactive editor](https
|
|
|
31
31
|
### Resources
|
|
32
32
|
|
|
33
33
|
- Tutorial: [Ohm: Parsing Made Easy](https://nextjournal.com/dubroy/ohm-parsing-made-easy)
|
|
34
|
-
- The [math example](examples/math/index.html) is extensively commented and is a good way to dive deeper.
|
|
35
|
-
- [Examples](examples/)
|
|
34
|
+
- The [math example](https://github.com/ohmjs/ohm/tree/main/examples/math/index.html) is extensively commented and is a good way to dive deeper.
|
|
35
|
+
- [Examples](https://github.com/ohmjs/ohm/tree/main/examples/)
|
|
36
36
|
- [Documentation](doc/README.md)
|
|
37
|
-
- For community support and discussion, join us on [Discord](https://discord.gg/KwxY5gegRQ), [GitHub Discussions](https://github.com/
|
|
37
|
+
- For community support and discussion, join us on [Discord](https://discord.gg/KwxY5gegRQ), [GitHub Discussions](https://github.com/ohmjs/ohm/discussions), or the [ohm-discuss mailing list](https://groups.google.com/u/0/g/ohm-discuss).
|
|
38
38
|
- For updates, follow [@\_ohmjs on Twitter](https://twitter.com/_ohmjs).
|
|
39
39
|
|
|
40
40
|
### Installation
|
|
@@ -45,14 +45,14 @@ To use Ohm in the browser, just add a single `<script>` tag to your page:
|
|
|
45
45
|
|
|
46
46
|
```html
|
|
47
47
|
<!-- Development version of Ohm from unpkg.com -->
|
|
48
|
-
<script src="https://unpkg.com/ohm-js@
|
|
48
|
+
<script src="https://unpkg.com/ohm-js@17/dist/ohm.js"></script>
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
or
|
|
52
52
|
|
|
53
53
|
```html
|
|
54
54
|
<!-- Minified version, for faster page loads -->
|
|
55
|
-
<script src="https://unpkg.com/ohm-js@
|
|
55
|
+
<script src="https://unpkg.com/ohm-js@17/dist/ohm.min.js"></script>
|
|
56
56
|
```
|
|
57
57
|
|
|
58
58
|
This creates a global variable named `ohm`.
|
|
@@ -75,10 +75,10 @@ Then, you can use `require` to use Ohm in a script:
|
|
|
75
75
|
const ohm = require('ohm-js');
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
Ohm can also be imported as an ES module:
|
|
79
79
|
|
|
80
80
|
```js
|
|
81
|
-
import ohm from 'ohm-js';
|
|
81
|
+
import * as ohm from 'ohm-js';
|
|
82
82
|
```
|
|
83
83
|
|
|
84
84
|
#### Deno
|
|
@@ -86,14 +86,14 @@ import ohm from 'ohm-js';
|
|
|
86
86
|
To use Ohm from [Deno](https://deno.land/):
|
|
87
87
|
|
|
88
88
|
```js
|
|
89
|
-
import ohm from 'https://unpkg.com/ohm-js@
|
|
89
|
+
import * as ohm from 'https://unpkg.com/ohm-js@17';
|
|
90
90
|
```
|
|
91
91
|
|
|
92
92
|
### Basics
|
|
93
93
|
|
|
94
94
|
#### Defining Grammars
|
|
95
95
|
|
|
96
|
-

|
|
97
97
|
|
|
98
98
|
To use Ohm, you need a grammar that is written in the Ohm language. The grammar provides a formal
|
|
99
99
|
definition of the language or data format that you want to parse. There are a few different ways
|
|
@@ -131,7 +131,7 @@ For more information, see [Instantiating Grammars](doc/api-reference.md#instanti
|
|
|
131
131
|
|
|
132
132
|
#### Using Grammars
|
|
133
133
|
|
|
134
|
-

|
|
135
135
|
|
|
136
136
|
<!-- @markscript
|
|
137
137
|
// The duplication here is required because Markscript only executes top-level code blocks.
|
|
@@ -159,11 +159,11 @@ For more information, see the [main documentation](doc/README.md).
|
|
|
159
159
|
|
|
160
160
|
Ohm has two tools to help you debug grammars: a text trace, and a graphical visualizer.
|
|
161
161
|
|
|
162
|
-
[](https://ohmjs.org/editor)
|
|
163
163
|
|
|
164
164
|
You can [try the visualizer online](https://ohmjs.org/editor).
|
|
165
165
|
|
|
166
|
-
To see the text trace for a grammar `g`, just use the [`g.trace()`](
|
|
166
|
+
To see the text trace for a grammar `g`, just use the [`g.trace()`](doc/api-reference.md#trace)
|
|
167
167
|
method instead of `g.match`. It takes the same arguments, but instead of returning a MatchResult
|
|
168
168
|
object, it returns a Trace object — calling its `toString` method returns a string describing
|
|
169
169
|
all of the decisions the parser made when trying to match the input. For example, here is the
|
|
@@ -203,4 +203,4 @@ our [suggestions for publishing grammars](./doc/publishing-grammars.md).
|
|
|
203
203
|
## Contributing to Ohm
|
|
204
204
|
|
|
205
205
|
Interested in contributing to Ohm? Please read [CONTRIBUTING.md](./CONTRIBUTING.md)
|
|
206
|
-
and the [Ohm Contributor Guide](
|
|
206
|
+
and the [Ohm Contributor Guide](doc/contributing.md).
|