From 0d3929070949719a67dabc6736513447f312b1f7 Mon Sep 17 00:00:00 2001 From: hasslesstech Date: Wed, 14 Oct 2026 20:07:28 +0300 Subject: [PATCH] fix infitite search for prior operator when opening brackets --- src/syntaxer.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/syntaxer.cpp b/src/syntaxer.cpp index 94bf5e7..34dd52a 100644 --- a/src/syntaxer.cpp +++ b/src/syntaxer.cpp @@ -2,10 +2,10 @@ #include "parser.hpp" #include "print.h" #include "syntaxer.hpp" +#include #include #include #include -#include namespace Syntax { @@ -606,13 +606,26 @@ static int same_inner_level_ops(const std::vector& tv, const static Expression::Token::Operator get_prior_mop(const std::vector& tv, const int location) { - for (int i = location - 1; i >= 0; i--) + for (int i = location - 1, lv = 0; i >= 0; i--) { - if (tv[i].t == Expression::Token::OPERATOR - && tv[i].v.o != Expression::Token::OPA - && tv[i].v.o != Expression::Token::CPA) + const Expression::Token &t = tv[i]; + + if (t.t == Expression::Token::OPERATOR) { - return tv[i].v.o; + if (t.v.o == Expression::Token::OPA) + { + lv--; + + if (lv == -2) + { + // enclosed in another pair of brackets, safe to assume ADD + return Expression::Token::ADD; + } + } + else + { + return t.v.o; + } } }