18using namespace msgSelectionHelpers;
22 const std::string::const_iterator& end,
23 std::string& tok)
const {
28 static const std::regex base_regex(
29 "^( ?((?:[^|&()! ]+)|(?:&&)|(?:!)|(?:\\()|(?:\\))|(?:\\|\\|))).*");
32 if (std::regex_match(next, end, m, base_regex)) {
34 next += m[1].length();
37 static const std::regex space_re{
"^ +$"};
38 if (std::regex_match(next, end, m, space_re)) {
42 throw std::runtime_error(
"Cannot tokenize: '" + std::string(next, end) +
49 m_iterator = m_tokenizer.begin();
70 else if (t ==
"false")
74 const std::regex base_regex(
"^([^|()&! ]*)$");
75 std::smatch base_match;
77 if (!std::regex_match(t, base_match, base_regex)) {
78 throw std::runtime_error(
"illegal variable encountered");
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.");
103 accessor = std::move(root);
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;
Lexer which turns a token stream into a stream of unambigous symbols to be used by a parser.
Type
Enum over the possible symbols that can be extracted from the token stream.
Lexer(const std::string &s)
Constructor from a strig.
Symbol nextSymbol()
Generate a new symbol from the token sequence.
Tokenizer::iterator m_iterator
bool operator()(std::string::const_iterator &next, const std::string::const_iterator &end, std::string &tok) const
Extracts the subsequent token from the input string iterator.
StatusCode term(std::unique_ptr< ISelectionReadAccessor > &root)
SelectionExprParser(DetailSelectionExprParser::Lexer lexer, bool defaultToChar=false)
Constructor for the parser which accepts a Lecer.
DetailSelectionExprParser::Lexer m_lexer
DetailSelectionExprParser::Lexer::Symbol m_symbol
StatusCode factor(std::unique_ptr< ISelectionReadAccessor > &root)
StatusCode expression(std::unique_ptr< ISelectionReadAccessor > &root)
StatusCode build(std::unique_ptr< ISelectionReadAccessor > &accessor)
Triggers the actual parsing of the expression.
Select isolated Photons, Electrons and Muons.
StatusCode makeSelectionReadAccessorVar(const std::string &name, std::unique_ptr< ISelectionReadAccessor > &accessor, bool defaultToChar)
Produces a simple ISelectionReadAccessor accessing the given decoration.
Struct grouping together the type and original string representation of a symbol.