aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-05-03 15:38:58 -0400
committerDavid Robillard <d@drobilla.net>2023-05-03 15:38:58 -0400
commitc311a4b59da70d5f9b790b7a817770bfb49b036a (patch)
tree5cb6c398813074726453d0e5639860fe574d06fb
parent5c3bc9ca3f5122c78f531d73fc0405f0f8dcc73a (diff)
downloadserd-c311a4b59da70d5f9b790b7a817770bfb49b036a.tar.gz
serd-c311a4b59da70d5f9b790b7a817770bfb49b036a.tar.bz2
serd-c311a4b59da70d5f9b790b7a817770bfb49b036a.zip
Factor out read_nquads_statement()
-rw-r--r--src/n3.c96
1 files changed, 54 insertions, 42 deletions
diff --git a/src/n3.c b/src/n3.c
index 011f57fa..c92059a5 100644
--- a/src/n3.c
+++ b/src/n3.c
@@ -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