def test_full_macro(self, str): global y cstle_fmacro = CastleFullMacro() cmd_parsr = TokensGenerator() print str, "->" try: tokens = cmd_parsr.full_macro.parseString(str) print "tokens = ", tokens print "tokens.fnc_name =", tokens.macro_name cstle_fmacro.macro_name = tokens.macro_name print "tokens.lines =", tokens.lines # cstle_fmacro.lines.append(tokens.lines) for myline in tokens.lines: if ":" in list(myline): # primitive line primtive_line = PrimitiveCastleCommand() fmacro_line = FullMacroLine() fmacro_line.isMacroCall = False fmacro_line.isPrimitive = True fmacro_line.time_stamp = myline.timestamp primtive_line.LID = myline.localid primtive_line.SID = myline.serviceid param_val_list = list(myline.param_val_grp) for att_i in range(0, len(myline.param_val_grp), 2): new_param = CommandParam() new_param.param_name = param_val_list[att_i] new_param.param_val = param_val_list[att_i + 1] primtive_line.parameters.append(new_param) # fmacro_line.line = PrimitiveCastleCommand() fmacro_line.line = primtive_line cstle_fmacro.lines.append(fmacro_line) elif "(" in list(myline): # macro call macro_call_line = CastleMacroCall() fmacro_line = FullMacroLine() fmacro_line.isMacroCall = True fmacro_line.isPrimitive = False fmacro_line.time_stamp = myline.timestamp macro_call_line.fnc_name = myline.macro_func param_list = list(myline.param_val_grp) for i in range(0, len(param_list), 2): new_param = CommandParam() new_param.param_name = param_list[i] new_param.param_val = param_list[i + 1] macro_call_line.parameters.append(new_param) fmacro_line.line = macro_call_line cstle_fmacro.lines.append(fmacro_line) return (cstle_fmacro, tokens, cmd_parsr) except ParseException, err: print " " * err.loc + "^\n" + err.msg print err return None
def test_primitive(self, str): cstle_cmd = PrimitiveCastleCommand() cmd_parsr = TokensGenerator() print str, "->" try: tokens = cmd_parsr.primitive_cmd.parseString(str) print "tokens = ", tokens print "tokens.localid =", tokens.localid cstle_cmd.LID = tokens.localid print "tokens.serviceid =", tokens.serviceid cstle_cmd.SID = tokens.serviceid for i in range(0, len(tokens.param_val_grp), 2): cstle_cmd.parameters.append((tokens.param_val_grp[i], tokens.param_val_grp[i + 1])) print "tokens.params =", cstle_cmd.parameters print # print "tokens.where =", tokens.where return (cstle_cmd, tokens) except ParseException, err: print " " * err.loc + "^\n" + err.msg print err return None