Skip to content

Commit f837b8d

Browse files
committed
breaking: drop support for quads in quoted triples as they are forbidden in the rdf-star spec
1 parent 37ab09c commit f837b8d

2 files changed

Lines changed: 13 additions & 24 deletions

File tree

src/N3Parser.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -845,21 +845,10 @@ export default class N3Parser {
845845
return this._readPath;
846846
}
847847

848-
// ### `_readRDFStarTailOrGraph` reads the graph of a nested RDF* quad or the end of a nested RDF* triple
849-
_readRDFStarTailOrGraph(token) {
850-
if (token.type !== '>>') {
851-
// An entity means this is a quad (only allowed if not already inside a graph)
852-
if (this._supportsQuads && this._graph === null && (this._graph = this._readEntity(token)) !== undefined)
853-
return this._readRDFStarTail;
854-
return this._error(`Expected >> to follow "${this._object.id}"`, token);
855-
}
856-
return this._readRDFStarTail(token);
857-
}
858-
859848
// ### `_readRDFStarTail` reads the end of a nested RDF* triple
860849
_readRDFStarTail(token) {
861850
if (token.type !== '>>')
862-
return this._error(`Expected >> but got ${token.type}`, token);
851+
return this._error(`Expected >> to follow "${this._object.id}" but got ${token.type}`, token);
863852
// Read the quad and restore the previous context
864853
const quad = this._quad(this._subject, this._predicate, this._object,
865854
this._graph || this.DEFAULTGRAPH);
@@ -897,7 +886,7 @@ export default class N3Parser {
897886
case 'formula':
898887
return this._readFormulaTail;
899888
case '<<':
900-
return this._readRDFStarTailOrGraph;
889+
return this._readRDFStarTail;
901890
}
902891
}
903892

test/N3Parser-test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,10 @@ describe('Parser', () => {
933933
shouldParse('<a> <b> <c> <g>.',
934934
['a', 'b', 'c', 'g']));
935935

936+
it('should not parse a quad in a quoted triple',
937+
shouldNotParse('<< <a> <b> <c> <g> >> <c> <d> .',
938+
'Expected >> to follow "http://example.org/c" but got IRI on line 1.'));
939+
936940
it('should parse a quad with 4 prefixed names',
937941
shouldParse('@prefix p: <p#>.\np:a p:b p:c p:g.',
938942
['p#a', 'p#b', 'p#c', 'p#g']));
@@ -1124,12 +1128,12 @@ describe('Parser', () => {
11241128

11251129
it('should not parse nested RDF* statements that are partially closed',
11261130
shouldNotParse('<d> <e> <<<<<a> <b> <c>>> <f> <g>.',
1127-
'Expected entity but got . on line 1.'
1131+
'Expected >> to follow "http://example.org/g" but got . on line 1.'
11281132
));
11291133

11301134
it('should not parse partially closed nested RDF* statements',
11311135
shouldNotParse('<d> <e> <<<<<a> <b> <c> <f> <g>>>.',
1132-
'Expected >> but got IRI on line 1.'
1136+
'Expected >> to follow "http://example.org/c" but got IRI on line 1.'
11331137
));
11341138

11351139
it('should not parse nested RDF* statements with too many closing tags',
@@ -1167,13 +1171,9 @@ describe('Parser', () => {
11671171
'Unexpected . on line 1.'
11681172
));
11691173

1170-
it('should parse an RDF* quad',
1171-
shouldParse('<<<a> <b> <c> <d>>> <a> <b> .',
1172-
[['a', 'b', 'c', 'd'], 'a', 'b']));
1173-
11741174
it('should not parse a malformed RDF* quad',
11751175
shouldNotParse('<<<a> <b> <c> <d> <e>>> <a> <b> .',
1176-
'Expected >> but got IRI on line 1.'));
1176+
'Expected >> to follow "http://example.org/c" but got IRI on line 1.'));
11771177

11781178
it('should parse statements with a shared RDF* subject',
11791179
shouldParse('<<<a> <b> <c>>> <b> <c>;\n<d> <c>.',
@@ -1392,7 +1392,7 @@ describe('Parser', () => {
13921392

13931393
it('should not parse nested quads',
13941394
shouldNotParse(parser, '<<_:a <http://ex.org/b> _:b <http://ex.org/b>>> <http://ex.org/b> "c" .',
1395-
'Expected >> to follow "_:b0_b" on line 1.'));
1395+
'Expected >> to follow "_:b0_b" but got IRI on line 1.'));
13961396
});
13971397

13981398
describe('A Parser instance for the TriG format', () => {
@@ -1452,7 +1452,7 @@ describe('Parser', () => {
14521452

14531453
it('should not parse nested quads',
14541454
shouldNotParse(parser, '<<_:a <http://ex.org/b> _:b <http://ex.org/b>>> <http://ex.org/b> "c" .',
1455-
'Expected >> to follow "_:b0_b" on line 1.'));
1455+
'Expected >> to follow "_:b0_b" but got IRI on line 1.'));
14561456
});
14571457

14581458
describe('A Parser instance for the N-Triples format', () => {
@@ -1527,7 +1527,7 @@ describe('Parser', () => {
15271527

15281528
it('should not parse nested quads',
15291529
shouldNotParse(parser, '<<_:a <http://ex.org/b> _:b <http://ex.org/b>>> <http://ex.org/b> "c" .',
1530-
'Expected >> to follow "_:b0_b" on line 1.'));
1530+
'Expected >> to follow "_:b0_b" but got IRI on line 1.'));
15311531
});
15321532

15331533
describe('A Parser instance for the N-Quads format', () => {
@@ -1941,7 +1941,7 @@ describe('Parser', () => {
19411941

19421942
it('should not parse nested quads',
19431943
shouldNotParse(parser, '<<_:a <http://ex.org/b> _:b <http://ex.org/b>>> <http://ex.org/b> "c" .',
1944-
'Expected >> to follow "_:.b" on line 1.'));
1944+
'Expected >> to follow "_:.b" but got IRI on line 1.'));
19451945
});
19461946

19471947
describe('A Parser instance for the N3 format with the explicitQuantifiers option', () => {

0 commit comments

Comments
 (0)