File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed
Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -112,12 +112,19 @@ def Expression(result):
112112 if operator == "!" :
113113 return lambda scope : list (map (int , map (op .not_ , result [1 ](scope ))))
114114 if isinstance (result [1 ], list ):
115- operator = result [1 ][0 ][0 ]
116- if isinstance (operator , basestring ) and rPostfix .match (operator ):
115+ operators = result [1 ]
116+ start_index = 0
117+ head = False
118+ for wrapped_operator in operators :
119+ operator = wrapped_operator [0 ]
117120 if operator == "[h]" :
118- return lambda scope : [result [0 ](scope )[0 ]]
121+ head = True
122+ break
119123 if operator == "[t]" :
120- return lambda scope : ["" .join (str (x ) for x in result [0 ](scope )[1 :])]
124+ start_index += 1
125+ if head :
126+ return lambda scope : [result [0 ](scope )[start_index ]]
127+ return lambda scope : result [0 ](scope )[start_index :]
121128 # Function call
122129 name = result [0 ]
123130 args = result [1 ]
Original file line number Diff line number Diff line change @@ -22,6 +22,11 @@ def test_not(self):
2222 def test_plus (self ):
2323 self .assertEqual (Run ("1+1" ), [1 , 1 ])
2424 self .assertEqual (Run ("1&1&1&1+1&1&1&1" ), [1 , 1 ])
25+
26+ def test_heads_tails (self ):
27+ self .assertEqual (Run ("100[t][t]" ), [0 ])
28+ self .assertEqual (Run ("100[t]" ), [0 , 0 ])
29+ self .assertEqual (Run ("100[h]" ), [1 ])
2530
2631 def test_parens (self ):
2732 self .assertEqual (Run ("((1))" ), [1 ])
You can’t perform that action at this time.
0 commit comments