summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-04-08 17:45:33 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-04-08 17:45:33 -0700
commit3461d0f5d1d020865d0e68ece92ea58ef83a6bf9 (patch)
tree7ad5d07054a5cc79fc418b2b6c7e3f2aa6a125ba
parentf5fddd6325ee30b4910a7e640b56feabab3d011d (diff)
downloadtxr-3461d0f5d1d020865d0e68ece92ea58ef83a6bf9.tar.gz
txr-3461d0f5d1d020865d0e68ece92ea58ef83a6bf9.tar.bz2
txr-3461d0f5d1d020865d0e68ece92ea58ef83a6bf9.zip
parser: fix poor diagnosis of \x invalid escape.
* parser.l (grammar): Because the \x pattern requires one or more digits after it, if they are not present, we simply report \x as an an unrecognized escape. It's better if we diagnose it properly as a \x that is not followed by digits.
-rw-r--r--parser.l13
1 files changed, 12 insertions, 1 deletions
diff --git a/parser.l b/parser.l
index e310d1f7..778c632a 100644
--- a/parser.l
+++ b/parser.l
@@ -836,6 +836,10 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
return TEXT;
}
+<SPECIAL>[\\]x {
+ yyerrorf(yyg, lit("\\x escape without digits"), nao);
+}
+
<SPECIAL>[\\]. {
yyerrorf(yyg, lit("unrecognized escape \\~a"), chr(yytext[1]), nao);
}
@@ -919,7 +923,10 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
return REGCHAR;
}
- yyerrprepf(yyg, lit("unrecognized escape in regex"), nao);
+ if (yytext[1] == 'x')
+ yyerrprepf(yyg, lit("\\x escape without digits in regex"), nao);
+ else
+ yyerrprepf(yyg, lit("unrecognized escape in regex"), nao);
return ERRTOK;
}
@@ -1021,6 +1028,10 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
return LITCHAR;
}
+<STRLIT,QSILIT,WLIT,QWLIT>[\\]x {
+ yyerrorf(yyg, lit("\\x escape without digits"), nao);
+}
+
<STRLIT,QSILIT,WLIT,QWLIT>[\\]. {
yyerrorf(yyg, lit("unrecognized escape: \\~a"), chr(yytext[1]), nao);
}