aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-05-13 00:47:58 +0200
committerDavid Robillard <d@drobilla.net>2023-12-02 16:27:02 -0500
commit8771f4611a37efbe2841abe6db06c662490bdd88 (patch)
tree5fca8b3ef419600f954c6731a91009cc1ca49356 /src
parent3fc450d7f586388135028ac83870d288834c34a1 (diff)
downloadserd-8771f4611a37efbe2841abe6db06c662490bdd88.tar.gz
serd-8771f4611a37efbe2841abe6db06c662490bdd88.tar.bz2
serd-8771f4611a37efbe2841abe6db06c662490bdd88.zip
Remove datatype and language from reader context
Diffstat (limited to 'src')
-rw-r--r--src/n3.c70
-rw-r--r--src/reader.h2
2 files changed, 32 insertions, 40 deletions
diff --git a/src/n3.c b/src/n3.c
index 36f90c4f..7042233f 100644
--- a/src/n3.c
+++ b/src/n3.c
@@ -675,26 +675,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_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_BAD_STACK;
}
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;
@@ -841,7 +842,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)
{
@@ -885,6 +885,9 @@ read_number(SerdReader* const reader,
read_0_9(reader, *dest, false);
}
}
+
+ SerdNode* meta = NULL;
+
c = peek_byte(reader);
if (c == 'e' || c == 'E') {
// double
@@ -898,20 +901,16 @@ 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);
+ meta = 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);
+ meta = push_node(reader, SERD_URI, XSD_DECIMAL, sizeof(XSD_DECIMAL) - 1);
} else {
- *datatype =
- push_node(reader, SERD_URI, XSD_INTEGER, sizeof(XSD_INTEGER) - 1);
+ meta = push_node(reader, SERD_URI, XSD_INTEGER, sizeof(XSD_INTEGER) - 1);
}
- if (*datatype) {
- *flags |= SERD_HAS_DATATYPE;
- }
-
- return SERD_SUCCESS;
+ *flags |= SERD_HAS_DATATYPE;
+ return meta ? SERD_SUCCESS : SERD_BAD_STACK;
}
static SerdStatus
@@ -931,8 +930,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)
{
@@ -944,11 +941,12 @@ read_literal(SerdReader* const reader,
return st;
}
+ SerdNode* datatype = NULL;
switch (peek_byte(reader)) {
case '@':
skip_byte(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;
@@ -959,7 +957,7 @@ read_literal(SerdReader* const 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 datatype\n");
}
break;
@@ -1130,12 +1128,10 @@ read_object(SerdReader* const reader,
SerdStatus st = 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 '"':
@@ -1179,11 +1175,11 @@ read_object(SerdReader* const reader,
case '7':
case '8':
case '9':
- st = read_number(reader, &o, &datatype, &flags, ate_dot);
+ st = read_number(reader, &o, &flags, ate_dot);
break;
case '\"':
case '\'':
- st = read_literal(reader, &o, &datatype, &lang, &flags, ate_dot);
+ st = read_literal(reader, &o, &flags, ate_dot);
break;
default:
/* Either a boolean literal, or a qname. Read the prefix first, and if
@@ -1197,10 +1193,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);
- st = SERD_SUCCESS;
+ flags = flags | SERD_HAS_DATATYPE;
+ o->type = SERD_LITERAL;
+ push_node(reader, SERD_URI, XSD_BOOLEAN, XSD_BOOLEAN_LEN);
+ st = SERD_SUCCESS;
} else if (read_PN_PREFIX_tail(reader, o) > SERD_FAILURE) {
st = SERD_BAD_SYNTAX;
} else {
@@ -1218,9 +1214,7 @@ read_object(SerdReader* const reader,
if (!st && emit && simple) {
st = emit_statement(reader, *ctx, o);
} else if (!st && !emit) {
- ctx->object = o;
- ctx->datatype = datatype;
- ctx->lang = lang;
+ ctx->object = o;
return SERD_SUCCESS;
}
@@ -1583,7 +1577,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;
@@ -1696,7 +1690,7 @@ read_nquads_statement(SerdReader* const reader)
{
SerdStatus st = SERD_SUCCESS;
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;
diff --git a/src/reader.h b/src/reader.h
index d126aeaa..7f5fe521 100644
--- a/src/reader.h
+++ b/src/reader.h
@@ -27,8 +27,6 @@ typedef struct {
SerdNode* subject;
SerdNode* predicate;
SerdNode* object;
- SerdNode* datatype;
- SerdNode* lang;
SerdStatementFlags* flags;
} ReadContext;