eyeling 1.26.0 → 1.26.2
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/dist/browser/eyeling.browser.js +247 -314
- package/examples/proof/age.n3 +14 -5
- package/examples/proof/socrates.n3 +7 -2
- package/examples/proof/witch.n3 +27 -9
- package/eyeling.js +247 -314
- package/lib/cli.js +2 -2
- package/lib/engine.js +130 -216
- package/lib/explain.js +98 -79
- package/lib/multisource.js +17 -17
- package/package.json +1 -1
package/lib/multisource.js
CHANGED
|
@@ -32,20 +32,20 @@ function emptyParsedDocument() {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
function lineStartsForText(text) {
|
|
35
|
-
const s = String(text);
|
|
36
35
|
const starts = [0];
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
starts.push(i + 1);
|
|
36
|
+
const str = String(text);
|
|
37
|
+
for (let i = 0; i < str.length; i++) {
|
|
38
|
+
const c = str[i];
|
|
39
|
+
if (c === '\n') starts.push(i + 1);
|
|
40
|
+
else if (c === '\r') {
|
|
41
|
+
starts.push(i + 1 < str.length && str[i + 1] === '\n' ? i + 2 : i + 1);
|
|
42
|
+
if (i + 1 < str.length && str[i + 1] === '\n') i++;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
return starts;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
function
|
|
48
|
+
function offsetToLine(lineStarts, offset) {
|
|
49
49
|
if (typeof offset !== 'number') return null;
|
|
50
50
|
let lo = 0;
|
|
51
51
|
let hi = lineStarts.length;
|
|
@@ -57,9 +57,9 @@ function offsetToLineFromStarts(offset, lineStarts) {
|
|
|
57
57
|
return lo + 1;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
function annotateSourceLocation(obj,
|
|
60
|
+
function annotateSourceLocation(obj, lineStarts, label) {
|
|
61
61
|
if (!obj || typeof obj.__sourceOffset !== 'number') return obj;
|
|
62
|
-
const line =
|
|
62
|
+
const line = offsetToLine(lineStarts, obj.__sourceOffset);
|
|
63
63
|
Object.defineProperty(obj, '__source', {
|
|
64
64
|
value: { label, line },
|
|
65
65
|
enumerable: false,
|
|
@@ -71,10 +71,10 @@ function annotateSourceLocation(obj, label, lineStarts) {
|
|
|
71
71
|
|
|
72
72
|
function annotateParsedSourceLocations(doc, text, label) {
|
|
73
73
|
const lineStarts = lineStartsForText(text);
|
|
74
|
-
for (const tr of doc.triples || []) annotateSourceLocation(tr,
|
|
75
|
-
for (const r of doc.frules || []) annotateSourceLocation(r,
|
|
76
|
-
for (const r of doc.brules || []) annotateSourceLocation(r,
|
|
77
|
-
for (const r of doc.logQueryRules || []) annotateSourceLocation(r,
|
|
74
|
+
for (const tr of doc.triples || []) annotateSourceLocation(tr, lineStarts, label);
|
|
75
|
+
for (const r of doc.frules || []) annotateSourceLocation(r, lineStarts, label);
|
|
76
|
+
for (const r of doc.brules || []) annotateSourceLocation(r, lineStarts, label);
|
|
77
|
+
for (const r of doc.logQueryRules || []) annotateSourceLocation(r, lineStarts, label);
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
function copySourceMetadata(from, to) {
|
|
@@ -169,7 +169,7 @@ function parseN3Text(text, opts = {}) {
|
|
|
169
169
|
label = '<input>',
|
|
170
170
|
keepSourceArtifacts = true,
|
|
171
171
|
collectUsedPrefixes = false,
|
|
172
|
-
|
|
172
|
+
sourceLocations = false,
|
|
173
173
|
rdf = false,
|
|
174
174
|
} = opts || {};
|
|
175
175
|
const tokens = lex(text, { rdf });
|
|
@@ -178,7 +178,7 @@ function parseN3Text(text, opts = {}) {
|
|
|
178
178
|
const [prefixes, triples, frules, brules, logQueryRules] = parser.parseDocument();
|
|
179
179
|
|
|
180
180
|
const doc = { prefixes, triples, frules, brules, logQueryRules, label };
|
|
181
|
-
if (
|
|
181
|
+
if (sourceLocations) annotateParsedSourceLocations(doc, text, label);
|
|
182
182
|
|
|
183
183
|
if (collectUsedPrefixes) {
|
|
184
184
|
Object.defineProperty(doc, 'usedPrefixes', {
|
|
@@ -369,8 +369,8 @@ function parseN3SourceList(input, opts = {}) {
|
|
|
369
369
|
label: source.label,
|
|
370
370
|
baseIri: source.baseIri || (sources.length === 1 ? defaultBaseIri : ''),
|
|
371
371
|
collectUsedPrefixes: true,
|
|
372
|
-
collectSourceLocations: !!opts.collectSourceLocations,
|
|
373
372
|
keepSourceArtifacts: !!opts.keepSourceArtifacts,
|
|
373
|
+
sourceLocations: !!opts.sourceLocations,
|
|
374
374
|
rdf: !!opts.rdf,
|
|
375
375
|
}),
|
|
376
376
|
);
|