ATLAS Offline Software
Classes | Public Types | Public Member Functions | Private Attributes | List of all members
CP::DetailSelectionExprParser::Lexer Class Reference

Lexer which turns a token stream into a stream of unambigous symbols to be used by a parser. More...

#include <SelectionExprParser.h>

Collaboration diagram for CP::DetailSelectionExprParser::Lexer:

Classes

struct  Symbol
 Struct grouping together the type and original string representation of a symbol. More...
 

Public Types

enum  Type {
  AND = 0, OR, LEFT, RIGHT,
  NOT, TRUE_LITERAL, FALSE_LITERAL, VAR,
  END
}
 Enum over the possible symbols that can be extracted from the token stream. More...
 

Public Member Functions

 Lexer (const std::string &s)
 Constructor from a strig. More...
 
 Lexer (const Lexer &)=delete
 Disable copying of this class. More...
 
 Lexer (Lexer &&)=default
 Default move-constructor behaviour. More...
 
Symbol nextSymbol ()
 Generate a new symbol from the token sequence. More...
 

Private Attributes

std::string m_string
 
Tokenizer m_tokenizer
 
Tokenizer::iterator m_iterator
 

Detailed Description

Lexer which turns a token stream into a stream of unambigous symbols to be used by a parser.

Definition at line 38 of file SelectionExprParser.h.

Member Enumeration Documentation

◆ Type

Enum over the possible symbols that can be extracted from the token stream.

Enumerator
AND 
OR 
LEFT 
RIGHT 
NOT 
TRUE_LITERAL 
FALSE_LITERAL 
VAR 
END 

Definition at line 50 of file SelectionExprParser.h.

50  {
51  AND = 0,
52  OR,
53  LEFT,
54  RIGHT,
55  NOT,
58  VAR,
59  END
60  };

Constructor & Destructor Documentation

◆ Lexer() [1/3]

CP::DetailSelectionExprParser::Lexer::Lexer ( const std::string &  s)

Constructor from a strig.

Definition at line 48 of file SelectionExprParser.cxx.

48  : m_string(s), m_tokenizer(m_string, {}) {
49  m_iterator = m_tokenizer.begin();
50 }

◆ Lexer() [2/3]

CP::DetailSelectionExprParser::Lexer::Lexer ( const Lexer )
delete

Disable copying of this class.

◆ Lexer() [3/3]

CP::DetailSelectionExprParser::Lexer::Lexer ( Lexer &&  )
default

Default move-constructor behaviour.

Member Function Documentation

◆ nextSymbol()

auto CP::DetailSelectionExprParser::Lexer::nextSymbol ( )

Generate a new symbol from the token sequence.

Definition at line 52 of file SelectionExprParser.cxx.

52  {
53  if (m_iterator == m_tokenizer.end()) {
54  return Symbol{END, ""};
55  }
56  std::string t = *m_iterator;
57  Type type;
58  if (t == "&&")
59  type = AND;
60  else if (t == "||")
61  type = OR;
62  else if (t == "(")
63  type = LEFT;
64  else if (t == ")")
65  type = RIGHT;
66  else if (t == "!")
67  type = NOT;
68  else if (t == "true")
70  else if (t == "false")
72  else {
73  // check if variable is valid
74  const std::regex base_regex("^([^|()&! ]*)$");
75  std::smatch base_match;
76 
77  if (!std::regex_match(t, base_match, base_regex)) {
78  throw std::runtime_error("illegal variable encountered");
79  } else {
80  type = VAR;
81  }
82  }
83 
84  ++m_iterator;
85  return Symbol{type, t};
86 }

Member Data Documentation

◆ m_iterator

Tokenizer::iterator CP::DetailSelectionExprParser::Lexer::m_iterator
private

Definition at line 75 of file SelectionExprParser.h.

◆ m_string

std::string CP::DetailSelectionExprParser::Lexer::m_string
private

Definition at line 73 of file SelectionExprParser.h.

◆ m_tokenizer

Tokenizer CP::DetailSelectionExprParser::Lexer::m_tokenizer
private

Definition at line 74 of file SelectionExprParser.h.


The documentation for this class was generated from the following files:
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
CP::DetailSelectionExprParser::Lexer::m_string
std::string m_string
Definition: SelectionExprParser.h:73
CP::DetailSelectionExprParser::Lexer::NOT
@ NOT
Definition: SelectionExprParser.h:55
CP::DetailSelectionExprParser::Lexer::OR
@ OR
Definition: SelectionExprParser.h:52
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
CP::DetailSelectionExprParser::Lexer::m_tokenizer
Tokenizer m_tokenizer
Definition: SelectionExprParser.h:74
CP::DetailSelectionExprParser::Lexer::m_iterator
Tokenizer::iterator m_iterator
Definition: SelectionExprParser.h:75
CP::DetailSelectionExprParser::Lexer::RIGHT
@ RIGHT
Definition: SelectionExprParser.h:54
CP::DetailSelectionExprParser::Lexer::FALSE_LITERAL
@ FALSE_LITERAL
Definition: SelectionExprParser.h:57
CP::DetailSelectionExprParser::Lexer::AND
@ AND
Definition: SelectionExprParser.h:51
xAODType
Definition: ObjectType.h:13
CP::DetailSelectionExprParser::Lexer::TRUE_LITERAL
@ TRUE_LITERAL
Definition: SelectionExprParser.h:56
CP::DetailSelectionExprParser::Lexer::LEFT
@ LEFT
Definition: SelectionExprParser.h:53
CP::DetailSelectionExprParser::Lexer::VAR
@ VAR
Definition: SelectionExprParser.h:58
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
CP::DetailSelectionExprParser::Lexer::END
@ END
Definition: SelectionExprParser.h:59