OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
MSLang.cpp
Go to the documentation of this file.
1#include "Utilities/MSLang.h"
3#include "Physics/Physics.h"
18#include "Utilities/Mesher.h"
20
21#include <regex>
22
23#include <cmath>
24#include <cstdlib>
25#include <fstream>
26#include <iostream>
27#include <streambuf>
28#include <string>
29
30namespace mslang {
31 const std::string Function::UDouble = "([0-9]+\\.?[0-9]*([Ee][+-]?[0-9]+)?)";
32 const std::string Function::Double = "(-?[0-9]+\\.?[0-9]*([Ee][+-]?[0-9]+)?)";
33 const std::string Function::UInt = "([0-9]+)";
34 const std::string Function::FCall = "([a-z_]*)\\((.*)";
35
36 bool parse(std::string str, Function*& fun) {
37 iterator it = str.begin();
38 iterator end = str.end();
39 if (!Function::parse(it, end, fun)) {
40 std::cout << "parsing failed here:" << std::string(it, end) << std::endl;
41 return false;
42 }
43
44 return true;
45 }
46
47 bool Function::parse(iterator& it, const iterator& end, Function*& fun) {
48 std::regex functionCall(Function::FCall);
49 std::smatch what;
50
51 std::string str(it, end);
52 if (!std::regex_match(str, what, functionCall)) return false;
53
54 std::string identifier = what[1];
55 std::string arguments = what[2];
56 unsigned int shift = identifier.size() + 1;
57
58 if (identifier == "rectangle") {
59 fun = new Rectangle;
60 it += shift;
61 if (!Rectangle::parse_detail(it, end, fun)) return false;
62
63 return true;
64 } else if (identifier == "ellipse") {
65 fun = new Ellipse;
66 it += shift;
67 if (!Ellipse::parse_detail(it, end, fun)) return false;
68
69 return true;
70 } else if (identifier == "polygon") {
71 fun = new Polygon;
72 it += shift;
73 if (!Polygon::parse_detail(it, end, fun)) return false;
74
75 return true;
76 } else if (identifier == "mask") {
77 fun = new Mask;
78 it += shift;
79
80 return Mask::parse_detail(it, end, fun);
81 } else if (identifier == "repeat") {
82 fun = new Repeat;
83 it += shift;
84 if (!Repeat::parse_detail(it, end, fun)) return false;
85
86 return true;
87 } else if (identifier == "rotate") {
88 fun = new Rotation;
89 it += shift;
90 if (!Rotation::parse_detail(it, end, fun)) return false;
91
92 return true;
93 } else if (identifier == "translate") {
94 fun = new Translation;
95 it += shift;
96 if (!Translation::parse_detail(it, end, fun)) return false;
97
98 return true;
99 } else if (identifier == "shear") {
100 fun = new Shear;
101 it += shift;
102 if (!Shear::parse_detail(it, end, fun)) return false;
103
104 return true;
105 } else if (identifier == "union") {
106 fun = new Union;
107 it += shift;
108 if (!Union::parse_detail(it, end, fun)) return false;
109
110 return true;
111 } else if (identifier == "difference") {
112 fun = new Difference;
113 it += shift;
114 if (!Difference::parse_detail(it, end, fun)) return false;
115
116 return true;
117 } else if (identifier == "symmetric_difference") {
118 fun = new SymmetricDifference;
119 it += shift;
120 if (!SymmetricDifference::parse_detail(it, end, fun)) return false;
121
122 return true;
123 } else if (identifier == "intersection") {
124 fun = new Intersection;
125 it += shift;
126 if (!Intersection::parse_detail(it, end, fun)) return false;
127
128 return true;
129 }
130
131 return (it == end);
132 }
133} // namespace mslang
std::string::iterator iterator
Definition MSLang.h:14
bool parse(std::string str, Function *&fun)
Definition MSLang.cpp:36
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
static bool parse_detail(iterator &it, const iterator &end, Function *fun)
Definition Ellipse.cpp:117
static const std::string FCall
Definition MSLang.h:34
static const std::string Double
Definition MSLang.h:32
static const std::string UDouble
Definition MSLang.h:31
static bool parse(iterator &it, const iterator &end, Function *&fun)
Definition MSLang.cpp:47
static const std::string UInt
Definition MSLang.h:33
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
Definition Mask.cpp:123
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
Definition Polygon.cpp:15
static bool parse_detail(iterator &it, const iterator &end, Function *fun)
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
Definition Repeat.cpp:37
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
Definition Rotation.cpp:36
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
Definition Shear.cpp:40
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
Definition Union.cpp:29