3244
This commit is contained in:
parent
aefe0592e8
commit
2d7131670e
|
@ -61,17 +61,27 @@ string slurp_balanced_bracket(istream& in) {
|
||||||
while (in >> c) {
|
while (in >> c) {
|
||||||
if (c == '(') open_brackets.push_back(c);
|
if (c == '(') open_brackets.push_back(c);
|
||||||
if (c == ')') {
|
if (c == ')') {
|
||||||
|
if (open_brackets.empty() || open_brackets.back() != '(') {
|
||||||
|
raise << "unbalanced ')'\n" << end();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
assert(open_brackets.back() == '(');
|
assert(open_brackets.back() == '(');
|
||||||
open_brackets.pop_back();
|
open_brackets.pop_back();
|
||||||
}
|
}
|
||||||
if (c == '[') open_brackets.push_back(c);
|
if (c == '[') open_brackets.push_back(c);
|
||||||
if (c == ']') {
|
if (c == ']') {
|
||||||
assert(open_brackets.back() == '[');
|
if (open_brackets.empty() || open_brackets.back() != '[') {
|
||||||
|
raise << "unbalanced ']'\n" << end();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
open_brackets.pop_back();
|
open_brackets.pop_back();
|
||||||
}
|
}
|
||||||
if (c == '{') open_brackets.push_back(c);
|
if (c == '{') open_brackets.push_back(c);
|
||||||
if (c == '}') {
|
if (c == '}') {
|
||||||
assert(open_brackets.back() == '{');
|
if (open_brackets.empty() || open_brackets.back() != '{') {
|
||||||
|
raise << "unbalanced '}'\n" << end();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
open_brackets.pop_back();
|
open_brackets.pop_back();
|
||||||
}
|
}
|
||||||
result << c;
|
result << c;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user