@@ -138,7 +138,7 @@ def evaluate(marker, *, env, strict = True, **kwargs):
138138 """
139139 tokens = tokenize (marker )
140140
141- ast = _new_expr (** kwargs )
141+ ast = _new_expr (marker = marker , ** kwargs )
142142 for _ in range (len (tokens ) * 2 ):
143143 if not tokens :
144144 break
@@ -219,17 +219,20 @@ def _not_fn(x):
219219 return not x
220220
221221def _new_expr (
222+ * ,
223+ marker ,
222224 and_fn = _and_fn ,
223225 or_fn = _or_fn ,
224226 not_fn = _not_fn ):
225227 # buildifier: disable=uninitialized
226228 self = struct (
229+ marker = marker ,
227230 tree = [],
228231 parse = lambda ** kwargs : _parse (self , ** kwargs ),
229232 value = lambda : _value (self ),
230233 # This is a way for us to have a handle to the currently constructed
231234 # expression tree branch.
232- current = lambda : self ._current [0 ] if self ._current else None ,
235+ current = lambda : self ._current [- 1 ] if self ._current else None ,
233236 _current = [],
234237 _and = and_fn ,
235238 _or = or_fn ,
@@ -393,12 +396,15 @@ def _append(self, value):
393396 current .tree .append (value )
394397 elif hasattr (current .tree [- 1 ], "append" ):
395398 current .tree [- 1 ].append (value )
396- else :
399+ elif hasattr ( current . tree , "_append" ) :
397400 current .tree ._append (value )
401+ else :
402+ fail ("Cannot evaluate '{}' in '{}', current: {}" .format (value , self .marker , current ))
398403
399404def _open_parenthesis (self ):
400405 """Add an extra node into the tree to perform evaluate inside parenthesis."""
401406 self ._current .append (_new_expr (
407+ marker = self .marker ,
402408 and_fn = self ._and ,
403409 or_fn = self ._or ,
404410 not_fn = self ._not ,
0 commit comments