From cf07e71feabf36b2843c106b5f90144d200972c3 Mon Sep 17 00:00:00 2001 From: Carsten Arnholm Date: Sat, 21 Nov 2020 20:40:48 +0100 Subject: [PATCH] Improved csg error detection and reporting --- csg_parser/csg_node.cpp | 16 ++++++++-------- csg_parser/csg_node.h | 5 +++++ csg_parser/csg_parser.cpp | 2 ++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/csg_parser/csg_node.cpp b/csg_parser/csg_node.cpp index 476e019..f3d7d7e 100644 --- a/csg_parser/csg_node.cpp +++ b/csg_parser/csg_node.cpp @@ -314,10 +314,10 @@ size_t csg_node::dimension() else if(this_tag == "polyhedron")dim=3; else if(this_tag == "linear_extrude")dim=3; else if(this_tag == "rotate_extrude")dim=3; - else if(this_tag == "text") throw std::runtime_error("OpenSCAD csg line "+ std::to_string(m_line_no) +", 'text' is not supported, line\n"+ m_func); - else if(this_tag == "surface") throw std::runtime_error("OpenSCAD csg line "+ std::to_string(m_line_no) +", 'surface' is not supported\n"+ m_func ); - else if(this_tag == "import") throw std::runtime_error("OpenSCAD csg line "+ std::to_string(m_line_no) +", 'import' is not supported\n"+ m_func); - else if(this_tag == "resize") throw std::runtime_error("OpenSCAD csg line "+ std::to_string(m_line_no) +", 'resize' is not supported\n"+ m_func); + else if(this_tag == "text") throw std::runtime_error("OpenSCAD csg line "+ std::to_string(m_line_no) +", 'text' is not supported: "+ m_func); + else if(this_tag == "surface") throw std::runtime_error("OpenSCAD csg line "+ std::to_string(m_line_no) +", 'surface' is not supported: "+ m_func ); + else if(this_tag == "import") throw std::runtime_error("OpenSCAD csg line "+ std::to_string(m_line_no) +", 'import' is not supported with this file type: "+ m_func); + else if(this_tag == "resize") throw std::runtime_error("OpenSCAD csg line "+ std::to_string(m_line_no) +", 'resize' is not supported: "+ m_func); if(dim>0)return dim; @@ -350,10 +350,10 @@ size_t csg_node::dimension() else if(c->tag().substr(0,4) == "rend")dim= c->dimension(); else if(c->tag().substr(0,4) == "hull")dim= c->dimension(); - else if(c->tag() == "text") throw std::runtime_error("OpenSCAD csg: 'text' is not supported, line "+ std::to_string(m_line_no)); - else if(c->tag() == "surface") throw std::runtime_error("OpenSCAD csg: 'surface' is not supported, line "+ std::to_string(m_line_no)); - else if(c->tag() == "import") throw std::runtime_error("OpenSCAD csg: 'import' is not supported, line "+ std::to_string(m_line_no)); - else if(c->tag() == "resize") throw std::runtime_error("OpenSCAD csg: 'resize' is not supported, line "+ std::to_string(m_line_no)); + else if(c->tag() == "text") throw std::runtime_error("OpenSCAD csg line "+ std::to_string(c->line_no()) +", 'text' is not supported: "+ c->func()); + else if(c->tag()== "surface") throw std::runtime_error("OpenSCAD csg line "+ std::to_string(c->line_no()) +", 'surface' is not supported: "+ c->func() ); + else if(c->tag() == "import") throw std::runtime_error("OpenSCAD csg line "+ std::to_string(c->line_no()) +", 'import' is not supported with this file type: "+ c->func()); + else if(c->tag()== "resize") throw std::runtime_error("OpenSCAD csg line "+ std::to_string(c->line_no()) +", 'resize' is not supported: "+ c->func()); if(dim>0)return dim; } diff --git a/csg_parser/csg_node.h b/csg_parser/csg_node.h index 337dc11..32e0ea3 100644 --- a/csg_parser/csg_node.h +++ b/csg_parser/csg_node.h @@ -45,6 +45,11 @@ class csg_node { // return naked function name std::string tag() const; + // return full function string + std::string func() const { return m_func; } + + size_t line_no() const { return m_line_no; } + // look up parameter par_iterator par_find(const std::string& name) { return m_par.find(name); }; par_iterator par_begin() { return m_par.begin(); } diff --git a/csg_parser/csg_parser.cpp b/csg_parser/csg_parser.cpp index 8c5540d..d38ee19 100644 --- a/csg_parser/csg_parser.cpp +++ b/csg_parser/csg_parser.cpp @@ -77,6 +77,8 @@ void csg_parser::init_func(const std::string& csg) } + if(func.size() == 0) throw std::runtime_error("csg tree has 0 elements!"); + // build the tree size_t index = 0; m_root->build_tree(func,index);