From 536168eee4478ce2e22d15a3c41be93e306259d0 Mon Sep 17 00:00:00 2001 From: zawz Date: Wed, 11 Aug 2021 11:56:44 +0200 Subject: [PATCH] fix for in empty value --- include/struc.hpp | 4 +++- src/generate.cpp | 7 +++++-- src/parse.cpp | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/struc.hpp b/include/struc.hpp index 3f6ae6c..50b1bb9 100644 --- a/include/struc.hpp +++ b/include/struc.hpp @@ -521,7 +521,7 @@ public: class for_block : public block { public: - for_block(variable* in=nullptr, arglist* args=nullptr, list* lst=nullptr) { type=_obj::block_for; var=in; iter=args; ops=lst; } + for_block(variable* in=nullptr, arglist* args=nullptr, list* lst=nullptr, bool ii=false) { type=_obj::block_for; var=in; iter=args; ops=lst; in_val=ii; } ~for_block() { if(iter!=nullptr) delete iter; if(ops!=nullptr) delete ops; @@ -533,6 +533,8 @@ public: arglist* iter; list* ops; + bool in_val; + std::string generate(int ind, generate_context* ctx); std::string generate(int ind) { return this->generate(ind, nullptr); } }; diff --git a/src/generate.cpp b/src/generate.cpp index e303dc3..e12cca4 100644 --- a/src/generate.cpp +++ b/src/generate.cpp @@ -202,8 +202,11 @@ std::string for_block::generate(int ind, generate_context* ctx) std::string ret; ret += "for "+var->generate(ind); - if(iter != nullptr) - ret += " in " + iter->generate(ind); + if(in_val) { + ret += " in"; + if(iter != nullptr) + ret += " " + iter->generate(ind); + } ret += '\n'; ret += indented("do\n", ind); ret += ops->generate(ind+1); diff --git a/src/parse.cpp b/src/parse.cpp index ce7d67a..6ac2e57 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -1496,6 +1496,7 @@ std::pair parse_for(parse_context ctx) auto pp = parse_arglist(ctx, false); ret->iter = pp.first; ctx = pp.second; + ret->in_val=true; } else if(wp.first != "") {