aboutsummaryrefslogtreecommitdiffstats
path: root/serd
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-06-03 22:15:53 +0200
committerDavid Robillard <d@drobilla.net>2020-10-27 13:13:58 +0100
commit6a91bfca72fc2cfd7ba1002174475d71e35b2969 (patch)
treed1689b03faf96f58ac4c7ca9081a600491d09a02 /serd
parent93e54363f5ae251acee94051f77305f60f0158c8 (diff)
downloadserd-6a91bfca72fc2cfd7ba1002174475d71e35b2969.tar.gz
serd-6a91bfca72fc2cfd7ba1002174475d71e35b2969.tar.bz2
serd-6a91bfca72fc2cfd7ba1002174475d71e35b2969.zip
Add SerdCursor to public API
Diffstat (limited to 'serd')
-rw-r--r--serd/serd.h85
1 files changed, 77 insertions, 8 deletions
diff --git a/serd/serd.h b/serd/serd.h
index 1f30065b..1cc68f82 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -72,6 +72,11 @@ typedef struct SerdWorldImpl SerdWorld;
typedef struct SerdStatementImpl SerdStatement;
/**
+ Cursor, the origin of a statement in a document.
+*/
+typedef struct SerdCursorImpl SerdCursor;
+
+/**
Environment.
Represents the state required to resolve a CURIE or relative URI, e.g. the
@@ -258,12 +263,10 @@ typedef struct {
An error description.
*/
typedef struct {
- SerdStatus status; /**< Error code */
- const char* filename; /**< File where error was encountered, or NULL */
- unsigned line; /**< Line where error was encountered, or 0 */
- unsigned col; /**< Column where error was encountered */
- const char* fmt; /**< Message format string (printf style) */
- va_list* args; /**< Arguments for fmt */
+ SerdStatus status; /**< Error code */
+ const SerdCursor* cursor; /**< Origin of error, or NULL */
+ const char* fmt; /**< Message format string (printf style) */
+ va_list* args; /**< Arguments for fmt */
} SerdError;
/**
@@ -1110,7 +1113,7 @@ serd_reader_start_stream(SerdReader* reader,
SerdReadFunc read_func,
SerdStreamErrorFunc error_func,
void* stream,
- const char* name,
+ const SerdNode* name,
size_t page_size);
/**
@@ -1118,7 +1121,9 @@ serd_reader_start_stream(SerdReader* reader,
*/
SERD_API
SerdStatus
-serd_reader_start_string(SerdReader* reader, const char* utf8);
+serd_reader_start_string(SerdReader* reader,
+ const char* utf8,
+ const SerdNode* name);
/**
Read a single "chunk" of data during an incremental read.
@@ -1301,6 +1306,70 @@ serd_statement_graph(const SerdStatement* statement);
/**
@}
+ @name Cursor
+ @{
+*/
+
+/**
+ Create a new cursor
+
+ Note that, to minimise model overhead, the cursor does not own the name
+ node, so `name` must have a longer lifetime than the cursor for it to be
+ valid. That is, serd_cursor_name() will return exactly the pointer
+ `name`, not a copy. For cursors from models, this is the lifetime of the
+ model. For user-created cursors, the simplest way to handle this is to use
+ `SerdNodes`.
+
+ @param name The name of the document or stream (usually a file URI)
+ @param line The line number in the document (1-based)
+ @param col The column number in the document (1-based)
+ @return A new cursor that must be freed with serd_cursor_free()
+*/
+SERD_API
+SerdCursor*
+serd_cursor_new(const SerdNode* name, unsigned line, unsigned col);
+
+/// Return a copy of `cursor`
+SERD_API
+SerdCursor*
+serd_cursor_copy(const SerdCursor* cursor);
+
+/// Free `cursor`
+SERD_API
+void
+serd_cursor_free(SerdCursor* cursor);
+
+/// Return true iff `lhs` is equal to `rhs`
+SERD_API
+bool
+serd_cursor_equals(const SerdCursor* lhs, const SerdCursor* rhs);
+
+/**
+ Return the document name.
+
+ This is typically a file URI, but may be a descriptive string node for
+ statements that originate from streams.
+*/
+SERD_API
+const SerdNode*
+serd_cursor_name(const SerdCursor* cursor);
+
+/**
+ Return the one-relative line number in the document.
+*/
+SERD_API
+unsigned
+serd_cursor_line(const SerdCursor* cursor);
+
+/**
+ Return the zero-relative column number in the line.
+*/
+SERD_API
+unsigned
+serd_cursor_column(const SerdCursor* cursor);
+
+/**
+ @}
@}
*/