diff --git a/core/src/smoke_gcode_parser.cpp b/core/src/smoke_gcode_parser.cpp index a5aeb33..5c07a3e 100644 --- a/core/src/smoke_gcode_parser.cpp +++ b/core/src/smoke_gcode_parser.cpp @@ -1493,10 +1493,18 @@ std::string expand_expressions_and_parameters(const std::string &line, out.reserve(line.size()); for (size_t i = 0; i < line.size();) { if (std::isalpha(static_cast(line[i])) && i + 1 < line.size()) { + const size_t value_start = i + 1; + size_t function_start = value_start; + if ((line[function_start] == '+' || line[function_start] == '-') && + function_start + 1 < line.size() && + !std::isdigit(static_cast(line[function_start + 1])) && + line[function_start + 1] != '.') { + ++function_start; + } size_t function_end = 0; - if (unary_function_span(line, i + 1, &function_end)) { + if (unary_function_span(line, function_start, &function_end)) { double value = 0.0; - if (!evaluate_expression(line.substr(i + 1, function_end - i - 1), + if (!evaluate_expression(line.substr(value_start, function_end - value_start), call_stack, parameters, named_parameters, diff --git a/core/tests/cnc_sim_api_smoke.cpp b/core/tests/cnc_sim_api_smoke.cpp index 4aa1922..19047ea 100644 --- a/core/tests/cnc_sim_api_smoke.cpp +++ b/core/tests/cnc_sim_api_smoke.cpp @@ -273,6 +273,7 @@ int main() { bool saw_math_function_assignment = false; bool saw_word_unary_function_motion = false; bool saw_word_atan_function_motion = false; + bool saw_signed_word_unary_function_motion = false; bool saw_trig_function_motion = false; bool saw_inverse_trig_function_motion = false; bool saw_atan_function_motion = false; @@ -3571,7 +3572,8 @@ int main() { "G21 G90\n" "F100\n" "G1 XABS[-2]\n" - "G1 YATAN[1]/[1]\n"; + "G1 YATAN[1]/[1]\n" + "G1 Z-ABS[-2]\n"; events.clear(); ok &= expect(cnc_sim_parse_program(sim, word_unary_function_program, @@ -3586,9 +3588,14 @@ int main() { (event.type == CNC_SIM_EVENT_LINEAR_FEED && event.line == 4 && near(event.end.y, 45.0)); + saw_signed_word_unary_function_motion = saw_signed_word_unary_function_motion || + (event.type == CNC_SIM_EVENT_LINEAR_FEED && + event.line == 5 && + event.end.z == -2.0); } ok &= expect(saw_word_unary_function_motion, "expected LinuxCNC unary function as a word value"); ok &= expect(saw_word_atan_function_motion, "expected LinuxCNC ATAN function as a word value"); + ok &= expect(saw_signed_word_unary_function_motion, "expected signed LinuxCNC unary function as a word value"); const char additional_math_function_program[] = "#1 = [ASIN[0.5] + ACOS[0.5]]\n"