add color highlighting during token post-processing
This commit is contained in:
+15
-6
@@ -420,7 +420,7 @@ static void write_operation(
|
||||
mp.erase(mp.begin() + position, mp.begin() + position + 1);
|
||||
}
|
||||
|
||||
static void add_bracket_to(std::vector<Expression::Token>& tv, const int location, const int direction)
|
||||
static int add_bracket_to(std::vector<Expression::Token>& tv, const int location, const int direction)
|
||||
{
|
||||
int i = location + direction, l = tv.size(), lv = 0;
|
||||
|
||||
@@ -438,7 +438,7 @@ static void add_bracket_to(std::vector<Expression::Token>& tv, const int locatio
|
||||
if (!lv)
|
||||
{
|
||||
tv.insert(tv.begin() + i + 1, Expression::Token(Expression::Token::OPA));
|
||||
return;
|
||||
return i + 1;
|
||||
}
|
||||
|
||||
if (tv[i].v.o == Expression::Token::OPA)
|
||||
@@ -449,6 +449,7 @@ static void add_bracket_to(std::vector<Expression::Token>& tv, const int locatio
|
||||
}
|
||||
|
||||
tv.insert(tv.begin(), Expression::Token(Expression::Token::OPA));
|
||||
return 0;
|
||||
}
|
||||
else if (direction == 1)
|
||||
{
|
||||
@@ -464,7 +465,7 @@ static void add_bracket_to(std::vector<Expression::Token>& tv, const int locatio
|
||||
if (!lv)
|
||||
{
|
||||
tv.insert(tv.begin() + i, Expression::Token(Expression::Token::CPA));
|
||||
return;
|
||||
return i;
|
||||
}
|
||||
|
||||
if (tv[i].v.o == Expression::Token::CPA)
|
||||
@@ -475,6 +476,12 @@ static void add_bracket_to(std::vector<Expression::Token>& tv, const int locatio
|
||||
}
|
||||
|
||||
tv.emplace_back(Expression::Token::CPA);
|
||||
return i;
|
||||
}
|
||||
else
|
||||
{
|
||||
pr_warn("Invalid direction given, this is a big bug!");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -699,8 +706,10 @@ void apply_corrections(std::vector<Expression::Token>& tv)
|
||||
}
|
||||
|
||||
// inverse order to keep location valid between calls
|
||||
add_bracket_to(tv, i, 1);
|
||||
add_bracket_to(tv, i, -1);
|
||||
std::vector<int> highlight_locations;
|
||||
highlight_locations.emplace_back(i+1);
|
||||
highlight_locations.emplace_back(add_bracket_to(tv, i, 1) + 1);
|
||||
highlight_locations.emplace(highlight_locations.begin(), add_bracket_to(tv, i, -1));
|
||||
|
||||
// advance one step to compensate for inserted left bracket
|
||||
i++;
|
||||
@@ -709,7 +718,7 @@ void apply_corrections(std::vector<Expression::Token>& tv)
|
||||
relative_level++;
|
||||
|
||||
pr_debug("Updated vector:");
|
||||
Parser::print_math_vector(tv);
|
||||
Parser::print_math_vector(tv, highlight_locations);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user