ATLAS Offline Software
Loading...
Searching...
No Matches
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 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.
 Lexer (const Lexer &)=delete
 Disable copying of this class.
 Lexer (Lexer &&)=default
 Default move-constructor behaviour.
Symbol nextSymbol ()
 Generate a new symbol from the token sequence.

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.

Constructor & Destructor Documentation

◆ Lexer() [1/3]

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}
Tokenizer m_tokenizer
std::string m_string
Tokenizer::iterator m_iterator

◆ Lexer() [2/3]

Disable copying of this class.

◆ Lexer() [3/3]

Default move-constructor behaviour.

Member Function Documentation

◆ 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, std::move(t)};
86}
Type
Enum over the possible symbols that can be extracted from the token stream.
Struct grouping together the type and original string representation of a symbol.

Member Data Documentation

◆ m_iterator

Definition at line 75 of file SelectionExprParser.h.

◆ m_string

Definition at line 73 of file SelectionExprParser.h.

◆ m_tokenizer

Definition at line 74 of file SelectionExprParser.h.


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