def testVarOps(self): ev = InitEvaluator() # initializes x=xxx and y=yyy unset_sub = ast.BracedVarSub(ast.token(Id.VSub_Name, 'unset')) part_vals = [] ev._EvalWordPart(unset_sub, part_vals) print(part_vals) set_sub = ast.BracedVarSub(ast.token(Id.VSub_Name, 'x')) part_vals = [] ev._EvalWordPart(set_sub, part_vals) print(part_vals) # Now add some ops part = ast.LiteralPart(ast.token(Id.Lit_Chars, 'default')) arg_word = ast.CompoundWord([part]) test_op = ast.StringUnary(Id.VTest_ColonHyphen, arg_word) unset_sub.suffix_op = test_op set_sub.suffix_op = test_op part_vals = [] ev._EvalWordPart(unset_sub, part_vals) print(part_vals) part_vals = [] ev._EvalWordPart(set_sub, part_vals) print(part_vals)
def testVarOps(self): ev = InitEvaluator() # initializes x=xxx and y=yyy unset_sub = ast.BracedVarSub(ast.token(Id.Lit_Chars, 'unset')) print(ev.EvalVarSub(unset_sub)) set_sub = ast.BracedVarSub(ast.token(Id.Lit_Chars, 'x')) print(ev.EvalVarSub(set_sub)) part = ast.LiteralPart(ast.token(Id.Lit_Chars, 'default')) arg_word = ast.CompoundWord([part]) test_op = ast.StringUnary(Id.VTest_ColonHyphen, arg_word) unset_sub.suffix_op = test_op set_sub.suffix_op = test_op print(ev.EvalVarSub(unset_sub)) print(ev.EvalVarSub(set_sub))
def _ParseVarOf(self): """ VarOf = NAME Subscript? | NUMBER # no subscript allowed, none of these are arrays # ${@[1]} doesn't work, even though slicing does | VarSymbol """ self._Peek() name_token = self.cur_token self._Next(LexMode.VS_2) self._Peek() # Check for [] if self.token_type == Id.VOp2_LBracket: bracket_op = self._ReadSubscript() if not bracket_op: return None else: bracket_op = None part = ast.BracedVarSub(name_token) part.bracket_op = bracket_op return part