n3 2.8.0 → 2.9.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 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, where `onQuad`, `onPrefix` and `onComment` are used to listen for `quads`, `prefixes` and `comments` as follows:
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 (required) accepts a listener of type (quad: RDF.Quad) => void
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