diff options
author | David Robillard <d@drobilla.net> | 2015-10-02 18:03:29 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2015-10-02 18:03:29 +0000 |
commit | aec46529233290f8274d137b795b4924f1db131a (patch) | |
tree | 837bbb7a5cedb2ddaa5e73c51acb14a480cb2480 /src/reader.c | |
parent | d908317e729ffc2495b9fc546cff88b541eacfb2 (diff) | |
download | serd-aec46529233290f8274d137b795b4924f1db131a.tar.gz serd-aec46529233290f8274d137b795b4924f1db131a.tar.bz2 serd-aec46529233290f8274d137b795b4924f1db131a.zip |
Full test coverage
git-svn-id: http://svn.drobilla.net/serd/trunk@492 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'src/reader.c')
-rw-r--r-- | src/reader.c | 95 |
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); |