eyemind 0.5.30 → 0.5.32
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 -96
- package/SPEC.md +34 -90
- package/package.json +1 -1
- package/src/cli.js +2 -2
- package/src/closure.js +18 -38
- package/src/engine.js +3 -4
- package/src/fidelity.js +38 -196
- package/src/formats.js +0 -12
- package/src/index.js +0 -1
- package/src/n3-parser.js +6 -9
- package/src/proof.js +5 -8
- package/src/srl.js +1 -2
- package/src/version.js +1 -1
- package/src/native-proof.js +0 -316
package/src/native-proof.js
DELETED
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
// Native proof documents keep the complete compiled certificate as RDF data.
|
|
2
|
-
// Their formulas/triple terms are checked displays, never a second authority
|
|
3
|
-
// for the claims, bindings or search tables checked by C1–C10.
|
|
4
|
-
import { parseN3, RDF, XSD, typedLiteral } from './n3-parser.js';
|
|
5
|
-
import { writeN3 } from './n3-writer.js';
|
|
6
|
-
import { readTerms } from './reader.js';
|
|
7
|
-
import { Parser } from './srl-parser.js';
|
|
8
|
-
import { Env, EyemindError, Struct, Var, isTerm, listFromItems, properListItems } from './terms.js';
|
|
9
|
-
|
|
10
|
-
export const PROOF_NS = 'https://eyereasoner.github.io/pe#';
|
|
11
|
-
export const TERM_NS = 'https://eyereasoner.github.io/eyemind/proof#';
|
|
12
|
-
const ROOT = 'urn:eyemind:proof';
|
|
13
|
-
const iri = (value) => new Struct('iri', [value]);
|
|
14
|
-
const rdfText = (value) => [...value].every((c) => {
|
|
15
|
-
const n = c.codePointAt(0);
|
|
16
|
-
return n !== 0 && !(n >= 0xd800 && n <= 0xdfff) && (n & 0xfffe) !== 0xfffe;
|
|
17
|
-
});
|
|
18
|
-
const iriText = (value) => typeof value === 'string' && rdfText(value) && !/[\u0000-\u0020<>"{}|^`\\]/.test(value);
|
|
19
|
-
function literal(value) {
|
|
20
|
-
if (rdfText(value)) return new Struct('literal', [value, new Struct('datatype', [`${XSD}string`])]);
|
|
21
|
-
const hex = Array.from({ length: value.length }, (_, i) => value.charCodeAt(i).toString(16).padStart(4, '0')).join('');
|
|
22
|
-
return new Struct('literal', [hex, new Struct('datatype', [`${TERM_NS}utf16`])]);
|
|
23
|
-
}
|
|
24
|
-
const list = listFromItems;
|
|
25
|
-
const empty = new Env();
|
|
26
|
-
const records = new Set(['clause/2', 'step/4', 'derived/2', 'searched/2', 'called/2']);
|
|
27
|
-
const record = (term) => term instanceof Struct && records.has(`${term.name}/${term.args.length}`);
|
|
28
|
-
|
|
29
|
-
// Tagged collections preserve atoms, exact integers, floats (including -0),
|
|
30
|
-
// variable names and arbitrary compounds without embedding executable text.
|
|
31
|
-
function encode(term) {
|
|
32
|
-
if (term instanceof Var) return list([iri(`${TERM_NS}variable`), literal(term.name)]);
|
|
33
|
-
if (typeof term === 'string') return list([iri(`${TERM_NS}atom`), literal(term)]);
|
|
34
|
-
if (typeof term === 'bigint') return list([iri(`${TERM_NS}integer`), literal(String(term))]);
|
|
35
|
-
if (typeof term === 'number') return list([iri(`${TERM_NS}float`), literal(Object.is(term, -0) ? '-0' : String(term))]);
|
|
36
|
-
if (isTerm(term, 'iri', 1) && iriText(term.args[0])) return list([iri(`${TERM_NS}iri`), iri(term.args[0])]);
|
|
37
|
-
if (isTerm(term, '.', 2)) {
|
|
38
|
-
const items = properListItems(term, empty);
|
|
39
|
-
if (items !== null) return list([iri(`${TERM_NS}list`), list(items.map(encode))]);
|
|
40
|
-
}
|
|
41
|
-
if (term instanceof Struct) return list([iri(`${TERM_NS}compound`), literal(term.name), list(term.args.map(encode))]);
|
|
42
|
-
throw new EyemindError('a native proof record contains an unsupported term');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function native(term, format) {
|
|
46
|
-
if (typeof term === 'bigint' || (typeof term === 'number' && Number.isFinite(term)) || term === '[]') return true;
|
|
47
|
-
if (term instanceof Var) return format === 'n3' && /^[A-Za-z_][A-Za-z0-9_]*$/.test(term.name);
|
|
48
|
-
if (!(term instanceof Struct)) return false;
|
|
49
|
-
if (isTerm(term, 'iri', 1)) return iriText(term.args[0]);
|
|
50
|
-
if (isTerm(term, 'literal', 2)) {
|
|
51
|
-
const [value, annotation] = term.args;
|
|
52
|
-
return typeof value === 'string' && rdfText(value) && annotation instanceof Struct &&
|
|
53
|
-
((annotation.name === 'datatype' && annotation.args.length === 1 && iriText(annotation.args[0])) ||
|
|
54
|
-
(annotation.name === 'lang' && [1, 2].includes(annotation.args.length) && annotation.args.every((arg) => typeof arg === 'string' && /^[A-Za-z0-9-]+$/.test(arg))));
|
|
55
|
-
}
|
|
56
|
-
if (isTerm(term, 'bnode', 2) || isTerm(term, 'skolem', 3)) return true;
|
|
57
|
-
if (isTerm(term, 'qvar', 1) || isTerm(term, 'qbnode', 1)) return format === 'n3' && typeof term.args[0] === 'string';
|
|
58
|
-
if (isTerm(term, '.', 2)) {
|
|
59
|
-
const items = properListItems(term, empty);
|
|
60
|
-
return items !== null && items.every((item) => native(item, format));
|
|
61
|
-
}
|
|
62
|
-
if (isTerm(term, 'triple', 3)) return term.args.every((arg) => native(arg, format));
|
|
63
|
-
if (isTerm(term, 'graph', 1) && format === 'n3') {
|
|
64
|
-
const triples = properListItems(term.args[0], empty);
|
|
65
|
-
return triples !== null && triples.every((t) => isTerm(t, 'rdf', 3) && t.args.every((arg) => native(arg, format)));
|
|
66
|
-
}
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function view(term, format) {
|
|
71
|
-
if (term instanceof Struct && ['rdf', 'result', 'inf', 'base'].includes(term.name) &&
|
|
72
|
-
term.args.length === 3 && term.args.every((arg) => native(arg, format))) {
|
|
73
|
-
return format === 'n3' ? new Struct('graph', [list([new Struct('rdf', term.args)])]) : new Struct('triple', term.args);
|
|
74
|
-
}
|
|
75
|
-
return encode(term);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function graph(terms, format) {
|
|
79
|
-
const triples = [];
|
|
80
|
-
const add = (subject, predicate, object) => triples.push([iri(subject), iri(predicate), object]);
|
|
81
|
-
add(ROOT, `${RDF}type`, iri(`${PROOF_NS}Proof`));
|
|
82
|
-
add(ROOT, `${TERM_NS}format`, literal(format));
|
|
83
|
-
add(ROOT, `${PROOF_NS}claims`, list(terms.filter((term) => !record(term)).map((term) => view(term, format))));
|
|
84
|
-
terms.forEach((term, i) => {
|
|
85
|
-
const id = `${ROOT}#record${i + 1}`;
|
|
86
|
-
if (isTerm(term, 'step', 4)) {
|
|
87
|
-
const [goal, by, bindings, uses] = term.args;
|
|
88
|
-
add(id, `${PROOF_NS}conclusion`, view(goal, format));
|
|
89
|
-
if (isTerm(by, 'clause', 1)) add(id, `${PROOF_NS}rule`, by.args[0]);
|
|
90
|
-
else if (isTerm(by, 'source', 1)) add(id, `${PROOF_NS}source`, by.args[0]);
|
|
91
|
-
else add(id, `${PROOF_NS}justification`, encode(by));
|
|
92
|
-
const pairs = properListItems(bindings, empty);
|
|
93
|
-
const premises = properListItems(uses, empty);
|
|
94
|
-
if (pairs === null || premises === null || !pairs.every((pair) => isTerm(pair, '=', 2))) {
|
|
95
|
-
throw new EyemindError('a native proof step needs bindings and uses as lists');
|
|
96
|
-
}
|
|
97
|
-
add(id, `${PROOF_NS}binding`, list(pairs.map(({ args: [name, value] }) =>
|
|
98
|
-
list([literal(name), native(value, format) ? value : encode(value)]))));
|
|
99
|
-
add(id, `${PROOF_NS}uses`, list(premises.map((premise) => view(premise, format))));
|
|
100
|
-
} else if (term instanceof Struct && ['derived', 'searched', 'called'].includes(term.name) && term.args.length === 2) {
|
|
101
|
-
add(id, `${PROOF_NS}${term.name}`, view(term.args[0], format));
|
|
102
|
-
const answers = properListItems(term.args[1], empty);
|
|
103
|
-
if (answers === null) throw new EyemindError('a native proof certificate needs an answers list');
|
|
104
|
-
add(id, `${PROOF_NS}answers`, list(answers.map((answer) => view(answer, format))));
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
// Present the readable steps first; the full compiled certificate follows.
|
|
108
|
-
add(ROOT, `${TERM_NS}records`, list(terms.map((_, i) => iri(`${ROOT}#record${i + 1}`))));
|
|
109
|
-
terms.forEach((term, i) => add(`${ROOT}#record${i + 1}`, `${TERM_NS}term`, encode(term)));
|
|
110
|
-
return triples;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function render(terms, format, prefixes) {
|
|
114
|
-
const names = new Map(prefixes instanceof Map ? prefixes : Object.entries(prefixes ?? {}));
|
|
115
|
-
names.set('pe', PROOF_NS);
|
|
116
|
-
names.set('em', TERM_NS);
|
|
117
|
-
names.set('proof', `${ROOT}#`);
|
|
118
|
-
const text = writeN3(graph(terms, format), { prefixes: names, strings: false });
|
|
119
|
-
if (format === 'n3') return `# N3 proof: claims, steps and the complete C1–C10 certificate.\n${text}`;
|
|
120
|
-
const end = text.indexOf('\n\n');
|
|
121
|
-
const declarations = text.slice(0, end).split('\n').map((line) => line.slice(1, -2).replace(/^prefix /, 'PREFIX '));
|
|
122
|
-
// Do not indent or otherwise rewrite the body: long literals can contain
|
|
123
|
-
// newlines and text that itself looks like a prefix declaration.
|
|
124
|
-
return `# SRL proof: DATA only; claims, steps and the complete C1–C10 certificate.\n${declarations.join('\n')}\n\nDATA {\n${text.slice(end + 2)}}\n`;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export function writeNativeProof(document, { format = 'n3', prefixes = null } = {}) {
|
|
128
|
-
if (!['n3', 'srl'].includes(format)) throw new EyemindError('a native proof format must be n3 or srl');
|
|
129
|
-
return render(readTerms(document).map(([term]) => term), format, prefixes);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function fail(message) { throw new EyemindError(`native proof: ${message}`); }
|
|
133
|
-
function string(term) {
|
|
134
|
-
if (term?.t === 'literal' && term.dt === `${TERM_NS}utf16` && /^(?:[0-9a-f]{4})*$/.test(term.v)) {
|
|
135
|
-
return term.v.replace(/[0-9a-f]{4}/g, (hex) => String.fromCharCode(parseInt(hex, 16)));
|
|
136
|
-
}
|
|
137
|
-
if (term?.t !== 'literal' || term.dt !== `${XSD}string` || term.lang) fail('expected a plain string or em:utf16 literal');
|
|
138
|
-
return term.v;
|
|
139
|
-
}
|
|
140
|
-
function collection(term) {
|
|
141
|
-
if (term?.t !== 'list') fail('expected an RDF collection');
|
|
142
|
-
return term.items;
|
|
143
|
-
}
|
|
144
|
-
function decode(term) {
|
|
145
|
-
const items = collection(term);
|
|
146
|
-
const tag = items[0]?.t === 'iri' ? items[0].v.slice(TERM_NS.length) : '';
|
|
147
|
-
if (items[0]?.v !== `${TERM_NS}${tag}`) fail('unknown term tag');
|
|
148
|
-
if (tag === 'compound' && items.length === 3) return new Struct(string(items[1]), collection(items[2]).map(decode));
|
|
149
|
-
if (items.length !== 2) fail('a tagged term has the wrong number of fields');
|
|
150
|
-
if (tag === 'list') return list(collection(items[1]).map(decode));
|
|
151
|
-
if (tag === 'iri' && items[1]?.t === 'iri') return iri(items[1].v);
|
|
152
|
-
if (tag === 'iri' && items[1]?.t === 'list' && !items[1].items.length) return iri(`${RDF}nil`);
|
|
153
|
-
const value = string(items[1]);
|
|
154
|
-
if (tag === 'atom') return value;
|
|
155
|
-
if (tag === 'variable') return new Var(value);
|
|
156
|
-
if (tag === 'integer' && /^-?(?:0|[1-9][0-9]*)$/.test(value)) return BigInt(value);
|
|
157
|
-
if (tag === 'float' && value !== '' && Number.isFinite(Number(value))) return Number(value);
|
|
158
|
-
fail(`invalid ${tag} term`);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// SRL expands collection syntax into rdf:first/rest cells. Fold only closed,
|
|
162
|
-
// reachable, unambiguous lists back into the same data AST that N3 reads.
|
|
163
|
-
function srlData(document) {
|
|
164
|
-
const parsed = new Parser(document, { strictGrammar: true }).parseProgram();
|
|
165
|
-
if (parsed.rules.length || parsed.imports.length) fail('an SRL proof contains DATA, never RULE or IMPORTS');
|
|
166
|
-
const term = (t) => {
|
|
167
|
-
if (t.type === 'iri') return { t: 'iri', v: t.value };
|
|
168
|
-
if (t.type === 'blank') return { t: 'bnode', v: t.value, scope: 0 };
|
|
169
|
-
if (t.type === 'literal') {
|
|
170
|
-
// A displayed decimal must not lose digits before its record is
|
|
171
|
-
// compared: adjacent exact values can round to the same binary64.
|
|
172
|
-
const value = t.lexical ?? (Object.is(t.value, -0) ? '-0' : String(t.value));
|
|
173
|
-
return t.lang ? { t: 'literal', v: value, dt: `${RDF}langString`, lang: t.lang, dir: t.langDir }
|
|
174
|
-
: typedLiteral(value, t.datatype ?? `${XSD}string`, true);
|
|
175
|
-
}
|
|
176
|
-
if (t.type === 'triple') return { t: 'triple', s: term(t.s), p: term(t.p), o: term(t.o) };
|
|
177
|
-
fail('an SRL proof must be ground RDF data');
|
|
178
|
-
};
|
|
179
|
-
const triples = parsed.data.map((t) => ({ s: term(t.s), p: term(t.p), o: term(t.o) }));
|
|
180
|
-
const cells = new Map();
|
|
181
|
-
for (const t of triples) if (t.s.t === 'bnode' && [`${RDF}first`, `${RDF}rest`].includes(t.p.v)) {
|
|
182
|
-
if (!cells.has(t.s.v)) cells.set(t.s.v, new Map());
|
|
183
|
-
const cell = cells.get(t.s.v);
|
|
184
|
-
if (cell.has(t.p.v)) fail('duplicate collection link');
|
|
185
|
-
cell.set(t.p.v, t.o);
|
|
186
|
-
}
|
|
187
|
-
const used = new Set();
|
|
188
|
-
const expand = (t, ancestors = new Set()) => {
|
|
189
|
-
if (t.t === 'iri' && t.v === `${RDF}nil`) return { t: 'list', items: [] };
|
|
190
|
-
if (t.t === 'triple') return { ...t, s: expand(t.s, ancestors), p: expand(t.p, ancestors), o: expand(t.o, ancestors) };
|
|
191
|
-
if (t.t !== 'bnode' || !cells.has(t.v)) return t;
|
|
192
|
-
// Keep only the active path: copying all ancestors for each nested list
|
|
193
|
-
// makes a long list of encoded terms quadratic. Siblings may share cells.
|
|
194
|
-
const path = [];
|
|
195
|
-
const items = [];
|
|
196
|
-
while (t.t === 'bnode' && cells.has(t.v)) {
|
|
197
|
-
if (ancestors.has(t.v)) fail('cyclic collection');
|
|
198
|
-
ancestors.add(t.v);
|
|
199
|
-
path.push(t.v);
|
|
200
|
-
const cell = cells.get(t.v);
|
|
201
|
-
if (cell.size !== 2) fail('an RDF collection needs first and rest');
|
|
202
|
-
used.add(t.v);
|
|
203
|
-
items.push(expand(cell.get(`${RDF}first`), ancestors));
|
|
204
|
-
t = cell.get(`${RDF}rest`);
|
|
205
|
-
}
|
|
206
|
-
if (t.t !== 'iri' || t.v !== `${RDF}nil`) fail('an RDF collection must end in rdf:nil');
|
|
207
|
-
for (const id of path) ancestors.delete(id);
|
|
208
|
-
return { t: 'list', items };
|
|
209
|
-
};
|
|
210
|
-
const out = triples.filter((t) => !(t.s.t === 'bnode' && cells.has(t.s.v) && [`${RDF}first`, `${RDF}rest`].includes(t.p.v)))
|
|
211
|
-
.map((t) => ({ s: expand(t.s), p: expand(t.p), o: expand(t.o) }));
|
|
212
|
-
if (used.size !== cells.size) fail('unreferenced collection data');
|
|
213
|
-
return { triples: out };
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// Display comparison permits prefix changes, triple reordering and consistent
|
|
217
|
-
// blank-node renaming. Every property is checked, including claims and uses;
|
|
218
|
-
// an extra assertion or an altered display cannot bypass the certificate.
|
|
219
|
-
function compare(actual, expected) {
|
|
220
|
-
const properties = (triples) => {
|
|
221
|
-
const found = new Map();
|
|
222
|
-
for (const t of triples) {
|
|
223
|
-
if (t.s.t !== 'iri' || t.p.t !== 'iri') fail('unexpected assertion outside a proof record');
|
|
224
|
-
const key = JSON.stringify([t.s.v, t.p.v]);
|
|
225
|
-
if (found.has(key)) fail('duplicate proof property');
|
|
226
|
-
found.set(key, t.o);
|
|
227
|
-
}
|
|
228
|
-
return found;
|
|
229
|
-
};
|
|
230
|
-
const a = properties(actual);
|
|
231
|
-
const e = properties(expected);
|
|
232
|
-
if (a.size !== e.size) fail('missing or extra proof properties');
|
|
233
|
-
const names = new Map();
|
|
234
|
-
const reverse = new Map();
|
|
235
|
-
const same = (x, y) => {
|
|
236
|
-
if (!x || !y || x.t !== y.t) return false;
|
|
237
|
-
if (x.t === 'bnode') {
|
|
238
|
-
const kx = `${x.scope}:${x.v}`, ky = `${y.scope}:${y.v}`;
|
|
239
|
-
if (names.has(kx)) return names.get(kx) === ky;
|
|
240
|
-
if (reverse.has(ky)) return false;
|
|
241
|
-
names.set(kx, ky); reverse.set(ky, kx);
|
|
242
|
-
return true;
|
|
243
|
-
}
|
|
244
|
-
if (x.t === 'list') return x.items.length === y.items.length && x.items.every((t, i) => same(t, y.items[i]));
|
|
245
|
-
if (x.t === 'graph') return x.triples.length === y.triples.length && x.triples.every((t, i) => sameTriple(t, y.triples[i]));
|
|
246
|
-
if (x.t === 'triple') return sameTriple(x, y);
|
|
247
|
-
return Object.is(x.v, y.v) && x.dt === y.dt && (x.lang ?? null) === (y.lang ?? null) && (x.dir ?? null) === (y.dir ?? null);
|
|
248
|
-
};
|
|
249
|
-
const sameTriple = (x, y) => same(x.s, y.s) && same(x.p, y.p) && same(x.o, y.o);
|
|
250
|
-
for (const [key, value] of e) if (!same(a.get(key), value)) fail(`a displayed proof property differs from its record: ${key}`);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// Read the graph reconstructed from records with N3's direct collections,
|
|
254
|
-
// avoiding SRL's expansion into first/rest cells and folding them back again.
|
|
255
|
-
// SRL folds every rdf:nil, including an explicit IRI, to ().
|
|
256
|
-
function expectedData(terms, format) {
|
|
257
|
-
const parsed = parseN3(writeN3(graph(terms, format), { strings: false }), { preserveNumericLiterals: true });
|
|
258
|
-
if (format === 'n3') return parsed;
|
|
259
|
-
const fold = (t) => {
|
|
260
|
-
if (t.t === 'iri' && t.v === `${RDF}nil`) return { t: 'list', items: [] };
|
|
261
|
-
if (t.t === 'list') return { ...t, items: t.items.map(fold) };
|
|
262
|
-
if (t.t === 'triple') return { ...t, s: fold(t.s), p: fold(t.p), o: fold(t.o) };
|
|
263
|
-
return t;
|
|
264
|
-
};
|
|
265
|
-
return { triples: parsed.triples.map((t) => ({ s: fold(t.s), p: fold(t.p), o: fold(t.o) })) };
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
function readNative(document) {
|
|
269
|
-
let parsed, format;
|
|
270
|
-
try { parsed = parseN3(document, { preserveNumericLiterals: true }); format = 'n3'; }
|
|
271
|
-
catch (n3Error) {
|
|
272
|
-
try { parsed = srlData(document); format = 'srl'; }
|
|
273
|
-
catch (error) { throw new EyemindError(`native proof: ${error.message}`); }
|
|
274
|
-
}
|
|
275
|
-
const properties = new Map();
|
|
276
|
-
for (const t of parsed.triples) {
|
|
277
|
-
if (t.s.t !== 'iri' || t.p.t !== 'iri') fail('unexpected assertion outside a proof record');
|
|
278
|
-
const key = JSON.stringify([t.s.v, t.p.v]);
|
|
279
|
-
if (properties.has(key)) fail('duplicate proof record property');
|
|
280
|
-
properties.set(key, t.o);
|
|
281
|
-
}
|
|
282
|
-
const property = (subject, predicate) => {
|
|
283
|
-
const value = properties.get(JSON.stringify([subject, predicate]));
|
|
284
|
-
if (!value) fail('missing proof record property');
|
|
285
|
-
return value;
|
|
286
|
-
};
|
|
287
|
-
if (string(property(ROOT, `${TERM_NS}format`)) !== format) fail('proof format does not match its syntax');
|
|
288
|
-
const ids = collection(property(ROOT, `${TERM_NS}records`));
|
|
289
|
-
const terms = ids.map((id, i) => {
|
|
290
|
-
if (id.t !== 'iri' || id.v !== `${ROOT}#record${i + 1}`) fail('proof records must be numbered in document order');
|
|
291
|
-
return decode(property(id.v, `${TERM_NS}term`));
|
|
292
|
-
});
|
|
293
|
-
const expected = expectedData(terms, format);
|
|
294
|
-
compare(parsed.triples, expected.triples);
|
|
295
|
-
return terms;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
export function readNativeProof(document) {
|
|
299
|
-
try { return readNative(document); }
|
|
300
|
-
catch (error) {
|
|
301
|
-
if (error instanceof EyemindError) throw error;
|
|
302
|
-
throw new EyemindError(`native proof: ${error.message}`);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
// The command line reads an SRL proof's execution context before checking
|
|
307
|
-
// the same document, so the last native document read is kept.
|
|
308
|
-
let lastNative = null;
|
|
309
|
-
|
|
310
|
-
export function readProofTerms(document) {
|
|
311
|
-
if (/^\s*(?:#|@|PREFIX\b|BASE\b|DATA\b|<|_:)/i.test(document)) {
|
|
312
|
-
if (lastNative?.document !== document) lastNative = { document, terms: readNativeProof(document) };
|
|
313
|
-
return lastNative.terms.map((term) => [term, 0]);
|
|
314
|
-
}
|
|
315
|
-
return readTerms(document);
|
|
316
|
-
}
|