summaryrefslogtreecommitdiff
path: root/ast.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2014-06-18 17:59:51 +0200
committerJo-Philipp Wich <jow@openwrt.org>2014-06-18 18:50:51 +0200
commitafa3a10096e6d3ad50dc9d8250f40d8f23a9ad42 (patch)
treee6a84c25ea9a61e2f30b7937f504a8539b694422 /ast.c
parentc0e1d4495a8afe51cc1900269d6a6fcf0b51a761 (diff)
downloadjsonpath-afa3a10096e6d3ad50dc9d8250f40d8f23a9ad42.tar.gz
Improve error reporting
Keep track of the exact location the error occured in and switch the internal error description from a dynamic string buffer to an integer which either holds negative values for lexer errors or positives values for grammer violations. In case of grammer violations the "error_code" member will hold a bitfield describing the expected tokens. Also rework the error messages emitted by the cli to be more precise. Examples: $ jsonfilter -s '{}' -e '@.foo bar' Syntax error: Expecting End of file In expression @.foo bar Near here ----------^ $ jsonfilter -s '{}' -e '@.foo\bar' Syntax error: Unexpected character In expression @.foo\bar Near here ---------^ $ jsonfilter -s '{}' -e '@.foo..bar' Syntax error: Expecting Label or '*' In expression @.foo..bar Near here ----------^ Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Diffstat (limited to 'ast.c')
-rw-r--r--ast.c14
1 files changed, 3 insertions, 11 deletions
diff --git a/ast.c b/ast.c
index 5093e8b..6db7a46 100644
--- a/ast.c
+++ b/ast.c
@@ -73,9 +73,6 @@ jp_free(struct jp_state *s)
op = tmp;
}
- if (s->error)
- free(s->error);
-
free(s);
}
@@ -101,18 +98,11 @@ jp_parse(const char *expr)
while (len > 0)
{
- s->off = (ptr - expr);
-
op = jp_get_token(s, ptr, &mlen);
if (mlen < 0)
{
- s->erroff = s->off;
- s->error = strdup((mlen == -3) ? "String too long" :
- (mlen == -2) ? "Invalid escape sequence" :
- (mlen == -1) ? "Unterminated string" :
- "Unknown error");
-
+ s->error_code = mlen;
goto out;
}
@@ -121,6 +111,8 @@ jp_parse(const char *expr)
len -= mlen;
ptr += mlen;
+
+ s->off += mlen;
}
Parse(pParser, 0, NULL, s);