Skip to content

Commit d27b920

Browse files
committed
feat: turtle-star spec tests are passing
1 parent 624e3e1 commit d27b920

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

src/N3Parser.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export default class N3Parser {
199199
case '(':
200200
// Lists are not allowed inside quoted triples
201201
if (this._contextStack.length > 0 && this._contextStack[this._contextStack.length - 1].type === '<<') {
202-
return this._error(`Unexpected list inside quoted triple`, token);
202+
return this._error('Unexpected list inside quoted triple', token);
203203
}
204204
// Start a new list
205205
this._saveContext('list', this._graph, this.RDF_NIL, null, null);
@@ -321,7 +321,7 @@ export default class N3Parser {
321321
case '(':
322322
// Lists are not allowed inside quoted triples
323323
if (this._contextStack.length > 0 && this._contextStack[this._contextStack.length - 1].type === '<<') {
324-
return this._error(`Unexpected list inside quoted triple`, token);
324+
return this._error('Unexpected list inside quoted triple', token);
325325
}
326326
// Start a new list
327327
this._saveContext('list', this._graph, this._subject, this._predicate, this.RDF_NIL);
@@ -370,9 +370,11 @@ export default class N3Parser {
370370
if (token.type === ']') {
371371
this._subject = null;
372372
return this._readBlankNodeTail(token);
373-
} else if (this._contextStack.length > 1 && this._contextStack[this._contextStack.length - 2].type === '<<') {
374-
return this._error('Compound blank node expressions not permitted within quoted triples', token)
375-
} else {
373+
}
374+
else if (this._contextStack.length > 1 && this._contextStack[this._contextStack.length - 2].type === '<<') {
375+
return this._error('Compound blank node expressions not permitted within quoted triples', token);
376+
}
377+
else {
376378
this._predicate = null;
377379
return this._readPredicate(token);
378380
}
@@ -896,10 +898,21 @@ export default class N3Parser {
896898

897899
// ### `_readRDFStarTail` reads the end of a nested RDF* triple
898900
_readAnnotatedTail(token) {
899-
this._emit(this._subject, this._predicate, this._object, this._graph);
900901
// if (this._subject && this._predicate && this._object) {
901902
// this._emit(this._subject, this._predicate, this._object, this._graph);
902903
// }
904+
if (token.type === '{|') {
905+
this._saveContext('{|', this._graph, this._subject, this._predicate, this._object);
906+
907+
// Note - we always use the default graph for the quoted triple component
908+
this._subject = this._quad(this._subject, this._predicate, this._object, this.DEFAULTGRAPH);
909+
this._predicate = null;
910+
this._object = null;
911+
return this._readPredicate;
912+
} else {
913+
this._emit(this._subject, this._predicate, this._object, this._graph);
914+
}
915+
903916
if (token.type !== '|}')
904917
return this._readPredicate;
905918
this._restoreContext('{|', token);

test/N3Parser-test.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ describe('Parser', () => {
11301130
shouldNotParse('<< () <a> <b> >> <c> <d>.',
11311131
'Unexpected list inside quoted triple on line 1.'
11321132
));
1133-
1133+
11341134
it('should not parse non-empty list inside quoted triple subject',
11351135
shouldNotParse('<< ( <f> ) <a> <b> >> <c> <d>.',
11361136
'Unexpected list inside quoted triple on line 1.'
@@ -1140,7 +1140,7 @@ describe('Parser', () => {
11401140
shouldNotParse('<< <a> () <b> >> <c> <d>.',
11411141
'Expected entity but got ( on line 1.'
11421142
));
1143-
1143+
11441144
it('should not parse non-empty list inside quoted triple predicate',
11451145
shouldNotParse('<< <a> ( <f> ) <b> >> <c> <d>.',
11461146
'Expected entity but got ( on line 1.'
@@ -1150,7 +1150,7 @@ describe('Parser', () => {
11501150
shouldNotParse('<< <a> <b> () >> <c> <d>.',
11511151
'Unexpected list inside quoted triple on line 1.'
11521152
));
1153-
1153+
11541154
it('should not parse non-empty list inside quoted triple object',
11551155
shouldNotParse('<< <a> <b> ( <f> ) >> <c> <d>.',
11561156
'Unexpected list inside quoted triple on line 1.'
@@ -1225,6 +1225,12 @@ describe('Parser', () => {
12251225
['a', 'b', 'c'],
12261226
[['a', 'b', 'c'], 'd', 'e']));
12271227

1228+
it('should parse an explicit triple with nested reified annotation',
1229+
shouldParse('<a> <b> <c> {| <d> <e> {| <f> <g> |} |} .',
1230+
['a', 'b', 'c'],
1231+
[['a', 'b', 'c'], 'd', 'e'],
1232+
[[['a', 'b', 'c'], 'd', 'e'], 'f', 'g']));
1233+
12281234
const q = ['http://example.com/ns#s', 'http://example.com/ns#p',
12291235
['http://example.com/ns#a', 'http://example.com/ns#b', 'http://example.com/ns#c']];
12301236

0 commit comments

Comments
 (0)