aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/token.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2022-12-15 11:24:18 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2022-12-15 11:24:18 +0200
commit3ca670b7b7c71ca67d70cac9dffb2ba6120b2e36 (patch)
tree1424ac78fe10f697c8a0b63d91bb49889e8cdc85 /libbuild2/token.cxx
parent0aa7a94e1032a96a2a72cb6a82824f9fe970d412 (diff)
Improve escape sequence support
Specifically: 1. In the double-quoted strings we now only do effective escaping of the special `$("\` characters plus `)` for symmetry. 2. There is now support for "escape sequence expansion" in the form $\X where \X can be any of the C/C++ simple escape sequences (\n, \t, etc) plus \0 (which in C/C++ is an octal escape sequence). For example: info "foo$\n$\tbar$\n$\tbaz" Will print: buildfile:1:1: info: foo bar baz
Diffstat (limited to 'libbuild2/token.cxx')
-rw-r--r--libbuild2/token.cxx21
1 files changed, 15 insertions, 6 deletions
diff --git a/libbuild2/token.cxx b/libbuild2/token.cxx
index ab14388..cc102cc 100644
--- a/libbuild2/token.cxx
+++ b/libbuild2/token.cxx
@@ -29,21 +29,30 @@ namespace build2
os << (r ? "\n" : "<newline>");
break;
}
- case token_type::pair_separator:
+ case token_type::word:
{
if (r)
- os << t.value[0];
+ os << t.value;
else
- os << "<pair separator " << t.value[0] << ">";
+ os << '\'' << t.value << '\'';
break;
}
- case token_type::word:
+ case token_type::escape:
{
if (r)
- os << t.value;
+ os << '\\' << t.value;
else
- os << '\'' << t.value << '\'';
+ os << "<escape sequence \\" << t.value << ">";
+
+ break;
+ }
+ case token_type::pair_separator:
+ {
+ if (r)
+ os << t.value[0];
+ else
+ os << "<pair separator " << t.value[0] << ">";
break;
}