summaryrefslogtreecommitdiffstats
path: root/jv_parse.c
diff options
context:
space:
mode:
authorStephen Dolan <mu@netsoc.tcd.ie>2012-12-27 01:56:23 +0000
committerStephen Dolan <mu@netsoc.tcd.ie>2012-12-27 01:56:23 +0000
commitd327772dfc78ad49f46fbf583418e33abc0b59d2 (patch)
tree5a6105e6f89eb921d1b6985f77ace21364067196 /jv_parse.c
parentcedda2084d2f6b331ba0a73e05f0b77ee7995c86 (diff)
JSON parsing error messages now specify a location of the error.
Should help with #53.
Diffstat (limited to 'jv_parse.c')
-rw-r--r--jv_parse.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/jv_parse.c b/jv_parse.c
index 0d4f1549..f55c17e5 100644
--- a/jv_parse.c
+++ b/jv_parse.c
@@ -26,6 +26,8 @@ void jv_parser_init(struct jv_parser* p) {
p->curr_buf = 0;
p->curr_buf_length = p->curr_buf_pos = p->curr_buf_is_partial = 0;
p->bom_strip_position = 0;
+ p->line = 1;
+ p->column = 0;
jvp_dtoa_context_init(&p->dtoa);
}
@@ -294,6 +296,11 @@ static int check_done(struct jv_parser* p, jv* out) {
}
static pfunc scan(struct jv_parser* p, char ch, jv* out) {
+ p->column++;
+ if (ch == '\n') {
+ p->line++;
+ p->column = 0;
+ }
presult answer = 0;
if (p->st == JV_PARSER_NORMAL) {
chclass cls = classify(ch);
@@ -373,7 +380,7 @@ jv jv_parser_next(struct jv_parser* p) {
if (msg == OK) {
return value;
} else if (msg) {
- return jv_invalid_with_msg(jv_string(msg));
+ return jv_invalid_with_msg(jv_string_fmt("%s at line %d, column %d", msg, p->line, p->column));
} else if (p->curr_buf_is_partial) {
assert(p->curr_buf_pos == p->curr_buf_length);
// need another buffer