|
34 | 34 | /* forward declarations */
|
35 | 35 | static void yy_error(const char *msg);
|
36 | 36 | static void yy_error_sym(const char *msg, int sym);
|
| 37 | +static void yy_error_str(const char *msg, const char *str); |
37 | 38 |
|
38 | 39 | #define YYPOS cpos
|
39 | 40 | #define YYEND cend
|
@@ -246,6 +247,63 @@ static const char * sym_name[] = {
|
246 | 247 | #define YY_IN_SET(sym, set, bitset) \
|
247 | 248 | (bitset[sym>>3] & (1 << (sym & 0x7)))
|
248 | 249 |
|
| 250 | +size_t yy_escape(char *buf, unsigned char ch) |
| 251 | +{ |
| 252 | + switch (ch) { |
| 253 | + case '\\': buf[0] = '\\'; buf[1] = '\\'; return 2; |
| 254 | + case '\'': buf[0] = '\\'; buf[1] = '\''; return 2; |
| 255 | + case '\"': buf[0] = '\\'; buf[1] = '\"'; return 2; |
| 256 | + case '\a': buf[0] = '\\'; buf[1] = '\a'; return 2; |
| 257 | + case '\b': buf[0] = '\\'; buf[1] = '\b'; return 2; |
| 258 | + case 27: buf[0] = '\\'; buf[1] = '\e'; return 2; |
| 259 | + case '\f': buf[0] = '\\'; buf[1] = '\f'; return 2; |
| 260 | + case '\n': buf[0] = '\\'; buf[1] = '\n'; return 2; |
| 261 | + case '\r': buf[0] = '\\'; buf[1] = '\r'; return 2; |
| 262 | + case '\t': buf[0] = '\\'; buf[1] = '\t'; return 2; |
| 263 | + case '\v': buf[0] = '\\'; buf[1] = '\v'; return 2; |
| 264 | + case '\?': buf[0] = '\\'; buf[1] = 0x3f; return 2; |
| 265 | + default: break; |
| 266 | + } |
| 267 | + if (ch < 32 || ch >= 127) { |
| 268 | + buf[0] = '\\'; |
| 269 | + buf[1] = '0' + ((ch >> 6) % 8); |
| 270 | + buf[2] = '0' + ((ch >> 3) % 8); |
| 271 | + buf[3] = '0' + (ch % 8); |
| 272 | + return 4; |
| 273 | + } else { |
| 274 | + buf[0] = ch; |
| 275 | + return 1; |
| 276 | + } |
| 277 | +} |
| 278 | + |
| 279 | +const char *yy_escape_char(char *buf, unsigned char ch) |
| 280 | +{ |
| 281 | + size_t len = yy_escape(buf, ch); |
| 282 | + buf[len] = 0; |
| 283 | + return buf; |
| 284 | +} |
| 285 | + |
| 286 | +const char *yy_escape_string(char *buf, size_t size, const unsigned char *str, size_t n) |
| 287 | +{ |
| 288 | + size_t i = 0; |
| 289 | + size_t pos = 0; |
| 290 | + size_t len; |
| 291 | + |
| 292 | + while (i < n) { |
| 293 | + if (pos + 8 > size) { |
| 294 | + buf[pos++] = '.'; |
| 295 | + buf[pos++] = '.'; |
| 296 | + buf[pos++] = '.'; |
| 297 | + break; |
| 298 | + } |
| 299 | + len = yy_escape(buf + pos, str[i]); |
| 300 | + i++; |
| 301 | + pos += len; |
| 302 | + } |
| 303 | + buf[pos] = 0; |
| 304 | + return buf; |
| 305 | +} |
| 306 | + |
249 | 307 | static int skip_EOL(int sym);
|
250 | 308 | static int skip_WS(int sym);
|
251 | 309 | static int skip_ONE_LINE_COMMENT(int sym);
|
@@ -310,6 +368,7 @@ static int synpred_5(int sym);
|
310 | 368 | static int synpred_6(int sym);
|
311 | 369 |
|
312 | 370 | static int get_skip_sym(void) {
|
| 371 | + char buf[64]; |
313 | 372 | int ch;
|
314 | 373 | int ret;
|
315 | 374 | int accept = -1;
|
@@ -1667,9 +1726,9 @@ static int get_skip_sym(void) {
|
1667 | 1726 | if (YYPOS >= YYEND) {
|
1668 | 1727 | yy_error("unexpected <EOF>");
|
1669 | 1728 | } else if (YYPOS == yy_text) {
|
1670 |
| - yy_error("unexpected character 'escape_char(ch)'"); |
| 1729 | + yy_error_str("unexpected character", yy_escape_char(buf, ch)); |
1671 | 1730 | } else {
|
1672 |
| - yy_error("unexpected sequence 'escape_string(yy_text, 1 + YYPOS - yy_text))'"); |
| 1731 | + yy_error_str("unexpected sequence", yy_escape_string(buf, sizeof(buf), yy_text, 1 + YYPOS - yy_text)); |
1673 | 1732 | }
|
1674 | 1733 | YYPOS++;
|
1675 | 1734 | goto _yy_state_start;
|
@@ -3592,3 +3651,7 @@ static void yy_error(const char *msg) {
|
3592 | 3651 | static void yy_error_sym(const char *msg, int sym) {
|
3593 | 3652 | zend_ffi_parser_error("%s '%s' at line %d", msg, sym_name[sym], yy_line);
|
3594 | 3653 | }
|
| 3654 | + |
| 3655 | +static void yy_error_str(const char *msg, const char *str) { |
| 3656 | + zend_ffi_parser_error("%s '%s' at line %d\n", msg, str, yy_line); |
| 3657 | +} |
0 commit comments