diff options
-rw-r--r-- | lexer.c | 19 | ||||
-rw-r--r-- | tests/00_syntax/09_string_literals | 15 |
2 files changed, 14 insertions, 20 deletions
@@ -414,21 +414,8 @@ parse_string(struct uc_state *s) case '5': case '6': case '7': - case '8': - case '9': - /* likely octal */ - if (*ptr < '8') { - s->lex.esc[s->lex.esclen++] = 'o'; - s->lex.esc[s->lex.esclen++] = *ptr; - } - - /* non-octal char, add verbatim */ - else { - s->lex.is_escape = false; - lookbehind_append(s, ptr, 1); - buf_consume(s, (ptr + 1) - s->lex.bufstart); - } - + s->lex.esc[s->lex.esclen++] = 'o'; + s->lex.esc[s->lex.esclen++] = *ptr; break; default: @@ -549,7 +536,7 @@ parse_string(struct uc_state *s) } s->lex.esclen = 4; - buf_consume(s, ptr - s->lex.bufstart); + buf_consume(s, ptr-- - s->lex.bufstart); } /* append */ diff --git a/tests/00_syntax/09_string_literals b/tests/00_syntax/09_string_literals index 381076e..0967850 100644 --- a/tests/00_syntax/09_string_literals +++ b/tests/00_syntax/09_string_literals @@ -28,16 +28,23 @@ Octal escape: ABC xyz Testing various parsing corner cases. -- Expect stdout -- -[ "\t", "\n", "y" ] +[ "\t", "\n", "y", "\u0001", "\n", "\u0001\u0002", "\u0001\u0002", "\u0001\u0002", "\u0001a", "\na" ] -- End -- -- Testcase -- {% print([ - "\ ", // properly handle escaped tab + "\ ", // properly handle escaped tab "\ -", // properly handle escaped newline - "\y" // substitute unrecognized escape with escaped char +", // properly handle escaped newline + "\y", // substitute unrecognized escape with escaped char + "\1", // handle short octal sequence at end of string + "\12", // handle short octal sequence at end of string + "\1\2", // handle subsequent short octal sequences + "\001\2", // handle short sequence after long one + "\1\002", // handle long sequence after short one + "\1a", // handle short octal sequence terminated by non-octal char + "\12a" // handle short octal sequence terminated by non-octal char ], "\n"); %} -- End -- |