cppfront
cppfront copied to clipboard
[BUG] Cppfront can not parse "\x{62}"
trafficstars
Cppfront produces the error:
main.cpp2(3,22): error: string literal "\" is missing its closing "
main.cpp2(5,32): error: local variable c cannot be used in its own initializer
while parsing ""\x{62}blub""
A reproducer on compiler explorer: https://cpp2.godbolt.org/z/h6e8vc1rv
One possible patch is:
diff --git a/source/lex.h b/source/lex.h
index bab314a..ba3be0e 100644
--- a/source/lex.h
+++ b/source/lex.h
@@ -939,10 +939,16 @@ auto lex_line(
if (
peek( offset) == '\\'
&& peek(1+offset) == 'x'
- && is_hexadecimal_digit(peek(2+offset))
+ && (is_hexadecimal_digit(peek(2+offset))
+ || (peek(2+offset) == '{' && is_hexadecimal_digit(peek(3+offset)))
)
+ )
{
+ bool has_bracket = peek(2+offset) == '{';
auto j = 3;
+
+ if (has_bracket) { ++j; }
+
while (
peek(j+offset)
&& is_hexadecimal_digit(peek(j+offset))
@@ -950,6 +956,14 @@ auto lex_line(
{
++j;
}
+
+ if (has_bracket) {
+ if (peek(j+offset) == '}') {
+ ++j;
+ } else {
+ return 0;
+ }
+ }
return j;
}
return 0;
It seems that there is currently no regression test for the escapes.