aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/serd/reader.h19
-rw-r--r--src/reader.c9
-rw-r--r--src/serdi.c9
-rw-r--r--test/test_overflow.c2
-rw-r--r--test/test_reader.c10
-rw-r--r--test/test_reader_writer.c10
6 files changed, 26 insertions, 33 deletions
diff --git a/include/serd/reader.h b/include/serd/reader.h
index a2b2698d..5df1acc9 100644
--- a/include/serd/reader.h
+++ b/include/serd/reader.h
@@ -27,23 +27,22 @@ SERD_BEGIN_DECLS
/// Streaming parser that reads a text stream and writes to a statement sink
typedef struct SerdReaderImpl SerdReader;
+/// Reader options
+typedef enum {
+ SERD_READ_LAX = 1U << 0U, ///< Tolerate invalid input where possible
+} SerdReaderFlag;
+
+/// Bitwise OR of SerdReaderFlag values
+typedef uint32_t SerdReaderFlags;
+
/// Create a new RDF reader
SERD_API SerdReader* SERD_ALLOCATED
serd_reader_new(SerdWorld* SERD_NONNULL world,
SerdSyntax syntax,
+ SerdReaderFlags flags,
const SerdSink* SERD_NONNULL sink);
/**
- Enable or disable strict parsing.
-
- The reader is non-strict (lax) by default, which will tolerate URIs with
- invalid characters. Setting strict will fail when parsing such files. An
- error is printed for invalid input in either case.
-*/
-SERD_API void
-serd_reader_set_strict(SerdReader* SERD_NONNULL reader, bool strict);
-
-/**
Set a prefix to be added to all blank node identifiers.
This is useful when multiple files are to be parsed into the same output (a
diff --git a/src/reader.c b/src/reader.c
index f45e9e0d..e819d472 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -161,6 +161,7 @@ serd_reader_read_document(SerdReader* const reader)
SerdReader*
serd_reader_new(SerdWorld* const world,
const SerdSyntax syntax,
+ const SerdReaderFlags flags,
const SerdSink* const sink)
{
const size_t stack_size = world->limits.reader_stack_size;
@@ -175,7 +176,7 @@ serd_reader_new(SerdWorld* const world,
me->stack = serd_stack_new(stack_size);
me->syntax = syntax;
me->next_id = 1;
- me->strict = true;
+ me->strict = !(flags & SERD_READ_LAX);
// Reserve a bit of space at the end of the stack to zero pad nodes
me->stack.buf_size -= serd_node_align;
@@ -193,12 +194,6 @@ serd_reader_new(SerdWorld* const world,
}
void
-serd_reader_set_strict(SerdReader* const reader, const bool strict)
-{
- reader->strict = strict;
-}
-
-void
serd_reader_free(SerdReader* const reader)
{
if (!reader) {
diff --git a/src/serdi.c b/src/serdi.c
index 8a4a52cf..42da9fd5 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -102,11 +102,11 @@ main(int argc, char** argv)
SerdSyntax input_syntax = SERD_SYNTAX_EMPTY;
SerdSyntax output_syntax = SERD_SYNTAX_EMPTY;
+ SerdReaderFlags reader_flags = 0;
SerdWriterFlags writer_flags = 0;
bool from_string = false;
bool from_stdin = false;
bool bulk_read = true;
- bool lax = false;
bool osyntax_set = false;
bool quiet = false;
size_t stack_size = 1048576U;
@@ -142,8 +142,8 @@ main(int argc, char** argv)
} else if (opt == 'h') {
return print_usage(prog, false);
} else if (opt == 'l') {
+ reader_flags |= SERD_READ_LAX;
writer_flags |= SERD_WRITE_LAX;
- lax = true;
} else if (opt == 'q') {
quiet = true;
} else if (opt == 't') {
@@ -254,10 +254,9 @@ main(int argc, char** argv)
const SerdLimits limits = {stack_size, MAX_DEPTH};
serd_world_set_limits(world, limits);
- SerdReader* const reader =
- serd_reader_new(world, input_syntax, serd_writer_sink(writer));
+ SerdReader* const reader = serd_reader_new(
+ world, input_syntax, reader_flags, serd_writer_sink(writer));
- serd_reader_set_strict(reader, !lax);
if (quiet) {
serd_world_set_error_func(world, quiet_error_func, NULL);
}
diff --git a/test/test_overflow.c b/test/test_overflow.c
index ac47d239..6c67d7cc 100644
--- a/test/test_overflow.c
+++ b/test/test_overflow.c
@@ -22,7 +22,7 @@ test_size(SerdWorld* const world,
serd_world_set_limits(world, limits);
SerdSink* sink = serd_sink_new(NULL, NULL, NULL);
- SerdReader* const reader = serd_reader_new(world, syntax, sink);
+ SerdReader* const reader = serd_reader_new(world, syntax, 0U, sink);
if (!reader) {
return SERD_BAD_STACK;
}
diff --git a/test/test_reader.c b/test/test_reader.c
index 6d4956e5..f931b258 100644
--- a/test/test_reader.c
+++ b/test/test_reader.c
@@ -58,7 +58,7 @@ test_read_string(void)
SerdSink* sink = serd_sink_new(&rt, test_sink, NULL);
assert(sink);
- SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink);
+ SerdReader* reader = serd_reader_new(world, SERD_TURTLE, 0U, sink);
assert(reader);
// Test reading a string that ends exactly at the end of input (no newline)
@@ -138,7 +138,7 @@ test_read_eof_by_page(const char* const path)
SerdWorld* world = serd_world_new();
ReaderTest ignored = {0, 0, 0, 0};
SerdSink* sink = serd_sink_new(&ignored, test_sink, NULL);
- SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink);
+ SerdReader* reader = serd_reader_new(world, SERD_TURTLE, 0U, sink);
serd_reader_start_stream(
reader, (SerdReadFunc)fread, (SerdStreamErrorFunc)ferror, f, NULL, 4096);
@@ -160,7 +160,7 @@ test_read_eof_by_byte(void)
SerdWorld* world = serd_world_new();
ReaderTest ignored = {0, 0, 0, 0};
SerdSink* sink = serd_sink_new(&ignored, test_sink, NULL);
- SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink);
+ SerdReader* reader = serd_reader_new(world, SERD_TURTLE, 0U, sink);
size_t n_reads = 0U;
serd_reader_start_stream(reader,
@@ -211,7 +211,7 @@ test_read_nquads_chunks(const char* const path)
SerdSink* const sink = serd_sink_new(&rt, test_sink, NULL);
assert(sink);
- SerdReader* const reader = serd_reader_new(world, SERD_NQUADS, sink);
+ SerdReader* const reader = serd_reader_new(world, SERD_NQUADS, 0U, sink);
assert(reader);
SerdStatus st = serd_reader_start_stream(
@@ -290,7 +290,7 @@ test_read_turtle_chunks(const char* const path)
SerdSink* sink = serd_sink_new(&rt, test_sink, NULL);
assert(sink);
- SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink);
+ SerdReader* reader = serd_reader_new(world, SERD_TURTLE, 0U, sink);
assert(reader);
SerdStatus st = serd_reader_start_stream(
diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c
index fcd4a2b8..67c0d7ba 100644
--- a/test/test_reader_writer.c
+++ b/test/test_reader_writer.c
@@ -115,8 +115,8 @@ test_write_errors(void)
SerdWriter* const writer =
serd_writer_new(world, syntax, 0U, env, faulty_sink, &ctx);
- const SerdSink* const sink = serd_writer_sink(writer);
- SerdReader* const reader = serd_reader_new(world, SERD_TRIG, sink);
+ const SerdSink* const sink = serd_writer_sink(writer);
+ SerdReader* const reader = serd_reader_new(world, SERD_TRIG, 0U, sink);
SerdStatus st = serd_reader_start_string(reader, doc_string, NULL);
assert(!st);
@@ -246,11 +246,11 @@ test_reader(const char* path)
SerdLimits limits = old_limits;
limits.reader_stack_size = 32U;
serd_world_set_limits(world, limits);
- assert(!serd_reader_new(world, SERD_TURTLE, sink));
+ assert(!serd_reader_new(world, SERD_TURTLE, 0U, sink));
- // Restore original limits and successfully create reader
+ // Restore limits and successfully create reader
serd_world_set_limits(world, old_limits);
- SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink);
+ SerdReader* reader = serd_reader_new(world, SERD_TURTLE, 0U, sink);
assert(reader);
assert(serd_reader_read_chunk(reader) == SERD_FAILURE);