Added dscheme interface for use scheme on Dlang projects

This commit is contained in:
Ernesto Castellotti 2019-05-11 00:15:06 +02:00
parent 30eff2526d
commit 192f909ae6
4 changed files with 794 additions and 777 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

@ -15,17 +15,17 @@ 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";
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 +96,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;
@ -115,7 +115,7 @@ class TLScheme2Json {
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 +127,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 +159,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(";");
@ -215,4 +216,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();
}
}