summaryrefslogtreecommitdiffhomepage
path: root/src/kv.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/kv.h')
-rw-r--r--src/kv.h27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/kv.h b/src/kv.h
index 4ed459b..44dc896 100644
--- a/src/kv.h
+++ b/src/kv.h
@@ -34,8 +34,8 @@
*/
struct kv_parser {
ushort line, col; /* the current line and column in the text */
- schar state; /* internal, shouldn't usually be touched directly */
- bool incomment; /* internal */
+ char state : 7; /* internal, shouldn't usually be touched directly */
+ bool incomment : 1; /* internal */
ushort nestlvl; /* internal */
const char *errmsg; /* the error message, *IF* parsing just failed */
@@ -46,8 +46,6 @@ struct kv_parser {
char tokbuf[KV_TOKEN_MAX];
};
-#define KV_PARSER_ERROR -1
-
/*
* These are the tokens that can be received by a kv_parser_cb (below).
* The x-macro and string descriptions are given to allow for easy debug
@@ -61,6 +59,8 @@ struct kv_parser {
X(KV_IDENT_QUOTED, "quoted-ident") \
X(KV_VAL, "value") \
X(KV_VAL_QUOTED, "quoted-value") \
+ X(KV_COND_PREFIX, "cond-prefix") \
+ X(KV_COND_SUFFIX, "cond-suffix") \
X(KV_NEST_START, "object-start") \
X(KV_NEST_END, "object-end")
@@ -76,20 +76,21 @@ typedef void (*kv_parser_cb)(enum kv_token type, const char *p, uint len,
* read in from a file.
*
* The lexer is reentrant and can be fed arbitrarily sized blocks of data at a
- * time. The function may return early in the event of an error; you must check
- * if parser->state == KV_PARSER_ERROR between calls! Continuing to try parsing
- * after an error is undefined.
+ * time. The function may return early in the event of an error; a return value
+ * of false indicates thaat this has happened, otherwise true is returned.
+ *
+ * In the event of an error, the errmsg, line and col fields of the parser
+ * struct can be used for diagnostics.
*/
-// FIXME: revise API usage so errors aren't passed through "state" value
-void kv_parser_feed(struct kv_parser *this, const char *in, uint sz,
+bool kv_parser_feed(struct kv_parser *this, const char *in, uint sz,
kv_parser_cb cb, void *ctxt);
/*
- * This indicates that parsing is done; if the state is midway through a token
- * this will be converted into an error state which can be checked in the same
- * way as noted above.
+ * This indicates that parsing is done; if this is called at an unexpected time,
+ * a parsing error will result; this is indicated in the return value as with
+ * kv_parser_feed.
*/
-void kv_parser_done(struct kv_parser *this);
+bool kv_parser_done(struct kv_parser *this);
#endif