eyemind 0.5.1 → 0.5.3
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 +46 -16
- package/SPEC.md +11 -1
- package/package.json +1 -1
- package/src/cli.js +37 -5
- package/src/formats.js +149 -0
- package/src/n3-builtins.js +622 -0
- package/src/n3-documents.js +75 -0
- package/src/n3-parser.js +465 -0
- package/src/n3-writer.js +203 -0
- package/src/n3.js +881 -0
- package/src/node.js +37 -0
- package/src/rdf-lexer.js +2024 -0
- package/src/rdf-parser.js +827 -0
- package/src/rdf-prelude.js +808 -0
- package/src/rdf-rules.js +106 -0
- package/src/rdf-syntax.js +249 -0
- package/src/rdf.js +429 -0
- package/src/srl-analyze.js +703 -0
- package/src/srl-assignments.js +40 -0
- package/src/srl-builtin-names.js +78 -0
- package/src/srl-functions.js +584 -0
- package/src/srl-parser.js +816 -0
- package/src/srl-term.js +288 -0
- package/src/srl-tokenizer.js +341 -0
- package/src/srl.js +649 -0
- package/src/version.js +1 -1
package/src/node.js
CHANGED
|
@@ -1,11 +1,48 @@
|
|
|
1
1
|
// What the program loader and the command line need from Node: files, and
|
|
2
2
|
// syntax errors with their line.
|
|
3
3
|
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { spawnSync } from 'node:child_process';
|
|
5
|
+
import { resolve } from 'node:path';
|
|
6
|
+
import { pathToFileURL } from 'node:url';
|
|
4
7
|
import vm from 'node:vm';
|
|
5
8
|
import { EyemindError } from './terms.js';
|
|
6
9
|
|
|
7
10
|
export const nodeIO = {
|
|
8
11
|
readFile: (path) => readFileSync(path, 'utf8'),
|
|
12
|
+
// The loader is synchronous. Fetch in a child before compilation, with
|
|
13
|
+
// bounds on its time and output; no I/O happens during proof checking.
|
|
14
|
+
readDocument(iri) {
|
|
15
|
+
if (!/^https?:/.test(iri)) throw new EyemindError('a remote document needs an HTTP or HTTPS IRI');
|
|
16
|
+
// The test suite pins remote inputs. A missing fixture is an error,
|
|
17
|
+
// so an offline run can never silently fall back to the network.
|
|
18
|
+
if (process.env.EYEMIND_N3_DOCUMENTS) {
|
|
19
|
+
const fixtures = JSON.parse(readFileSync(process.env.EYEMIND_N3_DOCUMENTS, 'utf8'));
|
|
20
|
+
const document = fixtures[iri.replace(/#.*$/, '')];
|
|
21
|
+
if (!document) throw new EyemindError(`no saved N3 document for ${iri}`);
|
|
22
|
+
if (document.error !== undefined) throw new EyemindError(document.error);
|
|
23
|
+
if (typeof document.text !== 'string') throw new EyemindError(`invalid saved N3 document for ${iri}`);
|
|
24
|
+
return document.text;
|
|
25
|
+
}
|
|
26
|
+
const child = spawnSync(process.execPath, ['--input-type=module', '-e', `
|
|
27
|
+
try {
|
|
28
|
+
const response = await fetch(process.argv[1], { signal: AbortSignal.timeout(10000) });
|
|
29
|
+
if (!response.ok) throw new Error('HTTP ' + response.status);
|
|
30
|
+
let size = 0;
|
|
31
|
+
for await (const chunk of response.body) {
|
|
32
|
+
size += chunk.byteLength;
|
|
33
|
+
if (size > 16 * 1024 * 1024) throw new Error('document exceeds 16 MiB');
|
|
34
|
+
process.stdout.write(chunk);
|
|
35
|
+
}
|
|
36
|
+
} catch (error) {
|
|
37
|
+
process.stderr.write(error.message);
|
|
38
|
+
process.exitCode = 1;
|
|
39
|
+
}
|
|
40
|
+
`, iri], { encoding: 'utf8', timeout: 11000, maxBuffer: 16 * 1024 * 1024 });
|
|
41
|
+
if (child.error || child.status !== 0) throw new EyemindError(child.error?.message ?? child.stderr.trim());
|
|
42
|
+
return child.stdout;
|
|
43
|
+
},
|
|
44
|
+
// The base IRI of a file, against which its relative IRIs resolve.
|
|
45
|
+
fileIri: (path) => (path === '<stdin>' ? null : pathToFileURL(resolve(path)).href),
|
|
9
46
|
checkSyntax(source, filename) {
|
|
10
47
|
try {
|
|
11
48
|
// Parsed only, never run: a script with the program's source.
|