indent fix

This commit is contained in:
bronku 2025-11-25 15:36:51 +01:00
parent 5062a9b588
commit 4def48d206
3 changed files with 37 additions and 50 deletions

View file

@ -13,17 +13,17 @@ public:
{
int current = indent_stack.top();
if (spaces == current)
{
return 0;
}
if (spaces > current)
{
indent_stack.push(spaces);
return 1;
}
if (spaces == current)
{
return 0;
}
pending_dedents = 0;
while (indent_stack.top() > spaces)
{
@ -31,35 +31,23 @@ public:
pending_dedents++;
}
if (indent_stack.top() != spaces)
{
throw std::runtime_error("Indentation error");
}
return -1;
}
bool hasPendingDedents() const
{
return pending_dedents > 0;
}
void consumePendingDedent()
{
if (pending_dedents > 0)
{
pending_dedents--;
return -1;
}
return 0;
}
int flushAllDedents()
// returns false on failure
bool consumeDedent()
{
int total_dedents = 0;
while (indent_stack.size() > 1)
if (pending_dedents <= 0)
{
indent_stack.pop();
total_dedents++;
return false;
}
return total_dedents;
pending_dedents--;
return true;
}
};