1
0
mirror of https://github.com/ErnyTech/TLScheme2Json synced 2024-06-17 10:30:06 +02:00

Compare commits

...

4 Commits

Author SHA1 Message Date
8d68279ae0 Update JSON scheme to TDLIB 8ab43e5 2022-10-09 16:54:32 +02:00
2be9a475e9 Update JSON scheme to TDLIB 99163ff 2020-10-02 22:28:00 +02:00
Ernesto Castellotti
7499a41441
Base class name moved to a configurable constant 2019-06-03 23:16:23 +02:00
Ernesto Castellotti
192f909ae6 Added dscheme interface for use scheme on Dlang projects 2019-05-11 00:15:06 +02:00
4 changed files with 15539 additions and 3063 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,12 @@
{ {
"name": "tlscheme2json",
"description": "A TLScheme generator for Json",
"dependencies": {
"asdf": "~>0.4.6"
},
"authors": [ "authors": [
"Ernesto Castellotti" "Ernesto Castellotti"
], ],
"copyright": "Copyright 2019 Ernesto Castellotti <erny.castell@gmail.com>", "copyright": "Copyright 2019 Ernesto Castellotti <erny.castell@gmail.com>",
"dependencies": { "license": "MPL-2.0 with extra appendix"
"asdf": "~>0.4.6" }
},
"description": "A TLScheme generator for Json",
"license": "MPL-2.0 with extra appendix",
"name": "tlscheme2json"
}

View File

@ -11,7 +11,7 @@
*/ */
void main(string[] args) { void main(string[] args) {
import tlscheme2json; import tlscheme2json : TLScheme2Json;
import std.getopt : getopt; import std.getopt : getopt;
import std.getopt : config; import std.getopt : config;
import std.array : empty; import std.array : empty;

View File

@ -13,19 +13,20 @@
module tlscheme2json; module tlscheme2json;
enum DEFAULT_TL_URL = "https://raw.githubusercontent.com/tdlib/td/master/td/generate/scheme/td_api.tl"; enum DEFAULT_TL_URL = "https://raw.githubusercontent.com/tdlib/td/master/td/generate/scheme/td_api.tl";
enum BASECLASS_NAME = "TLBaseClass";
class TLMethod { class TLMethod {
string name; string name = "";
string type; string type = "";
string description; string description = "";
} }
class TLClass { class TLClass {
string name; string name = "";
TLMethod[] methods; TLMethod[] methods;
string description; string description = "";
string inheritance; string inheritance = "";
string return_type; string return_type = "";
bool isFunction; bool isFunction;
bool isSynchronous; bool isSynchronous;
} }
@ -96,12 +97,12 @@ class TLScheme2Json {
return this.classList.serializeToJsonPretty(); return this.classList.serializeToJsonPretty();
} }
void parseType(ref string* lineptr, bool isFunction) { private void parseType(ref string* lineptr, bool isFunction) {
auto tlClass = implParse(lineptr, isFunction); auto tlClass = implParse(lineptr, isFunction);
this.classList ~= tlClass; this.classList ~= tlClass;
} }
void parseClass(string line, bool isFunction) { private void parseClass(string line, bool isFunction) {
import std.array : split; import std.array : split;
import std.array : replace; import std.array : replace;
import std.string : strip; import std.string : strip;
@ -110,12 +111,12 @@ class TLScheme2Json {
auto tlClass = new TLClass(); auto tlClass = new TLClass();
tlClass.name = lineSplit[1].replace("class", "").strip(); tlClass.name = lineSplit[1].replace("class", "").strip();
tlClass.description = lineSplit[2].replace("description", "").strip(); tlClass.description = lineSplit[2].replace("description", "").strip();
tlClass.inheritance = "TLBaseClass"; tlClass.inheritance = BASECLASS_NAME;
tlClass.isFunction = isFunction; tlClass.isFunction = isFunction;
this.classList ~= tlClass; this.classList ~= tlClass;
} }
TLClass implParse(ref string* lineptr, bool isFunction) { private TLClass implParse(ref string* lineptr, bool isFunction) {
import std.array : empty; import std.array : empty;
import std.array : split; import std.array : split;
import std.array : join; import std.array : join;
@ -127,10 +128,10 @@ class TLScheme2Json {
import std.uni : toLower; import std.uni : toLower;
import std.stdio : writeln; import std.stdio : writeln;
string name; string name = "";
string description; string description = "";
string inheritance; string inheritance = "";
string return_type; string return_type = "";
bool isSynchronous = false; bool isSynchronous = false;
TLMethod[] methods; TLMethod[] methods;
@ -159,6 +160,7 @@ class TLScheme2Json {
methods[i] = new TLMethod(); methods[i] = new TLMethod();
methods[i].name = methodProperties[0]; methods[i].name = methodProperties[0];
methods[i].type = methodProperties[1]; methods[i].type = methodProperties[1];
methods[i].description = "";
} }
auto rawreturn = fields[fields.length -1].stripRight(";"); auto rawreturn = fields[fields.length -1].stripRight(";");
@ -176,7 +178,7 @@ class TLScheme2Json {
} }
if(inheritance == null) { if(inheritance == null) {
inheritance = "BaseTLClass"; inheritance = BASECLASS_NAME;
} }
if(isFunction && return_type.empty) { if(isFunction && return_type.empty) {
@ -215,4 +217,20 @@ class TLScheme2Json {
tlClass.isSynchronous = isSynchronous; tlClass.isSynchronous = isSynchronous;
return tlClass; return tlClass;
} }
}
TLClass[] getTLClasses() {
return this.classList;
}
static TLClass[] get() {
auto tlScheme2Json = new TLScheme2Json();
tlScheme2Json.parse();
return tlScheme2Json.getTLClasses();
}
static TLClass[] get(string scheme) {
auto tlScheme2Json = new TLScheme2Json(scheme);
tlScheme2Json.parse();
return tlScheme2Json.getTLClasses();
}
}