Commit 37a0970f authored by Deepak Rangarajan's avatar Deepak Rangarajan Committed by Mark Meredith
Browse files

Fix parsing bug

parent c68f72f6
Loading
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -260,6 +260,7 @@ template <> struct action<attr_list> {
    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<cylinder> {
      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,6 +642,7 @@ template <> struct action<string_literal> {
    std::stringstream ss(in.string());
    std::string v;
    ss >> v;
    if (!st.current_name.empty())
      st.curr_attr[st.current_name] = v;
  }
};
@@ -650,6 +653,7 @@ template <> struct action<double_> {
    std::stringstream ss(in.string());
    double v;
    ss >> v;
    if (!st.current_name.empty())
      st.curr_attr[st.current_name] = v;
  }
};
@@ -658,6 +662,7 @@ template <> struct action<true_literal> {
  template <typename Input>
  static void apply(const Input &in, parser_state &st) {
    std::stringstream ss(in.string());
    if (!st.current_name.empty())
      st.curr_attr[st.current_name] = true;
  }
};
@@ -666,6 +671,7 @@ template <> struct action<false_literal> {
  template <typename Input>
  static void apply(const Input &in, parser_state &st) {
    std::stringstream ss(in.string());
    if (!st.current_name.empty())
      st.curr_attr[st.current_name] = false;
  }
};
@@ -674,6 +680,7 @@ template <> struct action<undef_literal> {
  template <typename Input>
  static void apply(const Input &in, parser_state &st) {
    std::stringstream ss(in.string());
    if (!st.current_name.empty())
      st.curr_attr[st.current_name] = UNDEFINED_STR;
  }
};
@@ -682,6 +689,7 @@ template <> struct action<vector_attr> {
  template <typename Input>
  static void apply(const Input &in, parser_state &st) {
    std::stringstream ss(in.string());
    if (!st.current_name.empty())
      st.curr_attr[st.current_name] = st.current_vec;
    st.current_vec.clear();
  }
@@ -691,6 +699,7 @@ template <> struct action<matrix_attr> {
  template <typename Input>
  static void apply(const Input &in, parser_state &st) {
    std::stringstream ss(in.string());
    if (!st.current_name.empty())
      st.curr_attr[st.current_name] = st.current_matrix;
    st.current_matrix.clear();
  }
+9 −0
Original line number Diff line number Diff line
@@ -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);
}
)");
}