aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-06-03 22:23:28 +0200
committerDavid Robillard <d@drobilla.net>2018-12-31 11:37:48 -0500
commitb6197eb59799c2933bd776ea22760fea5e97b4bd (patch)
tree7d924d86285ca33d6d7cf241501811f3616429aa
parent5246440bc489b9b8168d0e26700cf5f343895169 (diff)
downloadserd-b6197eb59799c2933bd776ea22760fea5e97b4bd.tar.gz
serd-b6197eb59799c2933bd776ea22760fea5e97b4bd.tar.bz2
serd-b6197eb59799c2933bd776ea22760fea5e97b4bd.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.c3
-rw-r--r--src/statement.c6
-rw-r--r--src/statement.h3
5 files changed, 19 insertions, 3 deletions
diff --git a/serd/serd.h b/serd/serd.h
index 6f8dece4..18a95b20 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -1266,6 +1266,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 79e2315e..fb06bdc3 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -126,7 +126,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 bc5e2287..b0437c66 100644
--- a/src/sink.c
+++ b/src/sink.c
@@ -47,7 +47,8 @@ serd_sink_write(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 5e2802eb..24440a38 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 7b5d752d..7c8384e9 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