Skip to content

Commit 042c867

Browse files
committed
Add D code parsing
1 parent 639cdbe commit 042c867

File tree

12 files changed

+175
-5
lines changed

12 files changed

+175
-5
lines changed

cpp/gerber/include/gerber/ast/ast.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
#include "./file.hpp"
55
#include "./node.hpp"
66

7+
#include "./d_codes/D01.hpp"
8+
#include "./d_codes/D02.hpp"
9+
#include "./d_codes/D03.hpp"
10+
#include "./d_codes/Dnn.hpp"
11+
712
#include "./g_codes/G01.hpp"
813
#include "./g_codes/G02.hpp"
914
#include "./g_codes/G03.hpp"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
#include "gerber/ast/command.hpp"
3+
#include <string>
4+
5+
namespace gerber {
6+
class D01 : public Command {
7+
public:
8+
std::string getNodeName() const override;
9+
};
10+
} // namespace gerber
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
#include "gerber/ast/command.hpp"
3+
#include <string>
4+
5+
namespace gerber {
6+
class D02 : public Command {
7+
public:
8+
std::string getNodeName() const override;
9+
};
10+
} // namespace gerber
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
#include "gerber/ast/command.hpp"
3+
#include <string>
4+
5+
namespace gerber {
6+
class D03 : public Command {
7+
public:
8+
std::string getNodeName() const override;
9+
};
10+
} // namespace gerber
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
#include "gerber/ast/command.hpp"
3+
#include <string>
4+
5+
namespace gerber {
6+
class Dnn : public Command {
7+
std::string aperture_id;
8+
9+
public:
10+
Dnn(const std::string_view& aperture_id_);
11+
std::string getNodeName() const override;
12+
std::string getApertureId() const;
13+
};
14+
} // namespace gerber

cpp/gerber/include/gerber/parser.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
#pragma once
2-
#include "fmt/format.h"
32
#include "gerber/ast/ast.hpp"
43
#include "gerber/errors.hpp"
5-
#include <algorithm>
64
#include <cstdint>
75
#include <memory>
86
#include <regex>
9-
#include <stdexcept>
107
#include <string>
118
#include <string_view>
129
#include <tuple>
@@ -25,6 +22,8 @@ namespace gerber {
2522
std::string_view full_source;
2623
location_t global_index;
2724
// Regular expressions cache
25+
// D-codes
26+
std::regex d_code_regex{"^[Dd]0*([1-9][0-9]*)\\*"};
2827
// G-codes
2928
std::regex g_code_regex{"^[Gg]0*([1-9][0-9]*)\\*"};
3029
std::regex g04_regex{"^[Gg]0*4([^%*]+)\\*"};
@@ -39,6 +38,7 @@ namespace gerber {
3938
location_t parse_global(const std::string_view& source, const location_t& index);
4039
[[noreturn]] void throw_syntax_error();
4140
offset_t parse_g_code(const std::string_view& gerber, const location_t& index);
41+
offset_t parse_d_code(const std::string_view& source, const location_t& index);
4242

4343
template <typename coordinate_type>
4444
offset_t parse_coordinate(const std::string_view& source, const location_t& index) {

cpp/gerber/src/ast/d_codes/D01.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "gerber/ast/d_codes/D01.hpp"
2+
3+
namespace gerber {
4+
std::string D01::getNodeName() const {
5+
return "D01";
6+
}
7+
} // namespace gerber

cpp/gerber/src/ast/d_codes/D02.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "gerber/ast/d_codes/D02.hpp"
2+
3+
namespace gerber {
4+
std::string D02::getNodeName() const {
5+
return "D02";
6+
}
7+
} // namespace gerber

cpp/gerber/src/ast/d_codes/D03.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "gerber/ast/d_codes/D03.hpp"
2+
3+
namespace gerber {
4+
std::string D03::getNodeName() const {
5+
return "D03";
6+
}
7+
} // namespace gerber

cpp/gerber/src/ast/d_codes/Dnn.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "gerber/ast/d_codes/Dnn.hpp"
2+
3+
namespace gerber {
4+
Dnn::Dnn(const std::string_view& aperture_id_) :
5+
aperture_id(aperture_id_) {}
6+
7+
std::string Dnn::getNodeName() const {
8+
return "Dnn";
9+
}
10+
11+
std::string Dnn::getApertureId() const {
12+
return aperture_id;
13+
}
14+
} // namespace gerber

0 commit comments

Comments
 (0)