From 9a3086fc065257503cbd7b0541734204115bfd74 Mon Sep 17 00:00:00 2001 From: zawwz Date: Fri, 5 Nov 2021 10:27:47 +0100 Subject: [PATCH] fix parenthesis arithmetic parsing --- src/parse.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/parse.cpp b/src/parse.cpp index bf53ca1..b7b810f 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -295,6 +295,18 @@ std::pair parse_arithmetic(parse_context ctx) ctx.i++; ret = new arithmetic_number_t( std::string(ctx.data+j, ctx.i-j) ); } + else if(word_eq("$((", ctx)) // arithmetics in arithmetics: equivalent to () + { + auto pa = parse_arithmetic(ctx); + ret = new arithmetic_parenthesis_t(pa.first); + ctx = pa.second; + ctx.i++; + if(ctx.i >= ctx.size || ctx[ctx.i] != ')') { + parse_error( "Unexpected ')', Expecting '))'", ctx ); + return std::make_pair(ret, ctx); + } + ctx.i++; + } else if(word_eq("$(", ctx)) { ctx.i+=2; @@ -313,7 +325,7 @@ std::pair parse_arithmetic(parse_context ctx) { ctx.i++; auto pa = parse_arithmetic(ctx); - ret = pa.first; + ret = new arithmetic_parenthesis_t(pa.first); ctx = pa.second; ctx.i++; }