eyeling 1.24.2 → 1.24.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/see/see.js CHANGED
@@ -284,11 +284,28 @@ class Parser {
284
284
  eof() {
285
285
  return this.pos >= this.tokens.length;
286
286
  }
287
- peek(value = undefined) {
288
- const tok = this.tokens[this.pos];
287
+ peek(value = undefined, offset = 0) {
288
+ const tok = this.tokens[this.pos + offset];
289
289
  if (value === undefined) return tok;
290
290
  return tok && tok.type === value;
291
291
  }
292
+ isTermToken(tok) {
293
+ return tok && ['qname', 'iri', 'var', 'string', 'number', 'boolean', '<<(', '(', '{', '['].includes(tok.type);
294
+ }
295
+ isNamedGraphStart() {
296
+ const tok = this.peek();
297
+ if (tok?.type === 'qname' && /^GRAPH$/i.test(tok.value)) {
298
+ return this.isTermToken(this.peek(undefined, 1)) && this.peek('{', 2);
299
+ }
300
+ return (tok?.type === 'qname' || tok?.type === 'iri') && this.peek('{', 1);
301
+ }
302
+ parseNamedGraphFact() {
303
+ if (this.peek()?.type === 'qname' && /^GRAPH$/i.test(this.peek().value)) this.next();
304
+ const name = this.parseTerm('fact', []);
305
+ const atoms = this.parseFormula('fact');
306
+ this.accept('.');
307
+ return { s: name, p: I('log:nameOf'), o: { kind: 'formula', atoms } };
308
+ }
292
309
  next() {
293
310
  if (this.eof()) throw new Error('Unexpected end of input');
294
311
  return this.tokens[this.pos++];
@@ -338,6 +355,10 @@ class Parser {
338
355
  this.skipVersion();
339
356
  continue;
340
357
  }
358
+ if (this.isNamedGraphStart()) {
359
+ facts.push(this.parseNamedGraphFact());
360
+ continue;
361
+ }
341
362
  if (this.peek('{')) {
342
363
  const lhs = this.parseFormula('body');
343
364
  if (this.accept('=>')) {
@@ -366,6 +387,9 @@ class Parser {
366
387
  this.accept('.');
367
388
  rules.push({ kind: 'backward', id: rules.length + 1, body: rhs, head: lhs });
368
389
  }
390
+ } else if (this.peek('.') || this.eof()) {
391
+ this.accept('.');
392
+ facts.push(...lhs);
369
393
  } else {
370
394
  const subject = { kind: 'formula', atoms: lhs };
371
395
  const triples = this.parseStatementRest('fact', subject);
package/test/api.test.js CHANGED
@@ -2541,12 +2541,24 @@ _:b a ex:Person ; ex:name "B" .
2541
2541
  },
2542
2542
 
2543
2543
  {
2544
- name: 'RDF 1.2 triple terms are accepted as N3 singleton graph terms',
2544
+ name: 'RDF 1.2 triple terms require explicit RDF compatibility mode',
2545
2545
  opt: { proofComments: false },
2546
2546
  input: `VERSION "1.2"
2547
2547
  @prefix : <http://example.org/triple-terms#> .
2548
2548
  @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
2549
2549
 
2550
+ :observation rdf:reifies <<( :sensor :reports :overheating )>> .
2551
+ `,
2552
+ expectError: true,
2553
+ },
2554
+
2555
+ {
2556
+ name: 'RDF 1.2 triple terms are accepted in RDF compatibility mode',
2557
+ opt: { proofComments: false, rdf: true },
2558
+ input: `VERSION "1.2"
2559
+ @prefix : <http://example.org/triple-terms#> .
2560
+ @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
2561
+
2550
2562
  :observation rdf:reifies <<( :sensor :reports :overheating )>> .
2551
2563
  :overheating :requires :inspection .
2552
2564
 
@@ -2557,10 +2569,64 @@ _:b a ex:Person ; ex:name "B" .
2557
2569
  ?observation :entails <<( ?device :needs ?action )>> .
2558
2570
  } .
2559
2571
  `,
2560
- expect: [/:observation\s+:entails\s+\{\s+:sensor\s+:needs\s+:inspection\s*\.\s*\}\s*\./m],
2572
+ expect: [/:observation\s+:entails\s+<<\(\s+:sensor\s+:needs\s+:inspection\s*\)>>\s*\./m],
2573
+ },
2574
+
2575
+ {
2576
+ name: 'RDF mode serializes only valid triple terms as RDF 1.2 triple terms',
2577
+ opt: { proofComments: false, rdf: true },
2578
+ input: `@prefix log: <http://www.w3.org/2000/10/swap/log#> .
2579
+ @prefix math: <http://www.w3.org/2000/10/swap/math#> .
2580
+ @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
2581
+ @prefix : <http://example.org/ns#> .
2582
+
2583
+ {
2584
+ (1 3) math:sum ?X .
2585
+ }
2586
+ =>
2587
+ {
2588
+ <<(?X a :Answer)>> a :Result.
2589
+ }.
2590
+ `,
2591
+ expect: [/\{\s*4\s+a\s+:Answer\s*\.\s*\}\s+a\s+:Result\s*\./m],
2592
+ notExpect: [/<<\(\s*4\s+a\s+:Answer\s*\)>>/m],
2593
+ },
2594
+
2595
+ {
2596
+ name: 'RDF dataset named graphs round-trip as TriG in RDF compatibility mode',
2597
+ opt: { proofComments: false, rdf: true },
2598
+ input: `VERSION "1.2"
2599
+ @prefix : <http://example.org/dataset#> .
2600
+ @prefix log: <http://www.w3.org/2000/10/swap/log#> .
2601
+ @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
2602
+
2603
+ # Ordinary TriG default-graph triples remain ordinary N3 facts.
2604
+ :sensor :reports :overheating .
2605
+ :overheating :requires :inspection .
2606
+
2607
+ # A TriG named graph block is accepted and normalized to a graph term.
2608
+ :factoryDataset {
2609
+ :observation rdf:reifies <<( :sensor :reports :overheating )>> .
2610
+ }
2611
+
2612
+ {
2613
+ :sensor :reports ?condition .
2614
+ ?condition :requires ?action .
2615
+ } => {
2616
+ :workOrder :entails <<( :sensor :needs ?action )>> .
2617
+ :audit log:nameOf {
2618
+ :workOrder :basedOn :factoryDataset .
2619
+ } .
2620
+ } .
2621
+ `,
2622
+ expect: [
2623
+ /:workOrder\s+:entails\s+<<\(\s+:sensor\s+:needs\s+:inspection\s*\)>>\s*\./m,
2624
+ /:audit\s+\{[\s\S]*:workOrder\s+:basedOn\s+:factoryDataset\s*\.[\s\S]*\}/m,
2625
+ ],
2561
2626
  },
2562
2627
  ];
2563
2628
 
2629
+
2564
2630
  let passed = 0;
2565
2631
  let failed = 0;
2566
2632
 
package/test/see.test.js CHANGED
File without changes
package/tools/bundle.js CHANGED
File without changes
package/tools/n3gen.js CHANGED
File without changes