Fix broken escape sequence parsing after octal/hex escape

The parser code just added the first character after an octal/hex sequence
as raw text, resulting in erroneous data whenever another escape
sequence follows directly after.
This commit is contained in:
Christian Kaeser 2015-11-08 11:39:48 +01:00
parent 40b1549b3b
commit 34c6b17215
3 changed files with 29 additions and 25 deletions

View File

@ -961,15 +961,6 @@ namespace chaiscript
} }
void parse(const char_type t_char, const int line, const int col, const std::string &filename) { void parse(const char_type t_char, const int line, const int col, const std::string &filename) {
if (t_char == '\\') {
if (is_escaped) {
match.push_back('\\');
is_escaped = false;
} else {
is_escaped = true;
}
} else {
if (is_escaped) {
const bool is_octal_char = t_char >= '0' && t_char <= '7'; const bool is_octal_char = t_char >= '0' && t_char <= '7';
if (is_octal) { if (is_octal) {
@ -979,9 +970,9 @@ namespace chaiscript
if (octal_matches.size() == 3) { if (octal_matches.size() == 3) {
process_octal(); process_octal();
} }
return;
} else { } else {
process_octal(); process_octal();
match.push_back(t_char);
} }
} else if (is_hex) { } else if (is_hex) {
const bool is_hex_char = (t_char >= '0' && t_char <= '9') const bool is_hex_char = (t_char >= '0' && t_char <= '9')
@ -990,11 +981,22 @@ namespace chaiscript
if (is_hex_char) { if (is_hex_char) {
hex_matches.push_back(t_char); hex_matches.push_back(t_char);
return;
} else { } else {
process_hex(); process_hex();
match.push_back(t_char);
} }
} else if (is_octal_char) { }
if (t_char == '\\') {
if (is_escaped) {
match.push_back('\\');
is_escaped = false;
} else {
is_escaped = true;
}
} else {
if (is_escaped) {
if (is_octal_char) {
is_octal = true; is_octal = true;
octal_matches.push_back(t_char); octal_matches.push_back(t_char);
} else if (t_char == 'x') { } else if (t_char == 'x') {

View File

@ -3,4 +3,5 @@ assert_equal("\x39", "9")
assert_equal("\x039", "9") assert_equal("\x039", "9")
assert_equal("\x39g", "9g") assert_equal("\x39g", "9g")
assert_equal("b\x39g", "b9g") assert_equal("b\x39g", "b9g")
assert_equal("\x39\x38g", "98g")

View File

@ -3,4 +3,5 @@ assert_equal("\71", "9")
assert_equal("\071", "9") assert_equal("\071", "9")
assert_equal("\71a", "9a") assert_equal("\71a", "9a")
assert_equal("b\71a", "b9a") assert_equal("b\71a", "b9a")
assert_equal("\71\70a", "98a")