@@ -115,22 +115,9 @@ def tokenize(self, expression, options=None):
115115 elif self ._current == '!' :
116116 yield self ._match_or_else ('=' , 'ne' , 'not' )
117117 elif self ._current == '=' :
118- if self ._next () == '=' :
119- yield {'type' : 'eq' , 'value' : '==' ,
120- 'start' : self ._position - 1 , 'end' : self ._position }
121- self ._next ()
122- else :
123- if self ._current is None :
124- # If we're at the EOF, we never advanced
125- # the position so we don't need to rewind
126- # it back one location.
127- position = self ._position
128- else :
129- position = self ._position - 1
130- raise LexerError (
131- lexer_position = position ,
132- lexer_value = '=' ,
133- message = "Unknown token '='" )
118+ yield self ._match_or_else ('=' , 'eq' , 'assign' )
119+ elif self ._current == '$' :
120+ yield self ._consume_variable ()
134121 else :
135122 raise LexerError (lexer_position = self ._position ,
136123 lexer_value = self ._current ,
@@ -145,6 +132,21 @@ def _consume_number(self):
145132 buff += self ._current
146133 return buff
147134
135+ def _consume_variable (self ):
136+ start = self ._position
137+ buff = self ._current
138+ self ._next ()
139+ if self ._current not in self .START_IDENTIFIER :
140+ raise LexerError (
141+ lexer_position = start ,
142+ lexer_value = self ._current ,
143+ message = 'Invalid variable starting character %s' % self ._current )
144+ buff += self ._current
145+ while self ._next () in self .VALID_IDENTIFIER :
146+ buff += self ._current
147+ return {'type' : 'variable' , 'value' : buff ,
148+ 'start' : start , 'end' : start + len (buff )}
149+
148150 def _peek_is_next_digit (self ):
149151 if (self ._position == self ._length - 1 ):
150152 return False
0 commit comments