ATLAS Offline Software
Loading...
Searching...
No Matches
CP::SelectionExprParser Class Reference

Public interface for the expression parsing facility. More...

#include <SelectionExprParser.h>

Collaboration diagram for CP::SelectionExprParser:

Public Member Functions

 SelectionExprParser (DetailSelectionExprParser::Lexer lexer, bool defaultToChar=false)
 Constructor for the parser which accepts a Lecer.
StatusCode build (std::unique_ptr< ISelectionReadAccessor > &accessor)
 Triggers the actual parsing of the expression.

Private Member Functions

StatusCode expression (std::unique_ptr< ISelectionReadAccessor > &root)
StatusCode term (std::unique_ptr< ISelectionReadAccessor > &root)
StatusCode factor (std::unique_ptr< ISelectionReadAccessor > &root)

Private Attributes

DetailSelectionExprParser::Lexer m_lexer
DetailSelectionExprParser::Lexer::Symbol m_symbol {}
bool m_defaultToChar {}

Detailed Description

Public interface for the expression parsing facility.

Definition at line 80 of file SelectionExprParser.h.

Constructor & Destructor Documentation

◆ SelectionExprParser()

CP::SelectionExprParser::SelectionExprParser ( DetailSelectionExprParser::Lexer lexer,
bool defaultToChar = false )

Constructor for the parser which accepts a Lecer.

Parameters
lexerThe lexer to use for parsing
Note
Lexer can be auto-constructed from a string, so you can pass one directly.
Parameters
defaultToCharAssume "as_char" as default encoding

Definition at line 90 of file SelectionExprParser.cxx.

91 : m_lexer(std::move(lexer)), m_defaultToChar(defaultToChar) {}
DetailSelectionExprParser::Lexer m_lexer

Member Function Documentation

◆ build()

StatusCode CP::SelectionExprParser::build ( std::unique_ptr< ISelectionReadAccessor > & accessor)

Triggers the actual parsing of the expression.

Parameters
[out]accessorUnique pointer the resulting accessor will be written to.
Returns
StatusCode noting whether the operation succeeded.

Definition at line 93 of file SelectionExprParser.cxx.

94 {
95 std::unique_ptr<ISelectionReadAccessor> root{nullptr};
96 ANA_CHECK(expression(root));
97
98 if (m_symbol.type != Lexer::END) {
99 throw std::runtime_error(
100 "Not all symbols in expression were consumed. Check your expression.");
101 }
102
103 accessor = std::move(root);
104 return StatusCode::SUCCESS;
105}
#define ANA_CHECK(EXP)
check whether the given expression was successful
DetailSelectionExprParser::Lexer::Symbol m_symbol
StatusCode expression(std::unique_ptr< ISelectionReadAccessor > &root)
const AccessorWrapper< T > * accessor(xAOD::JetAttribute::AttributeID id)
Returns an attribute accessor corresponding to an AttributeID.

◆ expression()

StatusCode CP::SelectionExprParser::expression ( std::unique_ptr< ISelectionReadAccessor > & root)
private

Definition at line 107 of file SelectionExprParser.cxx.

108 {
109 ANA_CHECK(term(root));
110 while (m_symbol.type == Lexer::OR) {
111 std::unique_ptr<ISelectionReadAccessor> left = std::move(root);
112 ANA_CHECK(term(root));
113 std::unique_ptr<ISelectionReadAccessor> right = std::move(root);
114 root = std::make_unique<SelectionAccessorExprOr>(std::move(left),
115 std::move(right));
116 }
117 return StatusCode::SUCCESS;
118}
StatusCode term(std::unique_ptr< ISelectionReadAccessor > &root)

◆ factor()

StatusCode CP::SelectionExprParser::factor ( std::unique_ptr< ISelectionReadAccessor > & root)
private

Definition at line 139 of file SelectionExprParser.cxx.

140 {
141 m_symbol = m_lexer.nextSymbol();
142 if (m_symbol.type == Lexer::TRUE_LITERAL) {
143 root = std::make_unique<SelectionReadAccessorNull>(true);
144 m_symbol = m_lexer.nextSymbol();
145 } else if (m_symbol.type == Lexer::FALSE_LITERAL) {
146 root = std::make_unique<SelectionReadAccessorNull>(false);
147 m_symbol = m_lexer.nextSymbol();
148 } else if (m_symbol.type == Lexer::NOT) {
149 ANA_CHECK(factor(root));
150 std::unique_ptr<ISelectionReadAccessor> notEx =
151 std::make_unique<SelectionAccessorExprNot>(std::move(root));
152 root = std::move(notEx);
153 } else if (m_symbol.type == Lexer::LEFT) {
154 ANA_CHECK(expression(root));
155 if (m_symbol.type != Lexer::RIGHT) {
156 throw std::runtime_error(
157 "Missing closing bracket, check your expression.");
158 }
159 m_symbol = m_lexer.nextSymbol();
160
161 } else if (m_symbol.type == Lexer::VAR) {
163 m_symbol = m_lexer.nextSymbol();
164 } else {
165 throw std::runtime_error("Malformed expression.");
166 }
167
168 return StatusCode::SUCCESS;
169}
StatusCode factor(std::unique_ptr< ISelectionReadAccessor > &root)
StatusCode makeSelectionReadAccessorVar(const std::string &name, std::unique_ptr< ISelectionReadAccessor > &accessor, bool defaultToChar)
Produces a simple ISelectionReadAccessor accessing the given decoration.

◆ term()

StatusCode CP::SelectionExprParser::term ( std::unique_ptr< ISelectionReadAccessor > & root)
private

Definition at line 120 of file SelectionExprParser.cxx.

121 {
122 ANA_CHECK(factor(root));
123 std::vector<std::unique_ptr<ISelectionReadAccessor>> factors;
124 factors.push_back(std::move(root));
125
126 while (m_symbol.type == Lexer::AND) {
127 ANA_CHECK(factor(root));
128 factors.push_back(std::move(root));
129 }
130
131 if (factors.size() == 1) {
132 root = std::move(factors[0]);
133 } else {
134 root = std::make_unique<SelectionAccessorList>(std::move(factors));
135 }
136 return StatusCode::SUCCESS;
137}

Member Data Documentation

◆ m_defaultToChar

bool CP::SelectionExprParser::m_defaultToChar {}
private

Definition at line 107 of file SelectionExprParser.h.

107{};

◆ m_lexer

DetailSelectionExprParser::Lexer CP::SelectionExprParser::m_lexer
private

Definition at line 103 of file SelectionExprParser.h.

◆ m_symbol

DetailSelectionExprParser::Lexer::Symbol CP::SelectionExprParser::m_symbol {}
private

Definition at line 105 of file SelectionExprParser.h.

105{};

The documentation for this class was generated from the following files: