ATLAS Offline Software
Loading...
Searching...
No Matches
python.EventSelectionConfig._ExprParser Class Reference
Collaboration diagram for python.EventSelectionConfig._ExprParser:

Public Member Functions

 __init__ (self, token_re)
 tokenize (self, text)
 parse (self, tokens)

Protected Member Functions

 _peek (self)
 _advance (self)
 _expect (self, kind)
 _parse_funcall (self)
 _parse_operand (self)
 _parse_sign (self)
 _parse_value (self)

Protected Attributes

 _token_re = token_re
list _tokens = []
int _pos = 0

Detailed Description

Small recursive-descent parser for EXPR selector expressions.

Definition at line 42 of file EventSelectionConfig.py.

Constructor & Destructor Documentation

◆ __init__()

python.EventSelectionConfig._ExprParser.__init__ ( self,
token_re )

Definition at line 45 of file EventSelectionConfig.py.

45 def __init__(self, token_re):
46 self._token_re = token_re
47 self._tokens = []
48 self._pos = 0
49

Member Function Documentation

◆ _advance()

python.EventSelectionConfig._ExprParser._advance ( self)
protected

Definition at line 66 of file EventSelectionConfig.py.

66 def _advance(self):
67 token = self._tokens[self._pos]
68 self._pos += 1
69 return token
70

◆ _expect()

python.EventSelectionConfig._ExprParser._expect ( self,
kind )
protected

Definition at line 71 of file EventSelectionConfig.py.

71 def _expect(self, kind):
72 token = self._advance()
73 if token[0] != kind:
74 raise InconsistentSettingsError(
75 f"[EventSelectionConfig] EXPR: expected {kind}, got '{token[1]}'")
76 return token
77

◆ _parse_funcall()

python.EventSelectionConfig._ExprParser._parse_funcall ( self)
protected

Definition at line 87 of file EventSelectionConfig.py.

87 def _parse_funcall(self):
88 variable = self._expect("ID")[1]
89 self._expect("LP")
90 operands = [self._parse_operand()]
91 separator = None
92 while self._peek()[0] in ("COMMA", "PLUS"):
93 sep = "," if self._advance()[0] == "COMMA" else "+"
94 if separator is None:
95 separator = sep
96 elif sep != separator:
97 raise InconsistentSettingsError(
98 "[EventSelectionConfig] EXPR: cannot mix ',' and '+' separators")
99 operands.append(self._parse_operand())
100 self._expect("RP")
101 return variable, separator, operands
102

◆ _parse_operand()

python.EventSelectionConfig._ExprParser._parse_operand ( self)
protected

Definition at line 103 of file EventSelectionConfig.py.

103 def _parse_operand(self):
104 coll = self._expect("ID")[1]
105 index = None
106 if self._peek()[0] == "LB":
107 self._advance()
108 index = int(self._expect("NUM")[1])
109 self._expect("RB")
110 return coll, index
111

◆ _parse_sign()

python.EventSelectionConfig._ExprParser._parse_sign ( self)
protected

Definition at line 112 of file EventSelectionConfig.py.

112 def _parse_sign(self):
113 token = self._advance()
114 if token[0] not in ("LT", "GT", "EQ", "GE", "LE"):
115 raise InconsistentSettingsError(
116 f"[EventSelectionConfig] EXPR: expected a comparison operator, got '{token[1]}'")
117 return token[0]
118

◆ _parse_value()

python.EventSelectionConfig._ExprParser._parse_value ( self)
protected

Definition at line 119 of file EventSelectionConfig.py.

119 def _parse_value(self):
120 negative = False
121 if self._peek()[0] == "MINUS":
122 self._advance()
123 negative = True
124 value = float(self._expect("NUM")[1])
125 return -value if negative else value
126
127
128

◆ _peek()

python.EventSelectionConfig._ExprParser._peek ( self)
protected

Definition at line 63 of file EventSelectionConfig.py.

63 def _peek(self):
64 return self._tokens[self._pos]
65

◆ parse()

python.EventSelectionConfig._ExprParser.parse ( self,
tokens )

Definition at line 78 of file EventSelectionConfig.py.

78 def parse(self, tokens):
79 self._tokens = tokens
80 self._pos = 0
81 variable, separator, operands = self._parse_funcall()
82 sign = self._parse_sign()
83 ref_value = self._parse_value()
84 self._expect("END")
85 return variable, separator, operands, sign, ref_value
86
std::map< std::string, std::string, std::less<> > parse(const std::string &list)

◆ tokenize()

python.EventSelectionConfig._ExprParser.tokenize ( self,
text )

Definition at line 50 of file EventSelectionConfig.py.

50 def tokenize(self, text):
51 tokens, pos = [], 0
52 while pos < len(text):
53 match = self._token_re.match(text, pos)
54 if not match:
55 raise InconsistentSettingsError(
56 f"[EventSelectionConfig] EXPR: cannot parse near '{text[pos:]}'")
57 pos = match.end()
58 if match.lastgroup != "WS":
59 tokens.append((match.lastgroup, match.group()))
60 tokens.append(("END", ""))
61 return tokens
62
std::vector< std::string > tokenize(std::string_view the_str, std::string_view delimiters)
Splits the string into smaller substrings.
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition hcg.cxx:359

Member Data Documentation

◆ _pos

int python.EventSelectionConfig._ExprParser._pos = 0
protected

Definition at line 48 of file EventSelectionConfig.py.

◆ _token_re

python.EventSelectionConfig._ExprParser._token_re = token_re
protected

Definition at line 46 of file EventSelectionConfig.py.

◆ _tokens

list python.EventSelectionConfig._ExprParser._tokens = []
protected

Definition at line 47 of file EventSelectionConfig.py.


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