aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-06-03 22:23:28 +0200
committerDavid Robillard <d@drobilla.net>2020-06-21 18:12:04 +0200
commit5329ada96fd9d746aa1302eb353efccf9ba4a1b3 (patch)
tree0024ff2827962f9c791bec8d484f1c7691729b36
parent8c4a8baf4f9081bdb9523c08005a529a71fd6722 (diff)
downloadserd-5329ada96fd9d746aa1302eb353efccf9ba4a1b3.tar.gz
serd-5329ada96fd9d746aa1302eb353efccf9ba4a1b3.tar.bz2
serd-5329ada96fd9d746aa1302eb353efccf9ba4a1b3.zip
Add cursor to statement
This allows the file and position of statements to be used in sinks, for example for more helpful error reporting outside the parser.
-rw-r--r--serd/serd.h7
-rw-r--r--src/reader.c3
-rw-r--r--src/sink.c5
-rw-r--r--src/statement.c6
-rw-r--r--src/statement.h3
5 files changed, 21 insertions, 3 deletions
diff --git a/serd/serd.h b/serd/serd.h
index 2e45225b..29422ef1 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -1301,6 +1301,13 @@ const SerdNode*
serd_statement_get_graph(const SerdStatement* statement);
/**
+ Return the source location where `statement` originated, or NULL.
+*/
+SERD_API
+const SerdCursor*
+serd_statement_get_cursor(const SerdStatement* statement);
+
+/**
@}
@name Cursor
@{
diff --git a/src/reader.c b/src/reader.c
index 8ec9f32e..82f92a44 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -128,7 +128,8 @@ emit_statement(SerdReader* reader, ReadContext ctx, SerdNode* o)
serd_node_zero_pad(o);
const SerdStatement statement = {
- { ctx.subject, ctx.predicate, o, graph }
+ { ctx.subject, ctx.predicate, o, graph },
+ &reader->source.cur
};
const SerdStatus st = reader->sink->statement(
diff --git a/src/sink.c b/src/sink.c
index 1c5c500f..40071d72 100644
--- a/src/sink.c
+++ b/src/sink.c
@@ -18,6 +18,8 @@
#include "statement.h"
+#include <stddef.h>
+
SerdStatus
serd_sink_write_base(const SerdSink* sink, const SerdNode* uri)
{
@@ -48,7 +50,8 @@ serd_sink_write(const SerdSink* sink,
const SerdNode* object,
const SerdNode* graph)
{
- const SerdStatement statement = { { subject, predicate, object, graph } };
+ const SerdStatement statement = { { subject, predicate, object, graph },
+ NULL };
return sink->statement(sink->handle, flags, &statement);
}
diff --git a/src/statement.c b/src/statement.c
index db076a38..e5062dfe 100644
--- a/src/statement.c
+++ b/src/statement.c
@@ -45,3 +45,9 @@ serd_statement_get_graph(const SerdStatement* statement)
{
return statement->nodes[SERD_GRAPH];
}
+
+const SerdCursor*
+serd_statement_get_cursor(const SerdStatement* statement)
+{
+ return statement->cursor;
+}
diff --git a/src/statement.h b/src/statement.h
index 19b4a91f..1cb5345c 100644
--- a/src/statement.h
+++ b/src/statement.h
@@ -27,7 +27,8 @@
typedef const SerdNode* SerdQuad[4];
struct SerdStatementImpl {
- SerdQuad nodes;
+ SerdQuad nodes;
+ SerdCursor* cursor;
};
#endif // SERD_STATEMENT_H