Improve error reporting
[oweals/jsonpath.git] / parser.y
index 9c06c07c4a90a1eeed05a9a072727576db6e346d..f77779bc72ca8f7a9597c4fdc15f6c2956a6d069 100644 (file)
--- a/parser.y
+++ b/parser.y
 }
 
 %syntax_error {
-       int n = sizeof(tokennames) / sizeof(tokennames[0]);
-       int l = strlen("Expecting ");
-       int c = 0;
        int i;
 
-       for (i = 0; i < n; i++)
-       {
+       for (i = 0; i < sizeof(tokennames) / sizeof(tokennames[0]); i++)
                if (yy_find_shift_action(yypParser, (YYCODETYPE)i) < YYNSTATE + YYNRULE)
-                       l += strlen(tokennames[i]) + 4;
-       }
-
-       s->error = malloc(l);
-
-       if (s->error)
-       {
-               s->erroff = s->off;
-               strcpy(s->error, "Expecting ");
-
-               for (i = 0; i < n; i++)
-               {
-                       if (yy_find_shift_action(yypParser, (YYCODETYPE)i) < YYNSTATE + YYNRULE)
-                       {
-                               if (c++)
-                                       strcat(s->error, " or ");
-
-                               strcat(s->error, tokennames[i]);
-                       }
-               }
-       }
+                       s->error_code |= (1 << i);
+
+       s->error_pos = s->off;
 }