From 505209a2ff35c2b880cc64712932fd4d11aeaf8d Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 21 Oct 2018 20:57:33 +0200 Subject: Simplify streaming API and improve pretty printing This removes the obligation from the caller to correctly maintain flags to describe the current anonymous context, instead making the writer handle this itself as much as possible. Flags remain for the cases the writer can not infer from context: the start of anonymous subject and object nodes. --- src/n3.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'src/n3.c') diff --git a/src/n3.c b/src/n3.c index bce9e01d..8a45c079 100644 --- a/src/n3.c +++ b/src/n3.c @@ -937,7 +937,7 @@ read_anon(SerdReader* reader, ReadContext ctx, bool subject, SerdNode** dest) bool empty; eat_byte_safe(reader, '['); if ((empty = peek_delim(reader, ']'))) { - *ctx.flags |= (subject) ? SERD_EMPTY_S : SERD_EMPTY_O; + *ctx.flags |= (subject) ? SERD_EMPTY_S : SERD_ANON_O_BEGIN; } else { *ctx.flags |= (subject) ? SERD_ANON_S_BEGIN : SERD_ANON_O_BEGIN; if (peek_delim(reader, '=')) { @@ -959,21 +959,19 @@ read_anon(SerdReader* reader, ReadContext ctx, bool subject, SerdNode** dest) 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->sink->end) { - reader->sink->end(reader->sink->handle, *dest); - } *ctx.flags = old_flags; } + + if (reader->sink->end && (!subject || !empty)) { + reader->sink->end(reader->sink->handle, *dest); + } + return (eat_byte_check(reader, ']') == ']') ? SERD_SUCCESS : SERD_ERR_BAD_SYNTAX; } @@ -1130,7 +1128,6 @@ end_collection(SerdReader* reader, SerdNode* n2, SerdStatus st) { - *ctx.flags &= ~SERD_LIST_CONT; if (!st) { eat_byte_safe(reader, ')'); } @@ -1148,7 +1145,6 @@ read_collection(SerdReader* reader, ReadContext ctx, SerdNode** dest) // subject predicate _:head *ctx.flags |= (end ? 0 : SERD_LIST_O_BEGIN); TRY(st, emit_statement(reader, ctx, *dest)); - *ctx.flags |= SERD_LIST_CONT; } else { *ctx.flags |= (end ? 0 : SERD_LIST_S_BEGIN); } @@ -1188,7 +1184,6 @@ read_collection(SerdReader* reader, ReadContext ctx, SerdNode** dest) } // _:node rdf:rest _:rest - *ctx.flags |= SERD_LIST_CONT; ctx.predicate = reader->rdf_rest; TRY(st, emit_statement(reader, ctx, (end ? reader->rdf_nil : rest))); -- cgit v1.2.1