6#line 1 "../../include/volksdata/codec/parser_common.h"
12#ifndef VOLK_PARSER_COMMON_H
13#define VOLK_PARSER_COMMON_H
25#define YYCTYPE uint8_t
26#define YYCURSOR it->cur
27#define YYMARKER it->mar
28#define YYLIMIT it->lim
29#define YYFILL fill(it) == 0
32typedef struct parse_it_t {
50#line 41 "../../include/volksdata/codec/parser_common.h"
67static void parse_init (
ParseIterator *it, FILE *fh,
const char *sh)
75 if (!it->
buf) log_error (
"Error allocating lexer buffer.");
96#line 83 "../../include/volksdata/codec/parser_common.h"
105 if (it->
eof)
return 1;
107 size_t shift = it->
tok - it->
buf;
108 size_t used = it->
lim - it->
tok;
116 cur_off = it->
cur - it->
buf,
117 tok_off = it->
tok - it->
buf,
118 lim_off = it->
lim - it->
buf,
119 mar_off = it->
mar - it->
buf;
124 log_error (
"Memory allocation error.");
129 it->
cur = it->
buf + cur_off;
130 it->
tok = it->
buf + tok_off;
131 it->
lim = it->
buf + lim_off;
132 it->
mar = it->
buf + mar_off;
134 log_debug (
"Shifting bytes: %zu", shift);
135 memmove (it->
buf, it->
tok, used);
136 log_trace (
"Limit offset before reading data: %zu", it->
lim - it->
tok);
144#line 145 "parser_nt.c"
146#line 129 "../../include/volksdata/codec/parser_common.h"
165#ifdef VOLK_CODEC_DEBUG
173 const YYCTYPE *lit_data_e, *dtype_s, *lang_s;
185#line 186 "parser_nt.c"
188 unsigned int yyaccept = 0;
203 if (
YYFILL)
goto yyFillLabel0;
211#line 162 "lexer_nt.re"
214 "Invalid token @ %p: %s (\\x%x)",
219#line 220 "parser_nt.c"
229 if (
YYFILL)
goto yyFillLabel1;
234#line 145 "lexer_nt.re"
240#line 241 "parser_nt.c"
251 if (
YYFILL)
goto yyFillLabel2;
256#line 61 "lexer_nt.re"
263#line 264 "parser_nt.c"
272 if (
YYFILL)
goto yyFillLabel3;
279 case 0xC2 ... 0xF4:
goto yy14;
292 if (
YYFILL)
goto yyFillLabel4;
296 case 0xC2 ... 0xDF:
goto yy25;
297 case 0xE0:
goto yy26;
298 case 0xE1 ... 0xEF:
goto yy27;
299 case 0xF0:
goto yy28;
300 case 0xF1 ... 0xF3:
goto yy29;
301 case 0xF4:
goto yy30;
305#line 151 "lexer_nt.re"
309 memcpy (data, it->
tok, size);
310 data [size - 1] =
'\0';
316#line 317 "parser_nt.c"
319#line 138 "lexer_nt.re"
326#line 327 "parser_nt.c"
339 case 0xC2 ... 0xF4:
goto yy32;
342 if (
YYFILL)
goto yyFillLabel5;
355 if (
YYFILL)
goto yyFillLabel6;
372 if (
YYFILL)
goto yyFillLabel7;
377 case '\\':
goto yy18;
378 case 0xC2 ... 0xDF:
goto yy19;
379 case 0xE0:
goto yy20;
380 case 0xE1 ... 0xEF:
goto yy21;
381 case 0xF0:
goto yy22;
382 case 0xF1 ... 0xF3:
goto yy23;
383 case 0xF4:
goto yy24;
424 if (
YYFILL)
goto yyFillLabel8;
432 lit_data_e = it->
yyt1;
435#line 85 "lexer_nt.re"
438 size_t size = lit_data_e - it->
tok - 2;
442 char *metadata = NULL;
453 }
else md_marker = NULL;
456 metadata = malloc (size);
457 memcpy (metadata, md_marker + 1, size);
458 metadata [size - 1] =
'\0';
476#line 477 "parser_nt.c"
494 if (
YYFILL)
goto yyFillLabel9;
503 case 0x80 ... 0xBF:
goto yy13;
506 if (
YYFILL)
goto yyFillLabel10;
515 case 0xA0 ... 0xBF:
goto yy19;
518 if (
YYFILL)
goto yyFillLabel11;
527 case 0x80 ... 0xBF:
goto yy19;
530 if (
YYFILL)
goto yyFillLabel12;
539 case 0x90 ... 0xBF:
goto yy21;
542 if (
YYFILL)
goto yyFillLabel13;
551 case 0x80 ... 0xBF:
goto yy21;
554 if (
YYFILL)
goto yyFillLabel14;
563 case 0x80 ... 0x8F:
goto yy21;
566 if (
YYFILL)
goto yyFillLabel15;
575 case 0x80 ... 0xBF:
goto yy8;
578 if (
YYFILL)
goto yyFillLabel16;
587 case 0xA0 ... 0xBF:
goto yy25;
590 if (
YYFILL)
goto yyFillLabel17;
599 case 0x80 ... 0xBF:
goto yy25;
602 if (
YYFILL)
goto yyFillLabel18;
611 case 0x90 ... 0xBF:
goto yy27;
614 if (
YYFILL)
goto yyFillLabel19;
623 case 0x80 ... 0xBF:
goto yy27;
626 if (
YYFILL)
goto yyFillLabel20;
635 case 0x80 ... 0x8F:
goto yy27;
638 if (
YYFILL)
goto yyFillLabel21;
655 case '~' ... 0x7F:
goto yy31;
657 case '\\':
goto yy34;
658 case 0xC2 ... 0xDF:
goto yy35;
659 case 0xE0:
goto yy36;
660 case 0xE1 ... 0xEF:
goto yy37;
661 case 0xF0:
goto yy38;
662 case 0xF1 ... 0xF3:
goto yy39;
663 case 0xF4:
goto yy40;
666 if (
YYFILL)
goto yyFillLabel22;
672#line 73 "lexer_nt.re"
684#line 685 "parser_nt.c"
694 if (
YYFILL)
goto yyFillLabel23;
703 case 0x80 ... 0xBF:
goto yy31;
706 if (
YYFILL)
goto yyFillLabel24;
715 case 0xA0 ... 0xBF:
goto yy35;
718 if (
YYFILL)
goto yyFillLabel25;
727 case 0x80 ... 0xBF:
goto yy35;
730 if (
YYFILL)
goto yyFillLabel26;
739 case 0x90 ... 0xBF:
goto yy37;
742 if (
YYFILL)
goto yyFillLabel27;
751 case 0x80 ... 0xBF:
goto yy37;
754 if (
YYFILL)
goto yyFillLabel28;
763 case 0x80 ... 0x8F:
goto yy37;
766 if (
YYFILL)
goto yyFillLabel29;
782 case 0xEF ... 0xF3:
goto yy50;
783 case 0xCD:
goto yy54;
784 case 0xE2:
goto yy57;
787 if (
YYFILL)
goto yyFillLabel30;
805 if (
YYFILL)
goto yyFillLabel31;
817 case 'a' ...
'z':
goto yy64;
820 if (
YYFILL)
goto yyFillLabel32;
832 if (
YYFILL)
goto yyFillLabel33;
843 case 'a' ...
'f':
goto yy66;
846 if (
YYFILL)
goto yyFillLabel34;
857 case 'a' ...
'f':
goto yy67;
860 if (
YYFILL)
goto yyFillLabel35;
871 case 'a' ...
'f':
goto yy68;
874 if (
YYFILL)
goto yyFillLabel36;
885 case 'a' ...
'f':
goto yy69;
888 if (
YYFILL)
goto yyFillLabel37;
903 case 'a' ...
'z':
goto yy49;
905 case 0xC2:
goto yy71;
906 case 0xC3:
goto yy52;
908 case 0xCE ... 0xDF:
goto yy53;
909 case 0xCD:
goto yy72;
910 case 0xE0:
goto yy55;
912 case 0xE4 ... 0xEC:
goto yy56;
913 case 0xE2:
goto yy73;
914 case 0xE3:
goto yy58;
915 case 0xED:
goto yy59;
916 case 0xEF:
goto yy60;
917 case 0xF0:
goto yy61;
918 case 0xF1 ... 0xF2:
goto yy62;
919 case 0xF3:
goto yy63;
922 if (
YYFILL)
goto yyFillLabel38;
927#line 126 "lexer_nt.re"
939#line 940 "parser_nt.c"
947 case 0xB8 ... 0xBF:
goto yy49;
950 if (
YYFILL)
goto yyFillLabel39;
959 case 0x80 ... 0xBF:
goto yy49;
962 if (
YYFILL)
goto yyFillLabel40;
972 case 0xBF:
goto yy49;
975 if (
YYFILL)
goto yyFillLabel41;
984 case 0xA0 ... 0xBF:
goto yy53;
987 if (
YYFILL)
goto yyFillLabel42;
996 case 0x80 ... 0xBF:
goto yy53;
999 if (
YYFILL)
goto yyFillLabel43;
1008 case 0x80:
goto yy74;
1009 case 0x81:
goto yy75;
1011 case 0xB0 ... 0xBE:
goto yy53;
1012 case 0x86:
goto yy76;
1013 case 0xBF:
goto yy77;
1016 if (
YYFILL)
goto yyFillLabel44;
1025 case 0x80:
goto yy78;
1026 case 0x81 ... 0xBF:
goto yy53;
1029 if (
YYFILL)
goto yyFillLabel45;
1038 case 0x80 ... 0x9F:
goto yy53;
1041 if (
YYFILL)
goto yyFillLabel46;
1051 case 0xB8 ... 0xBE:
goto yy53;
1052 case 0xB7:
goto yy79;
1053 case 0xBF:
goto yy80;
1056 if (
YYFILL)
goto yyFillLabel47;
1065 case 0x90 ... 0xBF:
goto yy56;
1068 if (
YYFILL)
goto yyFillLabel48;
1077 case 0x80 ... 0xBF:
goto yy56;
1080 if (
YYFILL)
goto yyFillLabel49;
1089 case 0x80 ... 0xAF:
goto yy56;
1092 if (
YYFILL)
goto yyFillLabel50;
1102 case '-':
goto yy81;
1104 case 'a' ...
'z':
goto yy64;
1107 if (
YYFILL)
goto yyFillLabel51;
1118 case ' ':
goto yy65;
1124 if (
YYFILL)
goto yyFillLabel52;
1135 case 'a' ...
'f':
goto yy83;
1138 if (
YYFILL)
goto yyFillLabel53;
1149 case 'a' ...
'f':
goto yy84;
1152 if (
YYFILL)
goto yyFillLabel54;
1163 case 'a' ...
'f':
goto yy85;
1166 if (
YYFILL)
goto yyFillLabel55;
1177 case 'a' ...
'f':
goto yy86;
1180 if (
YYFILL)
goto yyFillLabel56;
1193 case 'a' ...
'z':
goto yy49;
1194 case '.':
goto yy70;
1195 case 0xC2:
goto yy71;
1196 case 0xC3:
goto yy52;
1198 case 0xCE ... 0xDF:
goto yy53;
1199 case 0xCD:
goto yy72;
1200 case 0xE0:
goto yy55;
1202 case 0xE4 ... 0xEC:
goto yy56;
1203 case 0xE2:
goto yy73;
1204 case 0xE3:
goto yy58;
1205 case 0xED:
goto yy59;
1206 case 0xEF:
goto yy60;
1207 case 0xF0:
goto yy61;
1208 case 0xF1 ... 0xF2:
goto yy62;
1209 case 0xF3:
goto yy63;
1212 if (
YYFILL)
goto yyFillLabel57;
1221 case 0xB7:
goto yy49;
1224 if (
YYFILL)
goto yyFillLabel58;
1234 case 0xBF:
goto yy49;
1237 if (
YYFILL)
goto yyFillLabel59;
1246 case 0x80:
goto yy87;
1247 case 0x81:
goto yy88;
1249 case 0xB0 ... 0xBE:
goto yy53;
1250 case 0x86:
goto yy76;
1251 case 0xBF:
goto yy77;
1254 if (
YYFILL)
goto yyFillLabel60;
1263 case 0x8C ... 0x8D:
goto yy49;
1266 if (
YYFILL)
goto yyFillLabel61;
1275 case 0xB0 ... 0xBF:
goto yy49;
1278 if (
YYFILL)
goto yyFillLabel62;
1287 case 0x80 ... 0x8F:
goto yy49;
1290 if (
YYFILL)
goto yyFillLabel63;
1299 case 0x80 ... 0xAF:
goto yy49;
1302 if (
YYFILL)
goto yyFillLabel64;
1311 case 0x81 ... 0xBF:
goto yy49;
1314 if (
YYFILL)
goto yyFillLabel65;
1324 case 0xB0 ... 0xBF:
goto yy49;
1327 if (
YYFILL)
goto yyFillLabel66;
1336 case 0x80 ... 0xBD:
goto yy49;
1339 if (
YYFILL)
goto yyFillLabel67;
1350 case 'a' ...
'z':
goto yy89;
1353 if (
YYFILL)
goto yyFillLabel68;
1369 case '~' ... 0x7F:
goto yy82;
1370 case '>':
goto yy90;
1371 case '\\':
goto yy91;
1372 case 0xC2 ... 0xDF:
goto yy92;
1373 case 0xE0:
goto yy93;
1374 case 0xE1 ... 0xEF:
goto yy94;
1375 case 0xF0:
goto yy95;
1376 case 0xF1 ... 0xF3:
goto yy96;
1377 case 0xF4:
goto yy97;
1380 if (
YYFILL)
goto yyFillLabel69;
1391 case 'a' ...
'f':
goto yy98;
1394 if (
YYFILL)
goto yyFillLabel70;
1405 case 'a' ...
'f':
goto yy99;
1408 if (
YYFILL)
goto yyFillLabel71;
1419 case 'a' ...
'f':
goto yy100;
1422 if (
YYFILL)
goto yyFillLabel72;
1433 case 'a' ...
'f':
goto yy101;
1436 if (
YYFILL)
goto yyFillLabel73;
1446 case 0xBF:
goto yy49;
1449 if (
YYFILL)
goto yyFillLabel74;
1459 case 0xB0 ... 0xBF:
goto yy49;
1462 if (
YYFILL)
goto yyFillLabel75;
1472 case '-':
goto yy81;
1475 case 'a' ...
'z':
goto yy89;
1478 if (
YYFILL)
goto yyFillLabel76;
1492 case 'U':
goto yy102;
1493 case 'u':
goto yy103;
1496 if (
YYFILL)
goto yyFillLabel77;
1505 case 0x80 ... 0xBF:
goto yy82;
1508 if (
YYFILL)
goto yyFillLabel78;
1517 case 0xA0 ... 0xBF:
goto yy92;
1520 if (
YYFILL)
goto yyFillLabel79;
1529 case 0x80 ... 0xBF:
goto yy92;
1532 if (
YYFILL)
goto yyFillLabel80;
1541 case 0x90 ... 0xBF:
goto yy94;
1544 if (
YYFILL)
goto yyFillLabel81;
1553 case 0x80 ... 0xBF:
goto yy94;
1556 if (
YYFILL)
goto yyFillLabel82;
1565 case 0x80 ... 0x8F:
goto yy94;
1568 if (
YYFILL)
goto yyFillLabel83;
1579 case 'a' ...
'f':
goto yy46;
1582 if (
YYFILL)
goto yyFillLabel84;
1593 case 'a' ...
'f':
goto yy13;
1596 if (
YYFILL)
goto yyFillLabel85;
1607 case 'a' ...
'f':
goto yy48;
1610 if (
YYFILL)
goto yyFillLabel86;
1621 case 'a' ...
'f':
goto yy31;
1624 if (
YYFILL)
goto yyFillLabel87;
1635 case 'a' ...
'f':
goto yy104;
1638 if (
YYFILL)
goto yyFillLabel88;
1649 case 'a' ...
'f':
goto yy105;
1652 if (
YYFILL)
goto yyFillLabel89;
1663 case 'a' ...
'f':
goto yy106;
1666 if (
YYFILL)
goto yyFillLabel90;
1677 case 'a' ...
'f':
goto yy107;
1680 if (
YYFILL)
goto yyFillLabel91;
1691 case 'a' ...
'f':
goto yy108;
1694 if (
YYFILL)
goto yyFillLabel92;
1705 case 'a' ...
'f':
goto yy109;
1708 if (
YYFILL)
goto yyFillLabel93;
1719 case 'a' ...
'f':
goto yy103;
1722 if (
YYFILL)
goto yyFillLabel94;
1733 case 'a' ...
'f':
goto yy82;
1736 if (
YYFILL)
goto yyFillLabel95;
1741#line 68 "lexer_nt.re"
1746#line 1747 "parser_nt.c"
1748#line 170 "lexer_nt.re"
1757 parse_init (&it, NULL, rep);
1759 int ttype = lex (&it, term);
1775 FILE *fh,
const char *sh, VOLK_Graph *gr,
size_t *ct,
char **err_p)
1780 log_error (
"Neither file handle nor string input provided.");
1785 parse_init (&parse_it, fh, sh);
1787#ifdef VOLK_CODEC_DEBUG
1804 int ttype = lex (&parse_it, &term);
1807 char token[16] = {};
1808 strncpy (token, (
const char *)parse_it.
tok, 15);
1810 char *err_start =
"Parse error near token `";
1814 err_info,
"[...]' at line %u, character %ld.\n",
1817 size_t err_size = strlen (err_start) + 16 + strlen(err_info);
1818 char *err_str = malloc (err_size);
1819 sprintf (err_str,
"%s%s%s", err_start, token, err_info);
1823 log_error (err_str);
1828 NTParse (parser, ttype, term, it);
1830 if (ttype ==
T_EOF)
break;
1833 if (ct) *ct = parse_it.
ct;
1835 log_info (
"Parsed %u triples.", parse_it.
ct);
1841 NTParse (parser, 0, NULL, it);
1844 free (parse_it.
buf);
Codec interface definition and basic elements common to all codecs.
#define T_EOF
Lemon parser grammar for N-Triples.
void NTParseTrace(FILE *TraceFILE, char *zTracePrompt)
uint8_t * unescape_unicode(const uint8_t *esc_str, size_t size)
Replace \uxxxx and \Uxxxxxxxx with Unicode bytes.
#define VOLK_graph_add_init(...)
Non-transactional version of VOLK_graph_add_init_txn().
void VOLK_graph_free(VOLK_Graph *gr)
Free a graph.
void VOLK_graph_iter_free(VOLK_GraphIterator *it)
Free a graph iterator.
size_t VOLK_graph_size(const VOLK_Graph *gr)
Number of triples in a graph.
#define VOLK_VALUE_ERR
An invalid input value was provided.
#define VOLK_MEM_ERR
Memory allocation error.
#define VOLK_NORESULT
No result yielded.
#define VOLK_OK
Generic success return code.
#define VOLK_PARSE_ERR
Codec parser error.
VOLK_Term * VOLK_lt_literal_new(const char *data, char *lang)
Shortcut to create a language-tagged literal term.
VOLK_Term * VOLK_iriref_new(const char *data)
Create an IRI reference.
VOLK_Term * VOLK_literal_new(const char *data, VOLK_Term *datatype)
Shortcut to create a literal term.
void VOLK_term_free(VOLK_Term *term)
VOLK_Term * VOLK_term_new(VOLK_TermType type, const char *data, void *metadata)
Create a new term.
@ VOLK_TERM_LT_LITERAL
Language-tagged string literal.
@ VOLK_TERM_LITERAL
Literal without language tag.
@ VOLK_TERM_BNODE
Blank node.
#define YYCTYPE
TTL is UTF-8 encoded.
VOLK_rc nt_parse_doc(FILE *fh, const char *sh, VOLK_Graph *gr, size_t *ct, char **err_p)
Parse an RDF document in N-Triples format.
#define YYCTYPE
TTL is UTF-8 encoded.
VOLK_rc nt_parse_term(const char *rep, VOLK_Term **term)
Parse a single term.
FILE * fh
Input file handle.
size_t buf_size
Initial allocation for buffer.
unsigned line
Current line no. (for debugging).
YYCTYPE * cur
Next input character to be read (YYCURSOR).
const char * sh
Input string. Exclusive with fh.
bool eof
if we have reached EOF.
YYCTYPE * buf
Start of buffer.
unsigned ct
Number of statements parsed.
YYCTYPE * mar
Most recent match (YYMARKER).
YYCTYPE * tok
Start of current token.