diff options
Diffstat (limited to 'src/reader.h')
-rw-r--r-- | src/reader.h | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/reader.h b/src/reader.h index d5c8595b..842ba8b8 100644 --- a/src/reader.h +++ b/src/reader.h @@ -14,8 +14,93 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#ifndef SERD_READER_H +#define SERD_READER_H + #include "serd_internal.h" +#include "byte_source.h" +#include "node.h" +#include "stack.h" + +#ifdef SERD_STACK_CHECK +# define SERD_STACK_ASSERT_TOP(reader, ref) \ + assert(ref == reader->allocs[reader->n_allocs - 1]); +#else +# define SERD_STACK_ASSERT_TOP(reader, ref) +#endif + +/* Reference to a node in the stack (we can not use pointers since the + stack may be reallocated, invalidating any pointers to elements). +*/ +typedef size_t Ref; + +typedef struct { + Ref graph; + Ref subject; + Ref predicate; + Ref object; + Ref datatype; + Ref lang; + SerdStatementFlags* flags; +} ReadContext; + +struct SerdReaderImpl { + void* handle; + void (*free_handle)(void* ptr); + SerdBaseSink base_sink; + SerdPrefixSink prefix_sink; + SerdStatementSink statement_sink; + SerdEndSink end_sink; + SerdErrorSink error_sink; + void* error_handle; + Ref rdf_first; + Ref rdf_rest; + Ref rdf_nil; + SerdNode* default_graph; + SerdByteSource source; + SerdStack stack; + SerdSyntax syntax; + unsigned next_id; + SerdStatus status; + uint8_t* buf; + char* bprefix; + size_t bprefix_len; + bool strict; ///< True iff strict parsing + bool seen_genid; +#ifdef SERD_STACK_CHECK + Ref* allocs; ///< Stack of push offsets + size_t n_allocs; ///< Number of stack pushes +#endif +}; + +int r_err(SerdReader* reader, SerdStatus st, const char* fmt, ...); + +Ref push_node_padded(SerdReader* reader, + size_t maxlen, + SerdType type, + const char* str, + size_t n_bytes); + +Ref push_node(SerdReader* reader, + SerdType type, + const char* str, + size_t n_bytes); + +size_t genid_size(SerdReader* reader); +Ref blank_id(SerdReader* reader); +void set_blank_id(SerdReader* reader, Ref ref, size_t buf_size); + +SerdNode* deref(SerdReader* reader, Ref ref); + +Ref pop_node(SerdReader* reader, Ref ref); + +bool emit_statement(SerdReader* reader, ReadContext ctx, Ref o, Ref d, Ref l); + +bool read_n3_statement(SerdReader* reader); +SerdStatus read_nquadsDoc(SerdReader* reader); +SerdStatus read_turtleTrigDoc(SerdReader* reader); + static inline uint8_t peek_byte(SerdReader* reader) { @@ -81,3 +166,5 @@ push_bytes(SerdReader* reader, Ref ref, const uint8_t* bytes, unsigned len) push_byte(reader, ref, bytes[i]); } } + +#endif // SERD_READER_H |