aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/reader.c95
1 files changed, 49 insertions, 46 deletions
diff --git a/src/reader.c b/src/reader.c
index ec1a6034..c3c2e538 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -1089,56 +1089,48 @@ read_blankName(SerdReader* reader)
}
static bool
-read_blank(SerdReader* reader, ReadContext ctx, bool subject, Ref* dest, bool* ate_dot)
+read_anon(SerdReader* reader, ReadContext ctx, bool subject, Ref* dest)
{
const SerdStatementFlags old_flags = *ctx.flags;
bool empty;
- switch (peek_byte(reader)) {
- case '_':
- return (*dest = read_BLANK_NODE_LABEL(reader, ate_dot));
- case '[':
- eat_byte_safe(reader, '[');
- if ((empty = peek_delim(reader, ']'))) {
- *ctx.flags |= (subject) ? SERD_EMPTY_S : SERD_EMPTY_O;
- } else {
- *ctx.flags |= (subject) ? SERD_ANON_S_BEGIN : SERD_ANON_O_BEGIN;
- if (peek_delim(reader, '=')) {
- if (!(*dest = read_blankName(reader)) ||
- !eat_delim(reader, ';')) {
- return false;
- }
+ eat_byte_safe(reader, '[');
+ if ((empty = peek_delim(reader, ']'))) {
+ *ctx.flags |= (subject) ? SERD_EMPTY_S : SERD_EMPTY_O;
+ } else {
+ *ctx.flags |= (subject) ? SERD_ANON_S_BEGIN : SERD_ANON_O_BEGIN;
+ if (peek_delim(reader, '=')) {
+ if (!(*dest = read_blankName(reader)) ||
+ !eat_delim(reader, ';')) {
+ return false;
}
}
+ }
- if (!*dest) {
- *dest = blank_id(reader);
+ if (!*dest) {
+ *dest = blank_id(reader);
+ }
+ if (ctx.subject) {
+ TRY_RET(emit_statement(reader, ctx, *dest, 0, 0));
+ }
+
+ ctx.subject = *dest;
+ if (!empty) {
+ *ctx.flags &= ~(SERD_LIST_CONT);
+ if (!subject) {
+ *ctx.flags |= SERD_ANON_CONT;
}
- if (ctx.subject) {
- TRY_RET(emit_statement(reader, ctx, *dest, 0, 0));
+ bool ate_dot_in_list = false;
+ read_predicateObjectList(reader, ctx, &ate_dot_in_list);
+ if (ate_dot_in_list) {
+ return r_err(reader, SERD_ERR_BAD_SYNTAX, "`.' inside blank\n");
}
-
- ctx.subject = *dest;
- if (!empty) {
- *ctx.flags &= ~(SERD_LIST_CONT);
- if (!subject) {
- *ctx.flags |= SERD_ANON_CONT;
- }
- bool ate_dot_in_list = false;
- read_predicateObjectList(reader, ctx, &ate_dot_in_list);
- if (ate_dot_in_list) {
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "`.' inside blank\n");
- }
- read_ws_star(reader);
- if (reader->end_sink) {
- reader->end_sink(reader->handle, deref(reader, *dest));
- }
- *ctx.flags = old_flags;
+ read_ws_star(reader);
+ if (reader->end_sink) {
+ reader->end_sink(reader->handle, deref(reader, *dest));
}
- return (eat_byte_check(reader, ']') == ']');
- case '(':
- return read_collection(reader, ctx, dest);
- default: return false; // never reached
+ *ctx.flags = old_flags;
}
+ return (eat_byte_check(reader, ']') == ']');
}
// Recurses, calling statement_sink for every statement encountered.
@@ -1165,11 +1157,16 @@ read_object(SerdReader* reader, ReadContext ctx, bool* ate_dot)
case '\0':
case ')':
return false;
- case '[': case '(':
+ case '[':
emit = false;
- // fall through
+ TRY_THROW(ret = read_anon(reader, ctx, false, &o));
+ break;
+ case '(':
+ emit = false;
+ TRY_THROW(ret = read_collection(reader, ctx, &o));
+ break;
case '_':
- TRY_THROW(ret = read_blank(reader, ctx, false, &o, ate_dot));
+ TRY_THROW(ret = (o = read_BLANK_NODE_LABEL(reader, ate_dot)));
break;
case '<': case ':':
TRY_THROW(ret = read_iri(reader, &o, ate_dot));
@@ -1334,11 +1331,17 @@ read_subject(SerdReader* reader, ReadContext ctx, bool* nested)
Ref subject = 0;
bool ate_dot = false;
switch (peek_byte(reader)) {
- case '[': case '(':
+ case '[':
*nested = true;
- // nobreak
+ read_anon(reader, ctx, true, &subject);
+ break;
+ case '(':
+ *nested = true;
+ read_collection(reader, ctx, &subject);
+ break;
case '_':
- read_blank(reader, ctx, true, &subject, &ate_dot);
+ *nested = false;
+ subject = read_BLANK_NODE_LABEL(reader, &ate_dot);
break;
default:
read_iri(reader, &subject, &ate_dot);