18 using namespace msgSelectionHelpers;
20 namespace DetailSelectionExprParser {
21 bool Separator::operator()(std::string::const_iterator&
next,
22 const std::string::const_iterator&
end,
23 std::string& tok)
const {
29 "^( ?((?:[^|&()! ]+)|(?:&&)|(?:!)|(?:\\()|(?:\\))|(?:\\|\\|))).*");
32 if (std::regex_match(
next,
end,
m, base_regex)) {
34 next +=
m[1].length();
38 if (std::regex_match(
next,
end,
m, space_re)) {
42 throw std::runtime_error(
"Cannot tokenize: '" + std::string(
next,
end) +
48 Lexer::Lexer(
const std::string&
s) : m_string(
s), m_tokenizer(m_string, {}) {
49 m_iterator = m_tokenizer.begin();
53 if (m_iterator == m_tokenizer.end()) {
56 std::string
t = *m_iterator;
70 else if (
t ==
"false")
75 std::smatch base_match;
77 if (!std::regex_match(
t, base_match, base_regex)) {
78 throw std::runtime_error(
"illegal variable encountered");
91 : m_lexer(std::move(lexer)), m_defaultToChar(defaultToChar) {}
94 std::unique_ptr<ISelectionReadAccessor>&
accessor) {
95 std::unique_ptr<ISelectionReadAccessor>
root{
nullptr};
99 throw std::runtime_error(
100 "Not all symbols in expression were consumed. Check your expression.");
104 return StatusCode::SUCCESS;
108 std::unique_ptr<ISelectionReadAccessor>&
root) {
111 std::unique_ptr<ISelectionReadAccessor> left = std::move(
root);
113 std::unique_ptr<ISelectionReadAccessor> right = std::move(
root);
114 root = std::make_unique<SelectionAccessorExprOr>(std::move(left),
117 return StatusCode::SUCCESS;
121 std::unique_ptr<ISelectionReadAccessor>&
root) {
123 std::vector<std::unique_ptr<ISelectionReadAccessor>> factors;
124 factors.push_back(std::move(
root));
128 factors.push_back(std::move(
root));
131 if (factors.size() == 1) {
132 root = std::move(factors[0]);
134 root = std::make_unique<SelectionAccessorList>(std::move(factors));
136 return StatusCode::SUCCESS;
140 std::unique_ptr<ISelectionReadAccessor>&
root) {
143 root = std::make_unique<SelectionReadAccessorNull>(
true);
146 root = std::make_unique<SelectionReadAccessorNull>(
false);
150 std::unique_ptr<ISelectionReadAccessor> notEx =
151 std::make_unique<SelectionAccessorExprNot>(std::move(
root));
152 root = std::move(notEx);
156 throw std::runtime_error(
157 "Missing closing bracket, check your expression.");
165 throw std::runtime_error(
"Malformed expression.");
168 return StatusCode::SUCCESS;