aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-02-23 12:19:14 -0500
committerDavid Robillard <d@drobilla.net>2023-12-02 18:49:07 -0500
commitc661dbe50d7f634ec5b2863260f41f098fc9c882 (patch)
tree0db5fcf81e2c43b7d548883ff206e151ee790dd4
parentd80b2a1c153f81685d026f8e09c12175abed3d03 (diff)
downloadserd-c661dbe50d7f634ec5b2863260f41f098fc9c882.tar.gz
serd-c661dbe50d7f634ec5b2863260f41f098fc9c882.tar.bz2
serd-c661dbe50d7f634ec5b2863260f41f098fc9c882.zip
Simplify reading code with TRY_LAX macro
-rw-r--r--src/read_turtle.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/read_turtle.c b/src/read_turtle.c
index ef76c858..19a47ebf 100644
--- a/src/read_turtle.c
+++ b/src/read_turtle.c
@@ -26,6 +26,14 @@
#include <stdio.h>
#include <string.h>
+/// Like TRY() but tolerates SERD_FAILURE
+#define TRY_LAX(st, exp) \
+ do { \
+ if (((st) = (exp)) > SERD_FAILURE) { \
+ return (st); \
+ } \
+ } while (0)
+
static SerdStatus
read_collection(SerdReader* reader, ReadContext ctx, SerdNode** dest);
@@ -301,7 +309,7 @@ read_PrefixedName(SerdReader* const reader,
{
SerdStatus st = SERD_SUCCESS;
if (read_prefix) {
- TRY_FAILING(st, read_PN_PREFIX(reader, dest));
+ TRY_LAX(st, read_PN_PREFIX(reader, dest));
}
if (peek_byte(reader) != ':') {
@@ -464,10 +472,8 @@ read_verb(SerdReader* const reader, SerdNode** const dest)
return SERD_BAD_STACK;
}
- SerdStatus st = read_PN_PREFIX(reader, *dest);
- if (st > SERD_FAILURE) {
- return st;
- }
+ SerdStatus st = SERD_SUCCESS;
+ TRY_LAX(st, read_PN_PREFIX(reader, *dest));
bool ate_dot = false;
SerdNode* node = *dest;
@@ -897,8 +903,7 @@ read_turtle_prefixID(SerdReader* const reader,
return SERD_BAD_STACK;
}
- TRY_FAILING(st, read_PN_PREFIX(reader, name));
-
+ TRY_LAX(st, read_PN_PREFIX(reader, name));
TRY(st, eat_byte_check(reader, ':'));
read_turtle_ws_star(reader);
@@ -959,10 +964,7 @@ read_block(SerdReader* const reader, ReadContext* const ctx)
// Try to read a subject, though it may actually be a directive or graph name
SerdNode* token = NULL;
int s_type = 0;
- if ((st = read_turtle_subject(reader, *ctx, &token, &s_type)) >
- SERD_FAILURE) {
- return st;
- }
+ TRY_LAX(st, read_turtle_subject(reader, *ctx, &token, &s_type));
// Try to interpret as a SPARQL "PREFIX" or "BASE" directive
if (st && (st = read_sparql_directive(reader, token)) != SERD_FAILURE) {
@@ -976,9 +978,7 @@ read_block(SerdReader* const reader, ReadContext* const ctx)
// Our token is really a subject, read some triples
bool ate_dot = false;
ctx->subject = token;
- if ((st = read_turtle_triples(reader, *ctx, &ate_dot)) > SERD_FAILURE) {
- return st;
- }
+ TRY_LAX(st, read_turtle_triples(reader, *ctx, &ate_dot));
// "Failure" is only allowed for anonymous subjects like "[ ... ] ."
if (st && s_type != '[') {