bc: fix interactive handling of comments in strings and quotes in comments
function old new delta zbc_lex_next 1965 1979 +14 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
c192b0442b
commit
94576d2b97
@ -2910,25 +2910,29 @@ static bool bc_lex_more_input(void)
|
|||||||
string = G.input_buffer.v + prevlen;
|
string = G.input_buffer.v + prevlen;
|
||||||
while (*string) {
|
while (*string) {
|
||||||
char c = *string;
|
char c = *string;
|
||||||
if (string == G.input_buffer.v || string[-1] != '\\') {
|
if (!comment) {
|
||||||
if (IS_BC)
|
if (string == G.input_buffer.v || string[-1] != '\\') {
|
||||||
str ^= (c == '"');
|
if (IS_BC)
|
||||||
else {
|
str ^= (c == '"');
|
||||||
if (c == ']')
|
else {
|
||||||
str -= 1;
|
if (c == ']')
|
||||||
else if (c == '[')
|
str -= 1;
|
||||||
str += 1;
|
else if (c == '[')
|
||||||
|
str += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
string++;
|
string++;
|
||||||
if (c == '/' && *string == '*') {
|
if (!str) {
|
||||||
comment = true;
|
if (c == '/' && *string == '*') {
|
||||||
string++;
|
comment = true;
|
||||||
continue;
|
string++;
|
||||||
}
|
continue;
|
||||||
if (c == '*' && *string == '/') {
|
}
|
||||||
comment = false;
|
if (c == '*' && *string == '/') {
|
||||||
string++;
|
comment = false;
|
||||||
|
string++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (str != 0 || comment) {
|
if (str != 0 || comment) {
|
||||||
|
@ -6,16 +6,28 @@
|
|||||||
|
|
||||||
# testing "test name" "command" "expected result" "file input" "stdin"
|
# testing "test name" "command" "expected result" "file input" "stdin"
|
||||||
|
|
||||||
testing "bc comment 1" \
|
testing "bc comment" \
|
||||||
"bc" \
|
"bc" \
|
||||||
"3\n" \
|
"3\n" \
|
||||||
"" "1 /* comment */ + 2"
|
"" "1 /* comment */ + 2"
|
||||||
|
|
||||||
testing "bc comment 2: /*/ is not a closed comment" \
|
testing "bc /*/ is not a closed comment" \
|
||||||
"bc" \
|
"bc" \
|
||||||
"4\n" \
|
"4\n" \
|
||||||
"" "1 /*/ + 2 */ + 3"
|
"" "1 /*/ + 2 */ + 3"
|
||||||
|
|
||||||
|
# this needs interactive testing
|
||||||
|
testing "bc comment with \"" \
|
||||||
|
"bc" \
|
||||||
|
"3\n" \
|
||||||
|
"" "1 /* \" */ + 2"
|
||||||
|
|
||||||
|
# this needs interactive testing
|
||||||
|
testing "bc \"string/*\" is not a comment" \
|
||||||
|
"bc" \
|
||||||
|
"string/*9\n" \
|
||||||
|
"" "\"string/*\";9"
|
||||||
|
|
||||||
testing "bc comment 3: unterminated #comment" \
|
testing "bc comment 3: unterminated #comment" \
|
||||||
"bc" \
|
"bc" \
|
||||||
"" \
|
"" \
|
||||||
|
Loading…
Reference in New Issue
Block a user