ATLAS Offline Software
Loading...
Searching...
No Matches
SelectionExprParser.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef SELECTION_HELPERS__SELECTION_EXPR_PARSER_H
6#define SELECTION_HELPERS__SELECTION_EXPR_PARSER_H
7
8#include <boost/tokenizer.hpp>
9#include <functional>
10#include <memory>
11#include <string>
12
15
16namespace CP {
17
18// Private detail namespace. This is not strictly private to enable testing
20
22class Separator {
23 public:
25 bool operator()(std::string::const_iterator &next,
26 const std::string::const_iterator &end,
27 std::string &tok) const;
28
30 void reset() {}
31};
32
33// Typedef over boost's tokenizer using the above Separator
34typedef boost::tokenizer<Separator> Tokenizer;
35
38class Lexer {
39 public:
41 Lexer(const std::string &s);
42
44 Lexer(const Lexer &) = delete;
46 Lexer(Lexer &&) = default;
47
61
64 struct Symbol {
66 std::string value;
67 };
68
71
72 private:
73 std::string m_string;
75 Tokenizer::iterator m_iterator;
76};
77} // namespace DetailSelectionExprParser
78
81 public:
87 bool defaultToChar = false);
88
92 StatusCode build(std::unique_ptr<ISelectionReadAccessor> &accessor);
93
94 private:
95 // Construct a binary OR
96 StatusCode expression(std::unique_ptr<ISelectionReadAccessor> &root);
97 // Construct an AND, attempts to group all ANDs it can see into a list
98 StatusCode term(std::unique_ptr<ISelectionReadAccessor> &root);
99 // Handle other constructs, potentially more ORs or ANDs.
100 StatusCode factor(std::unique_ptr<ISelectionReadAccessor> &root);
101
102 // The lexer to generate symbols from.
104 // The last extracted symbol
106 // Stores constructor parameter to be used in calls to makeSelectionAccessorVar.
108};
109
110} // namespace CP
111
112#endif
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.
Lexer(Lexer &&)=default
Default move-constructor behaviour.
Lexer(const Lexer &)=delete
Disable copying of this class.
Separator to be used in a boost::tokenizer.
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.
void reset()
Optional state reset method, does nothing.
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.
boost::tokenizer< Separator > Tokenizer
Select isolated Photons, Electrons and Muons.
Struct grouping together the type and original string representation of a symbol.