@@ -62,8 +62,7 @@ class NQuadsParser implements iParser, iQuadIterator {
62
62
const BLANKNODE3_STRICT = '[-0-9_:A-Za-z\x{00B7}\x{00C0}-\x{00D6}\x{00D8}-\x{00F6}\x{00F8}-\x{02FF}\x{0300}-\x{037D}\x{037F}-\x{1FFF}\x{200C}-\x{200D}\x{203F}-\x{2040}\x{2070}-\x{218F}\x{2C00}-\x{2FEF}\x{3001}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFFD}\x{10000}-\x{EFFFF}.] ' ;
63
63
const BLANKNODE4_STRICT = '[-0-9_:A-Za-z\x{00B7}\x{00C0}-\x{00D6}\x{00D8}-\x{00F6}\x{00F8}-\x{02FF}\x{0300}-\x{037D}\x{037F}-\x{1FFF}\x{200C}-\x{200D}\x{203F}-\x{2040}\x{2070}-\x{218F}\x{2C00}-\x{2FEF}\x{3001}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFFD}\x{10000}-\x{EFFFF}] ' ;
64
64
const BLANKNODE = '(_:[^\s<.]+) ' ;
65
- const LITERAL_STRICT = '"((?>[^\x{22}\x{5C}\x{0A}\x{0D}]| \\\\[tbnrf" \'\\\\]| \\\\u[0-9A-Fa-f]{4}| \\\\U[0-9A-Fa-f]{8})*)" ' ;
66
- const LITERAL = '"((?>[^"]| \\")*)" ' ;
65
+ const LITERAL = '"((?>[^\x{22}\x{5C}\x{0A}\x{0D}]| \\\\[tbnrf" \'\\\\]| \\\\u[0-9A-Fa-f]{4}| \\\\U[0-9A-Fa-f]{8})*)" ' ;
67
66
const STAR_START = '% \\G\s*<<% ' ;
68
67
const STAR_END = '% \\G\s*>>% ' ;
69
68
const READ_BUF_SIZE = 8096 ;
@@ -155,7 +154,7 @@ public function __construct(iDataFactory $dataFactory, bool $strict = false,
155
154
$ iri = self ::IRIREF_STRICT ;
156
155
$ blank = '( ' . self ::BLANKNODE1_STRICT . self ::BLANKNODE2_STRICT . '(?: ' . self ::BLANKNODE3_STRICT . '* ' . self ::BLANKNODE4_STRICT . ')?) ' ;
157
156
$ lang = self ::LANGTAG_STRICT ;
158
- $ literal = self ::LITERAL_STRICT ;
157
+ $ literal = self ::LITERAL ;
159
158
$ lineEnd = "\\s* \\. $ comment$ eol " ;
160
159
$ flags = 'u ' ;
161
160
} else {
@@ -166,7 +165,7 @@ public function __construct(iDataFactory $dataFactory, bool $strict = false,
166
165
$ lang = self ::LANGTAG ;
167
166
$ literal = self ::LITERAL ;
168
167
$ lineEnd = "\\s* \\. " ;
169
- $ flags = '' ;
168
+ $ flags = 'u ' ;
170
169
}
171
170
$ graph = '' ;
172
171
if ($ mode === self ::MODE_QUADS || $ mode === self ::MODE_QUADS_STAR ) {
@@ -259,9 +258,9 @@ private function quadGenerator(): Generator {
259
258
while (true ) {
260
259
$ n ++;
261
260
$ this ->line = $ this ->readLine ();
262
- $ ret = preg_match ($ this ->regexp , $ this ->line , $ matches , PREG_UNMATCHED_AS_NULL );
263
- if ($ ret === 0 && !empty (trim ($ this ->line ))) {
264
- throw new RdfIoException ("Can't parse line $ n: " . $ this ->line );
261
+ $ ret = ( int ) preg_match ($ this ->regexp , $ this ->line , $ matches , PREG_UNMATCHED_AS_NULL );
262
+ if (0 === $ ret && !empty (trim ($ this ->line ))) {
263
+ throw new RdfIoException ("Can't parse line $ n with error ' " . preg_last_error_msg () . " ' : " . $ this ->line );
265
264
}
266
265
if (($ matches [3 ] ?? null ) !== null ) {
267
266
yield $ this ->makeQuad ($ matches );
@@ -320,10 +319,10 @@ private function starQuadGenerator(): Generator {
320
319
$ this ->level = 0 ;
321
320
$ this ->line = $ this ->readLine ();
322
321
try {
323
- yield $ this ->parseStar ();
322
+ yield $ this ->parseStar ($ n );
324
323
} catch (RdfIoException $ e ) {
325
324
$ ret = preg_match ($ this ->regexpCommentLine , $ this ->line );
326
- if ($ ret === 0 ) {
325
+ if (0 === ( int ) $ ret ) {
327
326
throw $ e ;
328
327
}
329
328
}
@@ -333,23 +332,23 @@ private function starQuadGenerator(): Generator {
333
332
}
334
333
}
335
334
336
- private function parseStar (): iQuad {
335
+ private function parseStar (int $ line ): iQuad {
337
336
//echo str_repeat("\t", $this->level) . "parsing " . substr($this->line, $this->offset);
338
337
$ matches = null ;
339
338
if (preg_match (self ::STAR_START , $ this ->line , $ matches , 0 , $ this ->offset )) {
340
339
$ this ->offset += strlen ($ matches [0 ]);
341
340
$ this ->level ++;
342
- $ sbj = $ this ->parseStar ();
341
+ $ sbj = $ this ->parseStar ($ line );
343
342
$ ret = preg_match ($ this ->regexpPred , $ this ->line , $ matches , PREG_UNMATCHED_AS_NULL , $ this ->offset );
344
- if ($ ret === 0 ) {
345
- throw new RdfIoException ("Failed parsing predicate " . substr ($ this ->line , $ this ->offset ));
343
+ if (0 === ( int ) $ ret ) {
344
+ throw new RdfIoException ("Failed parsing predicate on line $ line with error ' " . preg_last_error_msg () . " ': " . substr ($ this ->line , $ this ->offset ));
346
345
}
347
346
$ this ->offset += strlen ($ matches [0 ]);
348
347
$ pred = $ this ->dataFactory ::namedNode ($ matches [1 ]);
349
348
} else {
350
349
$ ret = preg_match ($ this ->regexpSbjPred , $ this ->line , $ matches , PREG_UNMATCHED_AS_NULL , $ this ->offset );
351
- if ($ ret === 0 ) {
352
- throw new RdfIoException ("Failed parsing subject and predicate " . substr ($ this ->line , $ this ->offset ));
350
+ if (0 === ( int ) $ ret ) {
351
+ throw new RdfIoException ("Failed parsing subject and predicate on line $ line with error ' " . preg_last_error_msg () . " ': " . substr ($ this ->line , $ this ->offset ));
353
352
}
354
353
$ this ->offset += strlen ($ matches [0 ]);
355
354
if ($ matches [1 ] !== null ) {
@@ -362,7 +361,7 @@ private function parseStar(): iQuad {
362
361
if (preg_match (self ::STAR_START , $ this ->line , $ matches , 0 , $ this ->offset )) {
363
362
$ this ->offset += strlen ($ matches [0 ]);
364
363
$ this ->level ++;
365
- $ obj = $ this ->parseStar ();
364
+ $ obj = $ this ->parseStar ($ line );
366
365
$ ret = preg_match ($ this ->regexpGraph , $ this ->line , $ matches , PREG_UNMATCHED_AS_NULL , $ this ->offset );
367
366
$ this ->offset += strlen ($ matches [0 ]);
368
367
if (($ matches [1 ] ?? null ) !== null ) {
@@ -371,9 +370,9 @@ private function parseStar(): iQuad {
371
370
$ graph = $ this ->dataFactory ::blankNode ($ matches [2 ]);
372
371
}
373
372
} else {
374
- $ ret = preg_match ($ this ->regexpObjGraph , $ this ->line , $ matches , PREG_UNMATCHED_AS_NULL , $ this ->offset );
375
- if ($ ret === 0 ) {
376
- throw new RdfIoException ("Can't parse object " . substr ($ this ->line , $ this ->offset ));
373
+ $ ret = ( int ) preg_match ($ this ->regexpObjGraph , $ this ->line , $ matches , PREG_UNMATCHED_AS_NULL , $ this ->offset );
374
+ if (0 === $ ret ) {
375
+ throw new RdfIoException ("Can't parse object on line $ line with error ' " . preg_last_error_msg () . " ': " . substr ($ this ->line , $ this ->offset ));
377
376
}
378
377
$ this ->offset += strlen ($ matches [0 ]);
379
378
if ($ matches [1 ] !== null ) {
@@ -393,8 +392,8 @@ private function parseStar(): iQuad {
393
392
}
394
393
$ regexpEnd = $ this ->level > 0 ? self ::STAR_END : $ this ->regexpLineEnd ;
395
394
$ ret = preg_match ($ regexpEnd , $ this ->line , $ matches , 0 , $ this ->offset );
396
- if ($ ret === 0 ) {
397
- throw new RdfIoException ("Can't parse end " . substr ($ this ->line , $ this ->offset ));
395
+ if (0 === ( int ) $ ret ) {
396
+ throw new RdfIoException ("Can't parse end on line $ line with error ' " . preg_last_error_msg () . " ': " . substr ($ this ->line , $ this ->offset ));
398
397
}
399
398
$ this ->offset += strlen ($ matches [0 ]);
400
399
$ quad = $ this ->dataFactory ::quad ($ sbj , $ pred , $ obj , $ graph ?? null );
0 commit comments