diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/n3.c | 104 |
1 files changed, 43 insertions, 61 deletions
@@ -154,9 +154,7 @@ read_UCHAR(SerdReader* const reader, // Read ECHAR escape, initial \ is already eaten by caller static SerdStatus -read_ECHAR(SerdReader* const reader, - SerdNode* const dest, - SerdNodeFlags* const flags) +read_ECHAR(SerdReader* const reader, SerdNode* const dest) { const int c = peek_byte(reader); switch (c) { @@ -167,11 +165,11 @@ read_ECHAR(SerdReader* const reader, eat_byte_safe(reader, 'b'); return push_byte(reader, dest, '\b'); case 'n': - *flags |= SERD_HAS_NEWLINE; + dest->flags |= SERD_HAS_NEWLINE; eat_byte_safe(reader, 'n'); return push_byte(reader, dest, '\n'); case 'r': - *flags |= SERD_HAS_NEWLINE; + dest->flags |= SERD_HAS_NEWLINE; eat_byte_safe(reader, 'r'); return push_byte(reader, dest, '\r'); case 'f': @@ -264,20 +262,17 @@ read_utf8_code(SerdReader* const reader, // Read one character (possibly multi-byte) // The first byte, c, has already been eaten by caller static SerdStatus -read_character(SerdReader* const reader, - SerdNode* const dest, - SerdNodeFlags* const flags, - const uint8_t c) +read_character(SerdReader* const reader, SerdNode* const dest, const uint8_t c) { if (!(c & 0x80)) { switch (c) { case 0xA: case 0xD: - *flags |= SERD_HAS_NEWLINE; + dest->flags |= SERD_HAS_NEWLINE; break; case '"': case '\'': - *flags |= SERD_HAS_QUOTE; + dest->flags |= SERD_HAS_QUOTE; break; default: break; @@ -349,10 +344,9 @@ eat_delim(SerdReader* const reader, const uint8_t delim) // STRING_LITERAL_LONG_QUOTE and STRING_LITERAL_LONG_SINGLE_QUOTE // Initial triple quotes are already eaten by caller static SerdStatus -read_STRING_LITERAL_LONG(SerdReader* const reader, - SerdNode* const ref, - SerdNodeFlags* const flags, - const uint8_t q) +read_STRING_LITERAL_LONG(SerdReader* const reader, + SerdNode* const ref, + const uint8_t q) { SerdStatus st = SERD_SUCCESS; @@ -361,7 +355,7 @@ read_STRING_LITERAL_LONG(SerdReader* const reader, if (c == '\\') { eat_byte_safe(reader, c); uint32_t code = 0; - if ((st = read_ECHAR(reader, ref, flags)) && + if ((st = read_ECHAR(reader, ref)) && (st = read_UCHAR(reader, ref, &code))) { return r_err(reader, st, "invalid escape `\\%c'\n", peek_byte(reader)); } @@ -373,14 +367,13 @@ read_STRING_LITERAL_LONG(SerdReader* const reader, eat_byte_safe(reader, q3); break; } - *flags |= SERD_HAS_QUOTE; + ref->flags |= SERD_HAS_QUOTE; push_byte(reader, ref, c); - st = read_character(reader, ref, flags, (uint8_t)q2); + st = read_character(reader, ref, (uint8_t)q2); } else if (c == EOF) { return r_err(reader, SERD_ERR_BAD_SYNTAX, "end of file in long string\n"); } else { - st = - read_character(reader, ref, flags, (uint8_t)eat_byte_safe(reader, c)); + st = read_character(reader, ref, (uint8_t)eat_byte_safe(reader, c)); } } @@ -390,10 +383,9 @@ read_STRING_LITERAL_LONG(SerdReader* const reader, // STRING_LITERAL_QUOTE and STRING_LITERAL_SINGLE_QUOTE // Initial quote is already eaten by caller static SerdStatus -read_STRING_LITERAL(SerdReader* const reader, - SerdNode* const ref, - SerdNodeFlags* const flags, - const uint8_t q) +read_STRING_LITERAL(SerdReader* const reader, + SerdNode* const ref, + const uint8_t q) { SerdStatus st = SERD_SUCCESS; @@ -409,7 +401,7 @@ read_STRING_LITERAL(SerdReader* const reader, return r_err(reader, SERD_ERR_BAD_SYNTAX, "line end in short string\n"); case '\\': eat_byte_safe(reader, c); - if ((st = read_ECHAR(reader, ref, flags)) && + if ((st = read_ECHAR(reader, ref)) && (st = read_UCHAR(reader, ref, &code))) { return r_err(reader, st, "invalid escape `\\%c'\n", peek_byte(reader)); } @@ -419,20 +411,18 @@ read_STRING_LITERAL(SerdReader* const reader, eat_byte_check(reader, q); return SERD_SUCCESS; } else { - st = - read_character(reader, ref, flags, (uint8_t)eat_byte_safe(reader, c)); + st = read_character(reader, ref, (uint8_t)eat_byte_safe(reader, c)); } } } - return st ? st - : (eat_byte_check(reader, q) ? SERD_SUCCESS : SERD_ERR_BAD_SYNTAX); + return st ? st + : eat_byte_check(reader, q) ? SERD_SUCCESS + : SERD_ERR_BAD_SYNTAX; } static SerdStatus -read_String(SerdReader* const reader, - SerdNode* const node, - SerdNodeFlags* const flags) +read_String(SerdReader* const reader, SerdNode* const node) { const int q1 = peek_byte(reader); eat_byte_safe(reader, q1); @@ -443,7 +433,7 @@ read_String(SerdReader* const reader, } if (q2 != q1) { // Short string (not triple quoted) - return read_STRING_LITERAL(reader, node, flags, (uint8_t)q1); + return read_STRING_LITERAL(reader, node, (uint8_t)q1); } eat_byte_safe(reader, q2); @@ -462,7 +452,7 @@ read_String(SerdReader* const reader, } eat_byte_safe(reader, q3); - return read_STRING_LITERAL_LONG(reader, node, flags, (uint8_t)q1); + return read_STRING_LITERAL_LONG(reader, node, (uint8_t)q1); } static bool @@ -844,10 +834,9 @@ read_0_9(SerdReader* const reader, SerdNode* const str, const bool at_least_one) } static SerdStatus -read_number(SerdReader* const reader, - SerdNode** const dest, - SerdNodeFlags* const flags, - bool* const ate_dot) +read_number(SerdReader* const reader, + SerdNode** const dest, + bool* const ate_dot) { #define XSD_DECIMAL NS_XSD "decimal" #define XSD_DOUBLE NS_XSD "double" @@ -903,13 +892,13 @@ read_number(SerdReader* const reader, } TRY(st, read_0_9(reader, *dest, true)); push_node(reader, SERD_URI, XSD_DOUBLE, sizeof(XSD_DOUBLE) - 1); - *flags |= SERD_HAS_DATATYPE; + (*dest)->flags |= SERD_HAS_DATATYPE; } else if (has_decimal) { push_node(reader, SERD_URI, XSD_DECIMAL, sizeof(XSD_DECIMAL) - 1); - *flags |= SERD_HAS_DATATYPE; + (*dest)->flags |= SERD_HAS_DATATYPE; } else { push_node(reader, SERD_URI, XSD_INTEGER, sizeof(XSD_INTEGER) - 1); - *flags |= SERD_HAS_DATATYPE; + (*dest)->flags |= SERD_HAS_DATATYPE; } return SERD_SUCCESS; @@ -930,14 +919,13 @@ read_iri(SerdReader* const reader, SerdNode** const dest, bool* const ate_dot) } static SerdStatus -read_literal(SerdReader* const reader, - SerdNode** const dest, - SerdNodeFlags* const flags, - bool* const ate_dot) +read_literal(SerdReader* const reader, + SerdNode** const dest, + bool* const ate_dot) { *dest = push_node(reader, SERD_LITERAL, "", 0); - SerdStatus st = read_String(reader, *dest, flags); + SerdStatus st = read_String(reader, *dest); if (st) { *dest = NULL; return st; @@ -947,7 +935,7 @@ read_literal(SerdReader* const reader, switch (peek_byte(reader)) { case '@': eat_byte_safe(reader, '@'); - *flags |= SERD_HAS_LANGUAGE; + (*dest)->flags |= SERD_HAS_LANGUAGE; if ((st = read_LANGTAG(reader))) { return r_err(reader, st, "bad literal\n"); } @@ -955,7 +943,7 @@ read_literal(SerdReader* const reader, case '^': eat_byte_safe(reader, '^'); eat_byte_check(reader, '^'); - *flags |= SERD_HAS_DATATYPE; + (*dest)->flags |= SERD_HAS_DATATYPE; if ((st = read_iri(reader, &datatype, ate_dot))) { return r_err(reader, st, "bad literal\n"); } @@ -1114,12 +1102,10 @@ read_object(SerdReader* const reader, const size_t orig_stack_size = reader->stack.size; - SerdStatus ret = SERD_FAILURE; - - bool simple = (ctx->subject != 0); - SerdNode* o = 0; - uint32_t flags = 0; - const int c = peek_byte(reader); + SerdStatus ret = SERD_FAILURE; + bool simple = (ctx->subject != 0); + SerdNode* o = 0; + const int c = peek_byte(reader); if (!fancy_syntax(reader)) { switch (c) { case '"': @@ -1163,11 +1149,11 @@ read_object(SerdReader* const reader, case '7': case '8': case '9': - ret = read_number(reader, &o, &flags, ate_dot); + ret = read_number(reader, &o, ate_dot); break; case '\"': case '\'': - ret = read_literal(reader, &o, &flags, ate_dot); + ret = read_literal(reader, &o, ate_dot); break; default: /* Either a boolean literal, or a qname. Read the prefix first, and if @@ -1181,7 +1167,7 @@ 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->flags |= SERD_HAS_DATATYPE; o->type = SERD_LITERAL; push_node(reader, SERD_URI, XSD_BOOLEAN, XSD_BOOLEAN_LEN); ret = SERD_SUCCESS; @@ -1195,10 +1181,6 @@ read_object(SerdReader* const reader, } } - if (!ret && simple && o) { - o->flags = flags; - } - if (!ret && emit && simple && o) { ret = emit_statement(reader, *ctx, o); } else if (!ret && !emit) { |