aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-08-15 19:54:39 +0200
committerDavid Robillard <d@drobilla.net>2021-03-08 23:23:05 -0500
commitbadd13ca1dd487a9327481d0f709741ba2127917 (patch)
treeeba9ae5a706a70f8ad4e634791c5fe7bd7c9a919 /src
parentfd4b39f477302ae5529aa63e78cb15b20ba04167 (diff)
downloadserd-badd13ca1dd487a9327481d0f709741ba2127917.tar.gz
serd-badd13ca1dd487a9327481d0f709741ba2127917.tar.bz2
serd-badd13ca1dd487a9327481d0f709741ba2127917.zip
Set flags directly when reading literal nodes
Diffstat (limited to 'src')
-rw-r--r--src/n3.c92
1 files changed, 35 insertions, 57 deletions
diff --git a/src/n3.c b/src/n3.c
index bf65b038..b396b326 100644
--- a/src/n3.c
+++ b/src/n3.c
@@ -142,7 +142,7 @@ read_UCHAR(SerdReader* reader, SerdNode* dest, uint32_t* char_code)
// Read ECHAR escape, initial \ is already eaten by caller
static inline SerdStatus
-read_ECHAR(SerdReader* reader, SerdNode* dest, SerdNodeFlags* flags)
+read_ECHAR(SerdReader* reader, SerdNode* dest)
{
const int c = peek_byte(reader);
switch (c) {
@@ -153,11 +153,11 @@ read_ECHAR(SerdReader* reader, SerdNode* dest, SerdNodeFlags* flags)
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':
@@ -242,20 +242,17 @@ read_utf8_code(SerdReader* reader, SerdNode* dest, uint32_t* code, uint8_t c)
// Read one character (possibly multi-byte)
// The first byte, c, has already been eaten by caller
static inline SerdStatus
-read_character(SerdReader* reader,
- SerdNode* dest,
- SerdNodeFlags* flags,
- uint8_t c)
+read_character(SerdReader* reader, SerdNode* dest, 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;
@@ -327,10 +324,7 @@ eat_delim(SerdReader* reader, const char 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* reader,
- SerdNode* ref,
- SerdNodeFlags* flags,
- uint8_t q)
+read_STRING_LITERAL_LONG(SerdReader* reader, SerdNode* ref, uint8_t q)
{
SerdStatus st = SERD_SUCCESS;
@@ -339,7 +333,7 @@ read_STRING_LITERAL_LONG(SerdReader* 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));
}
@@ -351,14 +345,13 @@ read_STRING_LITERAL_LONG(SerdReader* 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));
}
}
@@ -368,10 +361,7 @@ read_STRING_LITERAL_LONG(SerdReader* reader,
// STRING_LITERAL_QUOTE and STRING_LITERAL_SINGLE_QUOTE
// Initial quote is already eaten by caller
static SerdStatus
-read_STRING_LITERAL(SerdReader* reader,
- SerdNode* ref,
- SerdNodeFlags* flags,
- uint8_t q)
+read_STRING_LITERAL(SerdReader* reader, SerdNode* ref, uint8_t q)
{
SerdStatus st = SERD_SUCCESS;
@@ -387,7 +377,7 @@ read_STRING_LITERAL(SerdReader* 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));
}
@@ -397,18 +387,18 @@ read_STRING_LITERAL(SerdReader* 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* reader, SerdNode* node, SerdNodeFlags* flags)
+read_String(SerdReader* reader, SerdNode* node)
{
const int q1 = peek_byte(reader);
eat_byte_safe(reader, q1);
@@ -419,7 +409,7 @@ read_String(SerdReader* reader, SerdNode* node, SerdNodeFlags* flags)
}
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);
@@ -438,7 +428,7 @@ read_String(SerdReader* reader, SerdNode* node, SerdNodeFlags* flags)
}
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 inline bool
@@ -817,10 +807,7 @@ read_0_9(SerdReader* reader, SerdNode* str, bool at_least_one)
}
static SerdStatus
-read_number(SerdReader* reader,
- SerdNode** dest,
- SerdNodeFlags* flags,
- bool* ate_dot)
+read_number(SerdReader* reader, SerdNode** dest, bool* ate_dot)
{
#define XSD_DECIMAL NS_XSD "decimal"
#define XSD_DOUBLE NS_XSD "double"
@@ -875,13 +862,13 @@ read_number(SerdReader* 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;
@@ -902,14 +889,11 @@ read_iri(SerdReader* reader, SerdNode** dest, bool* ate_dot)
}
static SerdStatus
-read_literal(SerdReader* reader,
- SerdNode** dest,
- SerdNodeFlags* flags,
- bool* ate_dot)
+read_literal(SerdReader* reader, SerdNode** dest, bool* 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;
@@ -920,7 +904,7 @@ read_literal(SerdReader* reader,
switch (peek_byte(reader)) {
case '@':
eat_byte_safe(reader, '@');
- *flags |= SERD_HAS_LANGUAGE;
+ (*dest)->flags |= SERD_HAS_LANGUAGE;
if ((st = read_LANGTAG(reader, &lang))) {
return r_err(reader, st, "bad literal\n");
}
@@ -928,7 +912,7 @@ read_literal(SerdReader* 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");
}
@@ -1093,12 +1077,10 @@ read_object(SerdReader* reader, ReadContext* ctx, bool emit, bool* ate_dot)
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 '"':
@@ -1142,11 +1124,11 @@ read_object(SerdReader* reader, ReadContext* ctx, bool emit, bool* ate_dot)
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
@@ -1160,7 +1142,7 @@ read_object(SerdReader* reader, ReadContext* ctx, bool emit, bool* ate_dot)
}
if ((o->n_bytes == 4 && !memcmp(serd_node_string(o), "true", 4)) ||
(o->n_bytes == 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;
@@ -1174,10 +1156,6 @@ read_object(SerdReader* reader, ReadContext* ctx, bool emit, bool* ate_dot)
}
}
- if (!ret && simple && o) {
- o->flags = flags;
- }
-
if (!ret && emit && simple && o) {
ret = emit_statement(reader, *ctx, o);
} else if (!ret && !emit) {