Show invalid escape sequences It is easier to debug when the message actually displays the offending escape sequence.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
diff --git a/src/compose/parser.c b/src/compose/parser.c
index 57be1bd..5545a33 100644
--- a/src/compose/parser.c
+++ b/src/compose/parser.c
@@ -171,6 +171,7 @@ skip_more_whitespace_and_comments:
while (!scanner_eof(s) && !scanner_eol(s) && scanner_peek(s) != '\"') {
if (scanner_chr(s, '\\')) {
uint8_t o;
+ size_t start_pos = s->pos;
if (scanner_chr(s, '\\')) {
scanner_buf_append(s, '\\');
}
@@ -181,24 +182,27 @@ skip_more_whitespace_and_comments:
if (scanner_hex(s, &o) && is_valid_char((char) o)) {
scanner_buf_append(s, (char) o);
} else {
- // [TODO] actually show the sequence
scanner_warn_with_code(s,
XKB_WARNING_INVALID_ESCAPE_SEQUENCE,
- "illegal hexadecimal escape sequence in string literal");
+ "illegal hexadecimal escape sequence (%.*s) in string literal",
+ (int) (s->pos - start_pos + 1), &s->s[start_pos - 1]);
}
}
- else if (scanner_oct(s, &o)) {
- if (is_valid_char((char) o)) {
- scanner_buf_append(s, (char) o);
- } else {
- // [TODO] actually show the sequence
- scanner_warn_with_code(s,
- XKB_WARNING_INVALID_ESCAPE_SEQUENCE,
- "illegal octal escape sequence in string literal");
- }
+ else if (scanner_oct(s, &o) && is_valid_char((char) o)) {
+ scanner_buf_append(s, (char) o);
+ }
+ else if (s->pos > start_pos) {
+ scanner_warn_with_code(s,
+ XKB_WARNING_INVALID_ESCAPE_SEQUENCE,
+ "illegal octal escape sequence (%.*s) in string literal",
+ (int) (s->pos - start_pos + 1), &s->s[start_pos - 1]);
+ /* Ignore. */
}
else {
- scanner_warn(s, "unknown escape sequence (%c) in string literal", scanner_peek(s));
+ scanner_warn_with_code(s,
+ XKB_WARNING_UNKNOWN_CHAR_ESCAPE_SEQUENCE,
+ "unknown escape sequence (\\%c) in string literal",
+ scanner_peek(s));
/* Ignore. */
}
} else {
diff --git a/src/xkbcomp/scanner.c b/src/xkbcomp/scanner.c
index 800d2d0..57babbb 100644
--- a/src/xkbcomp/scanner.c
+++ b/src/xkbcomp/scanner.c
@@ -90,6 +90,7 @@ skip_more_whitespace_and_comments:
while (!scanner_eof(s) && !scanner_eol(s) && scanner_peek(s) != '\"') {
if (scanner_chr(s, '\\')) {
uint8_t o;
+ size_t start_pos = s->pos;
if (scanner_chr(s, '\\')) scanner_buf_append(s, '\\');
else if (scanner_chr(s, 'n')) scanner_buf_append(s, '\n');
else if (scanner_chr(s, 't')) scanner_buf_append(s, '\t');
@@ -98,20 +99,19 @@ skip_more_whitespace_and_comments:
else if (scanner_chr(s, 'f')) scanner_buf_append(s, '\f');
else if (scanner_chr(s, 'v')) scanner_buf_append(s, '\v');
else if (scanner_chr(s, 'e')) scanner_buf_append(s, '\033');
- else if (scanner_oct(s, &o)) {
- if (is_valid_char((char) o)) {
- scanner_buf_append(s, (char) o);
- } else {
- scanner_warn_with_code(s,
- XKB_WARNING_INVALID_ESCAPE_SEQUENCE,
- "invalid octal escape sequence: \\%o", o);
- }
- }
+ else if (scanner_oct(s, &o) && is_valid_char((char) o))
+ scanner_buf_append(s, (char) o);
+ else if (s->pos > start_pos)
+ scanner_warn_with_code(s,
+ XKB_WARNING_INVALID_ESCAPE_SEQUENCE,
+ "invalid octal escape sequence (%.*s) in string literal",
+ (int) (s->pos - start_pos + 1), &s->s[start_pos - 1]);
+ /* Ignore. */
else {
- // TODO: display actual sequence! See: scanner_peek(s).
- // require escaping any potential control character
- scanner_warn_with_code(s, XKB_WARNING_UNKNOWN_CHAR_ESCAPE_SEQUENCE,
- "unknown escape sequence in string literal");
+ scanner_warn_with_code(s,
+ XKB_WARNING_UNKNOWN_CHAR_ESCAPE_SEQUENCE,
+ "unknown escape sequence (\\%c) in string literal",
+ scanner_peek(s));
/* Ignore. */
}
} else {