n3 2.8.0 → 2.9.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 +13 -2
- package/browser/n3.esm.min.js +7 -7
- package/browser/n3.min.js +7 -7
- package/lib/N3Parser.js +42 -21
- package/package.json +1 -1
- package/src/N3Parser.js +47 -26
package/README.md
CHANGED
|
@@ -129,12 +129,12 @@ the callback is invoked one last time with `null` for `quad`
|
|
|
129
129
|
and a hash of prefixes as third argument.
|
|
130
130
|
<br>
|
|
131
131
|
|
|
132
|
-
Alternatively, an object can be supplied
|
|
132
|
+
Alternatively, an object can be supplied with named callbacks for quads, prefixes, comments, and token processing:
|
|
133
133
|
```JavaScript
|
|
134
134
|
const parser = new N3.Parser();
|
|
135
135
|
|
|
136
136
|
parser.parse(tomAndJerry, {
|
|
137
|
-
// onQuad (
|
|
137
|
+
// onQuad (optional) receives errors, quads, and completion
|
|
138
138
|
onQuad: (err, quad) => { console.log(quad); },
|
|
139
139
|
// onPrefix (optional) accepts a listener of type (prefix: string, iri: NamedNode) => void
|
|
140
140
|
onPrefix: (prefix, iri) => { console.log(prefix, 'expands to', iri.value); },
|
|
@@ -143,6 +143,17 @@ parser.parse(tomAndJerry, {
|
|
|
143
143
|
});
|
|
144
144
|
```
|
|
145
145
|
|
|
146
|
+
`onToken(token)` runs immediately before a lexer token is processed, and
|
|
147
|
+
`onTokenEnd(token)` runs immediately afterwards, including when processing throws.
|
|
148
|
+
|
|
149
|
+
```JavaScript
|
|
150
|
+
const tokens = [];
|
|
151
|
+
const quads = parser.parse('<a> <b> "hello"@en.', {
|
|
152
|
+
onToken: token => tokens.push(token),
|
|
153
|
+
onTokenEnd: token => { /* Finish per-token bookkeeping here. */ },
|
|
154
|
+
});
|
|
155
|
+
```
|
|
156
|
+
|
|
146
157
|
If no callbacks are provided, parsing happens synchronously returning an array of quads:
|
|
147
158
|
|
|
148
159
|
```JavaScript
|