{$define NULL_TO_STR} procedure _tostr_py(var s:string); begin // TODO end; var UT_PyList: integer; UT_PyDict: integer; UT_PyREx : integer; UT_PyMatch:integer; function _getType(dt:PScData):integer; begin Result := dt.getType; if(Result = data_code)or(Result = data_array)then Result := dt.getSubType; end; function _toCode(data:PScData; toType:byte):PScData; var ok:boolean; begin Result := data; { ok := false; case toType of data_int: case _getType(data) of data_null: begin Result := MakeData('0', true); ok := true; end; data_str: begin Result := MakeData('long(', true); Result.AddValue(data, true); Result.AddValue(MakeData(')', true), true); ok := true; end; data_real: begin Result := MakeData('long(round(', true); Result.AddValue(data, true); Result.AddValue(MakeData('))', true), true); ok := true; end; end; data_str: case _getType(data) of data_null: begin Result := MakeData(''); ok := true; end; data_int: begin Result := MakeData('str(', true); Result.AddValue(data, true); Result.AddValue(MakeData(')', true), true); ok := true; end; data_real: begin Result := MakeData('str(', true); Result.AddValue(data, true); Result.AddValue(MakeData(')', true), true); ok := true; end; end; data_real: case _getType(data) of data_null: begin Result := MakeData('0.0', true); ok := true; end; data_str: begin Result := MakeData('float(', true); Result.AddValue(data, true); Result.AddValue(MakeData(')', true), true); ok := true; end; end end; if ok then Result.SetSubType(toType); } { Result := data; } { case toType of data_str: case data.getSubType of data_int: begin Result := MakeData(data); Result.AddValue(MakeData('.toString()',true), true); end; end end;} end; procedure _lng_begin_func(parser:TParser; const name:string); var oldb, tmp, old_loc, loc_dt, fname:PScData; s:string; begin oldb := parser.VarList.find('old_block'); tmp := parser.VarList.find('tmp_block'); old_loc := parser.VarList.find('loc_block'); fname := parser.VarList.find('_fname_'); if oldb = nil then oldb := parser.VarList.addArg('old_block'); if tmp = nil then tmp := parser.VarList.addArg('tmp_block'); if old_loc = nil then old_loc := parser.VarList.addArg('loc_block'); if fname = nil then fname := parser.VarList.addArg('_fname_'); fname.setValue(name); loc_dt := GVarList.find('blk_events'); old_loc.setValue(loc_dt.toStr()); loc_dt.SetValue(parser.codeb.reggen(), data_code); s := parser.codeb.reggen(); tmp.SetValue(s); oldb.SetValue(parser.codeb.select(s)); end; procedure _lng_end_func(parser:TParser; const scope:string; glb:string); var loc_dt:PScData; name,b:string; begin loc_dt := GVarList.find('blk_events'); name := parser.VarList.find('_fname_').toStr(); parser.codeb.select(scope); parser.Print('def ' + name + ':'); parser.PrintLine(); parser.codeb.level := parser.codeb.level + 1; parser.Print('global '+glb); parser.PrintLine(); parser.codeb.level := parser.codeb.level - 1; parser.PrintLine(); parser.codeb.select(GVarList.find('blk_func').toStr()); if not parser.codeb.isEmpty(loc_dt.toStr()) then begin //parser.Print('var'); //parser.PrintLine(); parser.codeb.CopyTo(loc_dt.toStr(), parser.codeb.CurBlockName); parser.codeb.delete(loc_dt.toStr()); end; //parser.Print('begin'); //parser.PrintLine(); parser.codeb.level := parser.codeb.level + 1; loc_dt.setValue(parser.VarList.find('loc_block').toStr(), data_code); b := parser.VarList.find('tmp_block').toStr(); parser.codeb.CopyTo(b, parser.codeb.CurBlockName); parser.codeb.delete(b); parser.codeb.level := parser.codeb.level - 1; //parser.Print('End Function'); parser.PrintLine(); parser.PrintLine(); parser.codeb.select(parser.VarList.find('old_block').toStr()); end; type lng_indexer = ( lng_linked, lng_begin_func, lng_end_func, lng_project_name, lng_last); function ReadPointByTypeIndex(parser:TParser; ind:integer; ptype:byte):id_point; forward; const Multi:array[1..4]of byte = (pt_Event,pt_Work,pt_Data,pt_Var); function ExtractFileNameWithoutExt(const AFilename: string): string; var StartPos: Integer; ExtPos: Integer; begin StartPos:=length(AFilename)+1; while (StartPos>1) and (AFilename[StartPos-1]<>'\\') {$IFDEF Windows}and (AFilename[StartPos-1]<>':'){$ENDIF} do dec(StartPos); ExtPos:=length(AFilename); while (ExtPos>=StartPos) and (AFilename[ExtPos]<>'.') do dec(ExtPos); if (ExtPos id_empty then begin e := parser.cgt.ptGetParent(lp); with parser.cgt^ do while elGetClassIndex(e) in [CI_EditMulti, CI_MultiElement] do begin if elGetClassIndex(e) = CI_EditMulti then begin e := elGetSDK(e); if byte(propGetValue(elGetProperty(e, 0))^) = 0 then break; oe := parser.el; parser.el := e; lp := ptGetRLinkPoint(ReadPointByTypeIndex(parser, ptGetIndex(lp), Multi[ptGetType(lp)])); parser.el := oe; end else if elGetClassIndex(e) = CI_MultiElement then begin if byte(propGetValue(elGetProperty(e, 0))^) = 0 then break; oe := parser.el; parser.el := sdkGetElement(elGetSDK(e), 0); lp := ptGetRLinkPoint(ReadPointByTypeIndex(parser, ptGetIndex(lp), Multi[ptGetType(lp)])); parser.el := oe; end; if lp = id_empty then break; e := parser.cgt.ptGetParent(lp); end; Result.SetValue(lp); end; end; lng_begin_func: _lng_begin_func(parser, args.Values[0].toStr()); lng_end_func: _lng_end_func(parser, args.Values[0].toStr(), args.Values[1].toStr()); lng_project_name: begin id_element(pointer(@buf[0])^) := parser.el; parser.cgt.GetParam(PARAM_PROJECT_NAME, @buf[0]); Result.SetValue(ExtractFileNameWithoutExt(buf)); end; end; end; procedure fill_lng_object(var methods:TAObjMethod; var count:integer); begin UT_PyList := RegisterUserType('PyList'); UT_PyDict := RegisterUserType('PyDict'); UT_PyREx := RegisterUserType('PyREx'); UT_PyMatch:= RegisterUserType('PyMatch'); count := integer(lng_last); setlength(methods, count); methods[integer(lng_linked)] := MakeMethod('linked', 1, 'name'); methods[integer(lng_begin_func)] := MakeMethod('begin_func', 1, 'name'); methods[integer(lng_end_func)] := MakeMethod('end_func', 2, 'scope, glb'); methods[integer(lng_project_name)] := MakeMethod('project_name', 0, ''); end; const lng_count = 2; lngs:array[0..lng_count-1] of TLangRec = ( (entry:'EntryPoint'; name:'py'; str_del_o: 'u"'; str_del_c: '"'; op_del: ' + '; var_mask:'%n%i'; tostr_proc:_tostr_py), (entry:'TKRoot'; name:'py'; str_del_o: 'u"'; str_del_c: '"'; op_del: ' + '; var_mask:'%n%i'; tostr_proc:_tostr_py) );