35 if (((st) = (exp))) { \
83 uint8_t buf[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
95 if (
code < 0x00000080) {
97 }
else if (
code < 0x00000800) {
99 }
else if (
code < 0x00010000) {
101 }
else if (
code < 0x00110000) {
106 "unicode character 0x%X out of range\n",
118 buf[3] = (
uint8_t)(0x80u | (
c & 0x3Fu));
123 buf[2] = (
uint8_t)(0x80u | (
c & 0x3Fu));
128 buf[1] = (
uint8_t)(0x80u | (
c & 0x3Fu));
200 return bad_char(reader,
"invalid UTF-8 start 0x%X\n",
c);
204 for (
unsigned i = 1;
i < *
size; ++
i) {
206 if (
b == EOF || ((
uint8_t)
b & 0x80) == 0) {
221 uint8_t bytes[4] = {0, 0, 0, 0};
236 uint8_t bytes[4] = {0, 0, 0, 0};
278 while (((
c =
peek_byte(reader)) != 0xA) &&
c != 0xD &&
c != EOF &&
c) {
340 while (!(st && reader->
strict)) {
347 return r_err(reader, st,
"invalid escape `\\%c'\n",
peek_byte(reader));
353 if (q2 ==
q && q3 ==
q) {
360 }
else if (
c == EOF) {
381 while (!(st && reader->
strict)) {
395 return r_err(reader, st,
"invalid escape `\\%c'\n",
peek_byte(reader));
450 return ((
c >= 0x00C0 &&
c <= 0x00D6) || (
c >= 0x00D8 &&
c <= 0x00F6) ||
451 (
c >= 0x00F8 &&
c <= 0x02FF) || (
c >= 0x0370 &&
c <= 0x037D) ||
452 (
c >= 0x037F &&
c <= 0x1FFF) || (
c >= 0x200C &&
c <= 0x200D) ||
453 (
c >= 0x2070 &&
c <= 0x218F) || (
c >= 0x2C00 &&
c <= 0x2FEF) ||
454 (
c >= 0x3001 &&
c <= 0xD7FF) || (
c >= 0xF900 &&
c <= 0xFDCF) ||
455 (
c >= 0xFDF0 &&
c <= 0xFFFD) || (
c >= 0x10000 &&
c <= 0xEFFFF));
466 }
else if (
c == EOF || !(
c & 0x80)) {
485 (
c >= 0x203F &&
c <= 0x2040));
496 }
else if (
c == EOF || !(
c & 0x80)) {
577 bool trailing_unescaped_dot =
false;
595 return r_err(reader, st,
"bad escape\n");
602 if (
c ==
'.' ||
c ==
':') {
609 trailing_unescaped_dot = (
c ==
'.');
613 if (trailing_unescaped_dot) {
696 "bad IRI scheme char U+%04X (%c)\n",
752 "invalid escaped IRI character U+%04X\n",
772 "invalid IRI character (escape %%%02X)\n",
780 }
else if (!(
c & 0x80)) {
823 if (at_least_one &&
count == 0) {
833#define XSD_DECIMAL NS_XSD "decimal"
834#define XSD_DOUBLE NS_XSD "double"
835#define XSD_INTEGER NS_XSD "integer"
841 bool has_decimal =
false;
842 if (
c ==
'-' ||
c ==
'+') {
869 if (
c ==
'e' ||
c ==
'E') {
881 }
else if (has_decimal) {
924 *datatype =
pop_node(reader, *datatype);
927 return r_err(reader, st,
"bad literal\n");
933 if ((st =
read_iri(reader, datatype, ate_dot))) {
934 *datatype =
pop_node(reader, *datatype);
937 return r_err(reader, st,
"bad literal\n");
958 bool ate_dot =
false;
961 if (!st && node->
n_bytes == 1 && node->
buf[0] ==
'a' && next !=
':' &&
983 const Ref ref = *dest =
1020 return r_err(reader,
1022 "found both `b' and `B' blank IDs, prefix required\n");
1040 bool ate_dot =
false;
1042 read_iri(reader, &subject, &ate_dot);
1079 bool ate_dot_in_list =
false;
1081 if (ate_dot_in_list) {
1090 *ctx.
flags = old_flags;
1103 static const char*
const XSD_BOOLEAN =
NS_XSD "boolean";
1104 static const size_t XSD_BOOLEAN_LEN = 40;
1107 const size_t orig_stack_size = reader->
stack.
size;
1112 bool simple = (ctx->
subject != 0);
1136 ret =
read_anon(reader, *ctx,
false, &o);
1147 ret =
read_iri(reader, &o, ate_dot);
1162 ret =
read_number(reader, &o, &datatype, ate_dot);
1166 ret =
read_literal(reader, &o, &datatype, &lang, &flags, ate_dot);
1175 node =
deref(reader, o);
1176 if ((node->
n_bytes == 4 && !memcmp(node->
buf,
"true", 4)) ||
1177 (node->
n_bytes == 5 && !memcmp(node->
buf,
"false", 5))) {
1187 return r_err(reader, ret,
"expected prefixed name\n");
1192 if (!ret && simple && o) {
1196 if (!ret && emit && simple) {
1198 }
else if (!ret && !emit) {
1224 while (!*ate_dot &&
eat_delim(reader,
',')) {
1242 bool ate_semi =
false;
1319 bool ate_dot =
false;
1320 if ((st =
read_object(reader, &ctx,
true, &ate_dot)) || ate_dot) {
1351 bool ate_dot =
false;
1352 switch ((*s_type =
peek_byte(reader))) {
1363 st =
read_iri(reader, dest, &ate_dot);
1377 bool ate_dot =
false;
1390 if (!
read_iri(reader, dest, &ate_dot)) {
1488 const bool sparql =
peek_byte(reader) !=
'@';
1521 bool ate_dot =
false;
1529 if (
read_triples(reader, *ctx, &ate_dot) && s_type !=
'[') {
1567 bool ate_dot =
false;
1613 if (s_type ==
'(' || (s_type ==
'[' && !*ctx.
flags)) {
1621 }
else if ((st =
read_triples(reader, ctx, &ate_dot))) {
1632 }
else if (!ate_dot) {
1673 bool ate_dot =
false;
1689 (st =
read_object(reader, &ctx,
false, &ate_dot))) {
#define byte
Definition blargg_source.h:87
register unsigned i
Definition inflate.c:1575
static const char * name
Definition pugl.h:1582
SerdStatus
Return status code.
Definition serd.h:100
struct SerdReaderImpl SerdReader
Streaming parser that reads a text stream and writes to a statement sink.
Definition serd.h:94
uint32_t SerdStatementFlags
Bitwise OR of SerdStatementFlag values.
Definition serd.h:133
uint32_t SerdNodeFlags
Bitwise OR of SerdNodeFlag values.
Definition serd.h:196
@ SERD_ERR_ID_CLASH
Encountered clashing blank node IDs.
Definition serd.h:107
@ SERD_ERR_BAD_SYNTAX
Invalid syntax.
Definition serd.h:104
@ SERD_FAILURE
Non-fatal failure.
Definition serd.h:102
@ SERD_SUCCESS
No error.
Definition serd.h:101
@ SERD_TURTLE
Terse triples http://www.w3.org/TR/turtle.
Definition serd.h:114
@ SERD_TRIG
Terse quads http://www.w3.org/TR/trig/.
Definition serd.h:117
@ SERD_URI
Definition serd.h:169
@ SERD_CURIE
Definition serd.h:177
@ SERD_LITERAL
Definition serd.h:159
@ SERD_BLANK
Definition serd.h:186
@ SERD_EMPTY_S
Empty blank node subject.
Definition serd.h:122
@ SERD_LIST_CONT
Continuation of list.
Definition serd.h:129
@ SERD_EMPTY_O
Empty blank node object.
Definition serd.h:123
@ SERD_ANON_S_BEGIN
Start of anonymous subject.
Definition serd.h:124
@ SERD_LIST_O_BEGIN
Start of list object.
Definition serd.h:128
@ SERD_ANON_O_BEGIN
Start of anonymous object.
Definition serd.h:125
@ SERD_ANON_CONT
Continuation of anonymous node.
Definition serd.h:126
@ SERD_LIST_S_BEGIN
Start of list subject.
Definition serd.h:127
@ SERD_HAS_QUOTE
Contains quotes ('"').
Definition serd.h:192
@ SERD_HAS_NEWLINE
Contains line breaks ('\n' or '\r').
Definition serd.h:191
unsigned int uint32_t
Definition mid.cpp:100
unsigned char uint8_t
Definition mid.cpp:98
static bool read_ws_star(SerdReader *reader)
Definition n3.c:304
static uint8_t read_HEX(SerdReader *reader)
Definition n3.c:53
static SerdStatus read_number(SerdReader *reader, Ref *dest, Ref *datatype, bool *ate_dot)
Definition n3.c:831
static bool is_PN_CHARS_BASE(const uint32_t c)
Definition n3.c:448
static SerdStatus read_IRIREF_scheme(SerdReader *reader, Ref dest)
Definition n3.c:681
static SerdStatus read_base(SerdReader *reader, bool sparql, bool token)
Definition n3.c:1419
static SerdStatus read_verb(SerdReader *reader, Ref *dest)
Definition n3.c:946
static SerdStatus read_triples(SerdReader *reader, ReadContext ctx, bool *ate_dot)
Definition n3.c:1399
static SerdStatus read_PN_LOCAL_ESC(SerdReader *reader, Ref dest)
Definition n3.c:523
static SerdStatus read_PN_PREFIX_tail(SerdReader *reader, Ref dest)
Definition n3.c:625
static void skip_until(SerdReader *reader, uint8_t byte)
Definition n3.c:1643
static SerdStatus read_predicateObjectList(SerdReader *reader, ReadContext ctx, bool *ate_dot)
Definition n3.c:1232
static bool eat_delim(SerdReader *reader, const char delim)
Definition n3.c:320
SerdStatus read_turtleTrigDoc(SerdReader *reader)
Definition n3.c:1651
static SerdStatus read_BLANK_NODE_LABEL(SerdReader *reader, Ref *dest, bool *ate_dot)
Definition n3.c:978
static bool peek_delim(SerdReader *reader, const char delim)
Definition n3.c:313
static SerdStatus read_prefixID(SerdReader *reader, bool sparql, bool token)
Definition n3.c:1448
static SerdStatus read_objectList(SerdReader *reader, ReadContext ctx, bool *ate_dot)
Definition n3.c:1215
static SerdStatus read_0_9(SerdReader *reader, Ref str, bool at_least_one)
Definition n3.c:815
static bool fancy_syntax(const SerdReader *reader)
Definition n3.c:41
static SerdStatus read_utf8_code(SerdReader *reader, Ref dest, uint32_t *code, uint8_t c)
Definition n3.c:233
static int tokcmp(SerdReader *reader, Ref ref, const char *tok, size_t n)
Definition n3.c:1552
static SerdStatus read_collection(SerdReader *reader, ReadContext ctx, Ref *dest)
Definition n3.c:1287
static SerdStatus read_directive(SerdReader *reader)
Definition n3.c:1486
static SerdStatus read_iri(SerdReader *reader, Ref *dest, bool *ate_dot)
Definition n3.c:893
SerdStatus read_nquadsDoc(SerdReader *reader)
Definition n3.c:1667
static SerdStatus read_anon(SerdReader *reader, ReadContext ctx, bool subject, Ref *dest)
Definition n3.c:1047
static SerdStatus read_subject(SerdReader *reader, ReadContext ctx, Ref *dest, int *s_type)
Definition n3.c:1348
static SerdStatus read_PN_CHARS(SerdReader *reader, Ref dest)
Definition n3.c:489
static SerdStatus read_STRING_LITERAL_LONG(SerdReader *reader, Ref ref, SerdNodeFlags *flags, uint8_t q)
Definition n3.c:333
static SerdStatus bad_char(SerdReader *reader, const char *fmt, uint8_t c)
Definition n3.c:183
static SerdStatus read_PERCENT(SerdReader *reader, Ref dest)
Definition n3.c:509
static SerdStatus end_collection(SerdReader *reader, ReadContext ctx, Ref n1, Ref n2, SerdStatus st)
Definition n3.c:1269
static SerdStatus read_utf8_bytes(SerdReader *reader, uint8_t bytes[4], uint32_t *size, uint8_t c)
Definition n3.c:196
static Ref read_blankName(SerdReader *reader)
Definition n3.c:1031
static SerdStatus read_wrappedGraph(SerdReader *reader, ReadContext *ctx)
Definition n3.c:1513
static bool is_PN_CHARS(const uint32_t c)
Definition n3.c:482
static SerdStatus read_PN_PREFIX(SerdReader *reader, Ref dest)
Definition n3.c:645
static SerdStatus read_PrefixedName(SerdReader *reader, Ref dest, bool read_prefix, bool *ate_dot)
Definition n3.c:796
static SerdStatus read_PN_CHARS_BASE(SerdReader *reader, Ref dest)
Definition n3.c:459
static SerdStatus read_utf8_character(SerdReader *reader, Ref dest, uint8_t c)
Definition n3.c:218
static SerdStatus read_STRING_LITERAL(SerdReader *reader, Ref ref, SerdNodeFlags *flags, uint8_t q)
Definition n3.c:374
static SerdStatus read_character(SerdReader *reader, Ref dest, SerdNodeFlags *flags, uint8_t c)
Definition n3.c:251
static SerdStatus read_IRIREF(SerdReader *reader, Ref *dest)
Definition n3.c:711
static SerdStatus read_LANGTAG(SerdReader *reader, Ref *dest)
Definition n3.c:655
static void read_comment(SerdReader *reader)
Definition n3.c:274
SerdStatus read_n3_statement(SerdReader *reader)
Definition n3.c:1563
static SerdStatus read_PLX(SerdReader *reader, Ref dest)
Definition n3.c:559
static SerdStatus read_String(SerdReader *reader, Ref node, SerdNodeFlags *flags)
Definition n3.c:414
static bool read_ws(SerdReader *reader)
Definition n3.c:285
static SerdStatus read_PN_LOCAL(SerdReader *reader, Ref dest, bool *ate_dot)
Definition n3.c:573
static SerdStatus read_UCHAR(SerdReader *reader, Ref dest, uint32_t *char_code)
Definition n3.c:66
static SerdStatus read_labelOrSubject(SerdReader *reader, Ref *dest)
Definition n3.c:1375
#define TRY(st, exp)
Definition n3.c:33
static SerdStatus read_ECHAR(SerdReader *reader, Ref dest, SerdNodeFlags *flags)
Definition n3.c:146
png_uint_32 length
Definition png.c:2247
static int peek_byte(SerdReader *reader)
Definition reader.h:128
static int eat_byte_safe(SerdReader *reader, const int byte)
Definition reader.h:136
static int eat_byte_check(SerdReader *reader, const int byte)
Definition reader.h:148
static SerdStatus push_byte(SerdReader *reader, Ref ref, const int c)
Definition reader.h:170
static SerdStatus eat_string(SerdReader *reader, const char *str, unsigned n)
Definition reader.h:159
static void push_bytes(SerdReader *reader, Ref ref, const uint8_t *bytes, unsigned len)
Definition reader.h:189
size_t Ref
Definition reader.h:46
static void serd_stack_pop(SerdStack *stack, size_t n_bytes)
Definition stack.h:80
static const uint8_t replacement_char[]
Definition string_utils.h:27
static int serd_strncasecmp(const char *s1, const char *s2, size_t n)
Definition string_utils.h:112
static uint32_t utf8_num_bytes(const uint8_t c)
Definition string_utils.h:124
static bool is_xdigit(const int c)
Definition string_utils.h:59
static uint32_t parse_counted_utf8_char(const uint8_t *utf8, size_t size)
Return the code point of a UTF-8 character with known length.
Definition string_utils.h:147
static bool is_digit(const int c)
Definition string_utils.h:45
static bool is_alpha(const int c)
Definition string_utils.h:38
Ref object
Definition reader.h:52
SerdStatementFlags * flags
Definition reader.h:55
Ref graph
Definition reader.h:49
Ref datatype
Definition reader.h:53
Ref lang
Definition reader.h:54
Ref subject
Definition reader.h:50
Ref predicate
Definition reader.h:51
bool eof
True iff end of file reached.
Definition byte_source.h:47
A syntactic RDF node.
Definition serd.h:199
const uint8_t *SERD_NULLABLE buf
Value string.
Definition serd.h:200
size_t n_bytes
Size in bytes (excluding null).
Definition serd.h:201
SerdNodeFlags flags
Node flags (string properties).
Definition serd.h:203
SerdType type
Node type.
Definition serd.h:204
Ref rdf_first
Definition reader.h:67
SerdPrefixSink prefix_sink
Definition reader.h:62
Ref rdf_rest
Definition reader.h:68
uint8_t * bprefix
Definition reader.h:76
size_t bprefix_len
Definition reader.h:77
SerdByteSource source
Definition reader.h:71
bool seen_genid
Definition reader.h:79
SerdStack stack
Definition reader.h:72
Ref rdf_nil
Definition reader.h:69
bool strict
True iff strict parsing.
Definition reader.h:78
SerdEndSink end_sink
Definition reader.h:64
SerdBaseSink base_sink
Definition reader.h:61
void * handle
Definition reader.h:59
SerdSyntax syntax
Definition reader.h:73
size_t size
Conceptual size of stack in buf.
Definition stack.h:33
int n
Definition crypt.c:458
return c
Definition crypt.c:175
fmt[0]
Definition fileio.c:2503
register uch * q
Definition fileio.c:817
static bool is_uri_scheme_char(const int c)
Definition uri_utils.h:97
_WDL_CSTRING_PREFIX void INT_PTR count
Definition wdlcstring.h:263