diff options
author | David Robillard <d@drobilla.net> | 2023-05-03 15:38:58 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-05-03 15:38:58 -0400 |
commit | c311a4b59da70d5f9b790b7a817770bfb49b036a (patch) | |
tree | 5cb6c398813074726453d0e5639860fe574d06fb /src/n3.c | |
parent | 5c3bc9ca3f5122c78f531d73fc0405f0f8dcc73a (diff) | |
download | serd-c311a4b59da70d5f9b790b7a817770bfb49b036a.tar.gz serd-c311a4b59da70d5f9b790b7a817770bfb49b036a.tar.bz2 serd-c311a4b59da70d5f9b790b7a817770bfb49b036a.zip |
Factor out read_nquads_statement()
Diffstat (limited to 'src/n3.c')
-rw-r--r-- | src/n3.c | 96 |
1 files changed, 54 insertions, 42 deletions
@@ -1723,60 +1723,72 @@ read_turtleTrigDoc(SerdReader* const reader) return SERD_SUCCESS; } -SerdStatus -read_nquadsDoc(SerdReader* const reader) +static SerdStatus +read_nquads_statement(SerdReader* const reader) { - SerdStatus st = SERD_SUCCESS; - while (!reader->source.eof) { - SerdStatementFlags flags = 0; - ReadContext ctx = {0, 0, 0, 0, 0, 0, &flags}; - bool ate_dot = false; - int s_type = 0; + SerdStatus st = SERD_SUCCESS; + SerdStatementFlags flags = 0; + ReadContext ctx = {0, 0, 0, 0, 0, 0, &flags}; + bool ate_dot = false; + int s_type = 0; + + read_ws_star(reader); + if (peek_byte(reader) == EOF) { + return SERD_FAILURE; + } + + if (peek_byte(reader) == '@') { + return r_err( + reader, SERD_ERR_BAD_SYNTAX, "syntax does not support directives\n"); + } + + // subject predicate object + if ((st = read_subject(reader, ctx, &ctx.subject, &s_type)) || + !read_ws_star(reader) || (st = read_IRIREF(reader, &ctx.predicate)) || + !read_ws_star(reader) || + (st = read_object(reader, &ctx, false, &ate_dot))) { + return st; + } + + if (!ate_dot) { // graphLabel? read_ws_star(reader); - if (peek_byte(reader) == EOF) { + switch (peek_byte(reader)) { + case '.': break; + case '_': + TRY(st, read_BLANK_NODE_LABEL(reader, &ctx.graph, &ate_dot)); + break; + default: + TRY(st, read_IRIREF(reader, &ctx.graph)); } - if (peek_byte(reader) == '@') { - return r_err( - reader, SERD_ERR_BAD_SYNTAX, "syntax does not support directives\n"); + // Terminating '.' + read_ws_star(reader); + if (!eat_byte_check(reader, '.')) { + return SERD_ERR_BAD_SYNTAX; } + } - // subject predicate object - if ((st = read_subject(reader, ctx, &ctx.subject, &s_type)) || - !read_ws_star(reader) || (st = read_IRIREF(reader, &ctx.predicate)) || - !read_ws_star(reader) || - (st = read_object(reader, &ctx, false, &ate_dot))) { - return st; - } + TRY(st, emit_statement(reader, ctx, ctx.object, ctx.datatype, ctx.lang)); - if (!ate_dot) { // graphLabel? - read_ws_star(reader); - switch (peek_byte(reader)) { - case '.': - break; - case '_': - TRY(st, read_BLANK_NODE_LABEL(reader, &ctx.graph, &ate_dot)); - break; - default: - TRY(st, read_IRIREF(reader, &ctx.graph)); - } + pop_node(reader, ctx.graph); + pop_node(reader, ctx.lang); + pop_node(reader, ctx.datatype); + pop_node(reader, ctx.object); - // Terminating '.' - read_ws_star(reader); - if (!eat_byte_check(reader, '.')) { - return SERD_ERR_BAD_SYNTAX; - } - } + return SERD_SUCCESS; +} - TRY(st, emit_statement(reader, ctx, ctx.object, ctx.datatype, ctx.lang)); +SerdStatus +read_nquadsDoc(SerdReader* const reader) +{ + SerdStatus st = SERD_SUCCESS; - pop_node(reader, ctx.graph); - pop_node(reader, ctx.lang); - pop_node(reader, ctx.datatype); - pop_node(reader, ctx.object); + while (!reader->source.eof && !st) { + st = read_nquads_statement(reader); } - return SERD_SUCCESS; + + return st; } #if defined(__clang__) && __clang_major__ >= 10 |