From 1b27e3c5af5cbaa403de70f0827853a7f76152e0 Mon Sep 17 00:00:00 2001 From: roastduck Date: Sat, 21 Nov 2020 18:27:59 +0800 Subject: [PATCH] fix -s arg parser --- tools/taco.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/tools/taco.cpp b/tools/taco.cpp index 7a91409ff..f71c7fab4 100644 --- a/tools/taco.cpp +++ b/tools/taco.cpp @@ -814,23 +814,19 @@ int main(int argc, char* argv[]) { } else if ("-s" == argName) { setSchedule = true; - bool insideCall = false; - bool parsingExpr = false; + int parenthesesCnt = 0; - std::replace_if(argValue.begin(), argValue.end(), [&insideCall, &parsingExpr](char c) { + std::replace_if(argValue.begin(), argValue.end(), [&parenthesesCnt](char c) { if (c == '(') { - if (insideCall) { - parsingExpr = true; // need to handle precompute case specially - } else { - insideCall = true; - return true; + if (parenthesesCnt++ == 0) { // '(' for a call + return true; } } else if (c == ',') { - return !parsingExpr; + return parenthesesCnt <= 1; } else if (c == ')') { - bool previous = parsingExpr; - parsingExpr = false; - return !previous; + if (--parenthesesCnt == 0) { // ')' for a call + return true; + } } return false; }, ' ');