Skip to content

Commit be00c27

Browse files
committed
Parse graphs ending with a blank node.
1 parent 4bf01d1 commit be00c27

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

lib/N3Parser.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,15 @@ N3Parser.prototype = {
358358

359359
// ### `_readPredicateAfterBlank` reads a predicate after an anonymous blank node
360360
_readPredicateAfterBlank: function (token) {
361-
// If a dot follows a blank node in top context, there is no predicate
362-
if (token.type === '.' && !this._contextStack.length) {
363-
this._subject = null; // cancel the current quad
361+
switch (token.type) {
362+
case '.':
363+
case '}':
364+
// No predicate is coming if the triple is terminated here
365+
this._subject = null;
364366
return this._readPunctuation(token);
367+
default:
368+
return this._readPredicate(token);
365369
}
366-
return this._readPredicate(token);
367370
},
368371

369372
// ### `_readListItem` reads items from a list

test/N3Parser-test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,14 @@ describe('N3Parser', function () {
595595
['a', 'd', 'e'],
596596
['a', 'd', 'f']));
597597

598+
it('should parse a default graph with a blank node ending with a dot',
599+
shouldParse('{ [<p> <o>]. }',
600+
['_:b0', 'p', 'o']));
601+
602+
it('should parse a default graph with a blank node ending without a dot',
603+
shouldParse('{ [<p> <o>] }',
604+
['_:b0', 'p', 'o']));
605+
598606
it('should parse an empty named graph with an IRI',
599607
shouldParse('<g>{}'));
600608

@@ -641,6 +649,14 @@ describe('N3Parser', function () {
641649
['a', 'd', 'e', 'g#h'],
642650
['a', 'd', 'f', 'g#h']));
643651

652+
it('should parse a named graph with a blank node ending with a dot',
653+
shouldParse('<g> { [<p> <o>]. }',
654+
['_:b0', 'p', 'o', 'g']));
655+
656+
it('should parse a named graph with a blank node ending without a dot',
657+
shouldParse('<g> { [<p> <o>] }',
658+
['_:b0', 'p', 'o', 'g']));
659+
644660
it('should parse an empty anonymous graph',
645661
shouldParse('[] {}'));
646662

0 commit comments

Comments
 (0)