Skip to content

Commit

Permalink
simplify regex
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexRTer committed Mar 14, 2024
1 parent d29e1f2 commit 2f30d0b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/parser/daphnedsl/DaphneDSLVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1387,8 +1387,9 @@ antlrcpp::Any DaphneDSLVisitor::visitLiteral(DaphneDSLGrammarParser::LiteralCont
// spdlog::debug("stringview: {}", ss);
// spdlog::debug("substringview: {}", ss.substr(litStr.length() - 3));
// }
litStr = std::regex_replace(litStr, std::regex("_"), "");
litStr = std::regex_replace(litStr, std::regex("'"), "");

// remove digit separators
litStr = std::regex_replace(litStr, std::regex("_|'"), "");

if (litStr.back() == 'u')
return static_cast<mlir::Value>(builder.create<mlir::daphne::ConstantOp>(loc, std::stoul(litStr)));
Expand Down Expand Up @@ -1423,14 +1424,14 @@ antlrcpp::Any DaphneDSLVisitor::visitLiteral(DaphneDSLGrammarParser::LiteralCont
else if(litStr == "-inff")
val = -std::numeric_limits<float>::infinity();
else if (litStr.back() == 'f') {
litStr = std::regex_replace(litStr, std::regex("_"), "");
litStr = std::regex_replace(litStr, std::regex("'"), "");
// remove digit separators
litStr = std::regex_replace(litStr, std::regex("_|'"), "");
auto fval = std::stof(litStr.c_str());
return static_cast<mlir::Value>(builder.create<mlir::daphne::ConstantOp>(loc, fval));
}
else {
litStr = std::regex_replace(litStr, std::regex("_"), "");
litStr = std::regex_replace(litStr, std::regex("'"), "");
// remove digit separators
litStr = std::regex_replace(litStr, std::regex("_|'"), "");
val = std::atof(litStr.c_str());
}
return static_cast<mlir::Value>(builder.create<mlir::daphne::ConstantOp>(loc, val)
Expand Down

0 comments on commit 2f30d0b

Please sign in to comment.