diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/n3.c | 67 | ||||
-rw-r--r-- | src/reader.h | 2 |
2 files changed, 31 insertions, 38 deletions
@@ -676,26 +676,27 @@ read_PN_PREFIX(SerdReader* const reader, SerdNode* const dest) } static SerdStatus -read_LANGTAG(SerdReader* const reader, SerdNode** const dest) +read_LANGTAG(SerdReader* const reader) { int c = peek_byte(reader); if (!is_alpha(c)) { return r_err(reader, SERD_ERR_BAD_SYNTAX, "unexpected `%c'\n", c); } - if (!(*dest = push_node(reader, SERD_LITERAL, "", 0))) { + SerdNode* node = push_node(reader, SERD_LITERAL, "", 0); + if (!node) { return SERD_ERR_OVERFLOW; } SerdStatus st = SERD_SUCCESS; - TRY(st, push_byte(reader, *dest, eat_byte_safe(reader, c))); + TRY(st, push_byte(reader, node, eat_byte_safe(reader, c))); while ((c = peek_byte(reader)) && is_alpha(c)) { - TRY(st, push_byte(reader, *dest, eat_byte_safe(reader, c))); + TRY(st, push_byte(reader, node, eat_byte_safe(reader, c))); } while (peek_byte(reader) == '-') { - TRY(st, push_byte(reader, *dest, eat_byte_safe(reader, '-'))); + TRY(st, push_byte(reader, node, eat_byte_safe(reader, '-'))); while ((c = peek_byte(reader)) && (is_alpha(c) || is_digit(c))) { - TRY(st, push_byte(reader, *dest, eat_byte_safe(reader, c))); + TRY(st, push_byte(reader, node, eat_byte_safe(reader, c))); } } return SERD_SUCCESS; @@ -845,7 +846,6 @@ read_0_9(SerdReader* const reader, SerdNode* const str, const bool at_least_one) static SerdStatus read_number(SerdReader* const reader, SerdNode** const dest, - SerdNode** const datatype, SerdNodeFlags* const flags, bool* const ate_dot) { @@ -902,16 +902,13 @@ read_number(SerdReader* const reader, break; } TRY(st, read_0_9(reader, *dest, true)); - *datatype = push_node(reader, SERD_URI, XSD_DOUBLE, sizeof(XSD_DOUBLE) - 1); + push_node(reader, SERD_URI, XSD_DOUBLE, sizeof(XSD_DOUBLE) - 1); + *flags |= SERD_HAS_DATATYPE; } else if (has_decimal) { - *datatype = - push_node(reader, SERD_URI, XSD_DECIMAL, sizeof(XSD_DECIMAL) - 1); + push_node(reader, SERD_URI, XSD_DECIMAL, sizeof(XSD_DECIMAL) - 1); + *flags |= SERD_HAS_DATATYPE; } else { - *datatype = - push_node(reader, SERD_URI, XSD_INTEGER, sizeof(XSD_INTEGER) - 1); - } - - if (*datatype) { + push_node(reader, SERD_URI, XSD_INTEGER, sizeof(XSD_INTEGER) - 1); *flags |= SERD_HAS_DATATYPE; } @@ -935,8 +932,6 @@ read_iri(SerdReader* const reader, SerdNode** const dest, bool* const ate_dot) static SerdStatus read_literal(SerdReader* const reader, SerdNode** const dest, - SerdNode** const datatype, - SerdNode** const lang, SerdNodeFlags* const flags, bool* const ate_dot) { @@ -948,11 +943,12 @@ read_literal(SerdReader* const reader, return st; } + SerdNode* datatype = NULL; switch (peek_byte(reader)) { case '@': eat_byte_safe(reader, '@'); *flags |= SERD_HAS_LANGUAGE; - if ((st = read_LANGTAG(reader, lang))) { + if ((st = read_LANGTAG(reader))) { return r_err(reader, st, "bad literal\n"); } break; @@ -960,7 +956,7 @@ read_literal(SerdReader* const reader, eat_byte_safe(reader, '^'); eat_byte_check(reader, '^'); *flags |= SERD_HAS_DATATYPE; - if ((st = read_iri(reader, datatype, ate_dot))) { + if ((st = read_iri(reader, &datatype, ate_dot))) { return r_err(reader, st, "bad literal\n"); } break; @@ -1120,12 +1116,10 @@ read_object(SerdReader* const reader, SerdStatus ret = SERD_FAILURE; - bool simple = (ctx->subject != 0); - SerdNode* o = 0; - SerdNode* datatype = 0; - SerdNode* lang = 0; - uint32_t flags = 0; - const int c = peek_byte(reader); + bool simple = (ctx->subject != 0); + SerdNode* o = 0; + uint32_t flags = 0; + const int c = peek_byte(reader); if (!fancy_syntax(reader)) { switch (c) { case '"': @@ -1169,11 +1163,11 @@ read_object(SerdReader* const reader, case '7': case '8': case '9': - ret = read_number(reader, &o, &datatype, &flags, ate_dot); + ret = read_number(reader, &o, &flags, ate_dot); break; case '\"': case '\'': - ret = read_literal(reader, &o, &datatype, &lang, &flags, ate_dot); + ret = read_literal(reader, &o, &flags, ate_dot); break; default: /* Either a boolean literal, or a qname. Read the prefix first, and if @@ -1187,10 +1181,10 @@ read_object(SerdReader* const reader, } if ((o->length == 4 && !memcmp(serd_node_string(o), "true", 4)) || (o->length == 5 && !memcmp(serd_node_string(o), "false", 5))) { - flags = flags | SERD_HAS_DATATYPE; - o->type = SERD_LITERAL; - datatype = push_node(reader, SERD_URI, XSD_BOOLEAN, XSD_BOOLEAN_LEN); - ret = SERD_SUCCESS; + flags = flags | SERD_HAS_DATATYPE; + o->type = SERD_LITERAL; + push_node(reader, SERD_URI, XSD_BOOLEAN, XSD_BOOLEAN_LEN); + ret = SERD_SUCCESS; } else if (read_PN_PREFIX_tail(reader, o) > SERD_FAILURE) { ret = SERD_ERR_BAD_SYNTAX; } else { @@ -1208,9 +1202,7 @@ read_object(SerdReader* const reader, if (!ret && emit && simple) { ret = emit_statement(reader, *ctx, o); } else if (!ret && !emit) { - ctx->object = o; - ctx->datatype = datatype; - ctx->lang = lang; + ctx->object = o; return SERD_SUCCESS; } @@ -1573,7 +1565,7 @@ SerdStatus read_n3_statement(SerdReader* const reader) { SerdStatementFlags flags = 0; - ReadContext ctx = {0, 0, 0, 0, 0, 0, &flags}; + ReadContext ctx = {0, 0, 0, 0, &flags}; bool ate_dot = false; int s_type = 0; SerdStatus st = SERD_SUCCESS; @@ -1666,10 +1658,12 @@ read_turtleTrigDoc(SerdReader* const reader) serd_stack_pop_to(&reader->stack, orig_stack_size); return st; } + skip_until(reader, '\n'); } serd_stack_pop_to(&reader->stack, orig_stack_size); } + return SERD_SUCCESS; } @@ -1681,7 +1675,7 @@ read_nquadsDoc(SerdReader* const reader) const size_t orig_stack_size = reader->stack.size; SerdStatementFlags flags = 0; - ReadContext ctx = {0, 0, 0, 0, 0, 0, &flags}; + ReadContext ctx = {0, 0, 0, 0, &flags}; bool ate_dot = false; int s_type = 0; read_ws_star(reader); @@ -1726,6 +1720,7 @@ read_nquadsDoc(SerdReader* const reader) serd_stack_pop_to(&reader->stack, orig_stack_size); } + return SERD_SUCCESS; } diff --git a/src/reader.h b/src/reader.h index 48c08fe5..ec0e43f0 100644 --- a/src/reader.h +++ b/src/reader.h @@ -39,8 +39,6 @@ typedef struct { SerdNode* subject; SerdNode* predicate; SerdNode* object; - SerdNode* datatype; - SerdNode* lang; SerdStatementFlags* flags; } ReadContext; |