diff --git a/src/csg/parser.cpp b/src/csg/parser.cpp index b3a43134aada44895404459a7cab0b7d0c3709fb..7e8491e5e74c531730c7c9086e43586853ab68b6 100644 --- a/src/csg/parser.cpp +++ b/src/csg/parser.cpp @@ -260,6 +260,7 @@ template <> struct action { std::stringstream ss(in.string()); st.curr_attrs.push_back(st.curr_attr); st.curr_attr.clear(); + st.current_name.clear(); } }; @@ -510,6 +511,7 @@ template <> struct action { if (curr_attr.count("r1") || curr_attr.count("r2")) { std::cout << " ERROR: cannot specify both r and (r1 or r2); ambiguous " << std::endl; + assert(false); } csg::Cylinder cyl; cyl.name = get_name(curr_attr); @@ -640,7 +642,8 @@ template <> struct action { std::stringstream ss(in.string()); std::string v; ss >> v; - st.curr_attr[st.current_name] = v; + if (!st.current_name.empty()) + st.curr_attr[st.current_name] = v; } }; @@ -650,7 +653,8 @@ template <> struct action { std::stringstream ss(in.string()); double v; ss >> v; - st.curr_attr[st.current_name] = v; + if (!st.current_name.empty()) + st.curr_attr[st.current_name] = v; } }; @@ -658,7 +662,8 @@ template <> struct action { template static void apply(const Input &in, parser_state &st) { std::stringstream ss(in.string()); - st.curr_attr[st.current_name] = true; + if (!st.current_name.empty()) + st.curr_attr[st.current_name] = true; } }; @@ -666,7 +671,8 @@ template <> struct action { template static void apply(const Input &in, parser_state &st) { std::stringstream ss(in.string()); - st.curr_attr[st.current_name] = false; + if (!st.current_name.empty()) + st.curr_attr[st.current_name] = false; } }; @@ -674,7 +680,8 @@ template <> struct action { template static void apply(const Input &in, parser_state &st) { std::stringstream ss(in.string()); - st.curr_attr[st.current_name] = UNDEFINED_STR; + if (!st.current_name.empty()) + st.curr_attr[st.current_name] = UNDEFINED_STR; } }; @@ -682,7 +689,8 @@ template <> struct action { template static void apply(const Input &in, parser_state &st) { std::stringstream ss(in.string()); - st.curr_attr[st.current_name] = st.current_vec; + if (!st.current_name.empty()) + st.curr_attr[st.current_name] = st.current_vec; st.current_vec.clear(); } }; @@ -691,7 +699,8 @@ template <> struct action { template static void apply(const Input &in, parser_state &st) { std::stringstream ss(in.string()); - st.curr_attr[st.current_name] = st.current_matrix; + if (!st.current_name.empty()) + st.curr_attr[st.current_name] = st.current_matrix; st.current_matrix.clear(); } }; diff --git a/src/csg/tests/parser/boolean.t.cpp b/src/csg/tests/parser/boolean.t.cpp index b96d85ce52df6aa2c865b8f4d4967600e8e379ea..6cb885bea85cff116d3ce0e3e6a2c7d02d0b8d5d 100644 --- a/src/csg/tests/parser/boolean.t.cpp +++ b/src/csg/tests/parser/boolean.t.cpp @@ -92,3 +92,12 @@ circle(size = [1,2], center=true); )"); CHECK(st == nullptr); } + +TEST_CASE("sphere and cylinder union", "[csg]") { + auto st = csg::parse_csg(R"( +sphere(r = 0.1); +multmatrix([[1, 0, 0, 0.5], [0, 1, 0, 0.1], [0, 0, 1, 0], [0, 0, 0, 1]]) { + cylinder(h = 0.1, r1 = 0.1, r2 = 0.1, center = false); +} +)"); +}