@@ -187,6 +187,17 @@ export default class N3Parser {
187187 return value ;
188188 }
189189
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+
190201 // ### `_readSubject` reads a quad's subject
191202 _readSubject ( token ) {
192203 this . _predicate = null ;
@@ -197,14 +208,7 @@ export default class N3Parser {
197208 this . _subject = this . _blankNode ( ) , null , null ) ;
198209 return this . _readBlankNodeHead ;
199210 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 ) ;
208212 case '{' :
209213 // Start a new formula
210214 if ( ! this . _n3Mode )
@@ -282,6 +286,10 @@ export default class N3Parser {
282286 // Additional semicolons can be safely ignored
283287 return this . _predicate !== null ? this . _readPredicate :
284288 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 ) ;
285293 case '[' :
286294 if ( this . _n3Mode ) {
287295 // Start a new quad with a new blank node as subject
@@ -319,14 +327,7 @@ export default class N3Parser {
319327 this . _subject = this . _blankNode ( ) ) ;
320328 return this . _readBlankNodeHead ;
321329 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 ) ;
330331 case '{' :
331332 // Start a new formula
332333 if ( ! this . _n3Mode )
@@ -468,6 +469,14 @@ export default class N3Parser {
468469 // No list tail if this was an empty list
469470 if ( this . _subject === this . RDF_NIL )
470471 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 ;
471480 }
472481 // The list was in the parent context's object
473482 else {
@@ -519,9 +528,13 @@ export default class N3Parser {
519528
520529 // Is this the first element of the list?
521530 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
523532 if ( parent . predicate === null )
524533 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
525538 else
526539 parent . object = list ;
527540 }
0 commit comments