@@ -187,6 +187,17 @@ export default class N3Parser {
187
187
return value ;
188
188
}
189
189
190
+ _readList ( token , subject , predicate , object ) {
191
+ // Lists are not allowed inside quoted triples
192
+ if ( this . _contextStack . length > 0 && this . _contextStack [ this . _contextStack . length - 1 ] . type === '<<' ) {
193
+ return this . _error ( 'Unexpected list inside quoted triple' , token ) ;
194
+ }
195
+ // Start a new list
196
+ this . _saveContext ( 'list' , this . _graph , subject , predicate , object ) ;
197
+ this . _subject = null ;
198
+ return this . _readListItem ;
199
+ }
200
+
190
201
// ### `_readSubject` reads a quad's subject
191
202
_readSubject ( token ) {
192
203
this . _predicate = null ;
@@ -197,14 +208,7 @@ export default class N3Parser {
197
208
this . _subject = this . _blankNode ( ) , null , null ) ;
198
209
return this . _readBlankNodeHead ;
199
210
case '(' :
200
- // Lists are not allowed inside quoted triples
201
- if ( this . _contextStack . length > 0 && this . _contextStack [ this . _contextStack . length - 1 ] . type === '<<' ) {
202
- return this . _error ( 'Unexpected list inside quoted triple' , token ) ;
203
- }
204
- // Start a new list
205
- this . _saveContext ( 'list' , this . _graph , this . RDF_NIL , null , null ) ;
206
- this . _subject = null ;
207
- return this . _readListItem ;
211
+ return this . _readList ( token , this . RDF_NIL , null , null ) ;
208
212
case '{' :
209
213
// Start a new formula
210
214
if ( ! this . _n3Mode )
@@ -282,6 +286,10 @@ export default class N3Parser {
282
286
// Additional semicolons can be safely ignored
283
287
return this . _predicate !== null ? this . _readPredicate :
284
288
this . _error ( 'Expected predicate but got ;' , token ) ;
289
+ case '(' :
290
+ return this . _n3Mode ?
291
+ this . _readList ( token , this . _subject , this . RDF_NIL , null ) :
292
+ this . _error ( `Expected entity but got ${ type } ` , token ) ;
285
293
case '[' :
286
294
if ( this . _n3Mode ) {
287
295
// Start a new quad with a new blank node as subject
@@ -319,14 +327,7 @@ export default class N3Parser {
319
327
this . _subject = this . _blankNode ( ) ) ;
320
328
return this . _readBlankNodeHead ;
321
329
case '(' :
322
- // Lists are not allowed inside quoted triples
323
- if ( this . _contextStack . length > 0 && this . _contextStack [ this . _contextStack . length - 1 ] . type === '<<' ) {
324
- return this . _error ( 'Unexpected list inside quoted triple' , token ) ;
325
- }
326
- // Start a new list
327
- this . _saveContext ( 'list' , this . _graph , this . _subject , this . _predicate , this . RDF_NIL ) ;
328
- this . _subject = null ;
329
- return this . _readListItem ;
330
+ return this . _readList ( token , this . _subject , this . _predicate , this . RDF_NIL ) ;
330
331
case '{' :
331
332
// Start a new formula
332
333
if ( ! this . _n3Mode )
@@ -468,6 +469,14 @@ export default class N3Parser {
468
469
// No list tail if this was an empty list
469
470
if ( this . _subject === this . RDF_NIL )
470
471
return next ;
472
+ // Was this list the parent's predicate?
473
+ }
474
+ else if ( this . _object === null ) {
475
+ next = this . _readObject ;
476
+
477
+ // No list tail if this was an empty list
478
+ if ( this . _predicate === this . RDF_NIL )
479
+ return next ;
471
480
}
472
481
// The list was in the parent context's object
473
482
else {
@@ -519,9 +528,13 @@ export default class N3Parser {
519
528
520
529
// Is this the first element of the list?
521
530
if ( previousList === null ) {
522
- // This list is either the subject or the object of its parent
531
+ // This list is the subject of the parent
523
532
if ( parent . predicate === null )
524
533
parent . subject = list ;
534
+ // The list is the predicate of the parent
535
+ else if ( parent . object === null )
536
+ parent . predicate = list ;
537
+ // The list is the object of the parent
525
538
else
526
539
parent . object = list ;
527
540
}
0 commit comments