diff options
author | alyx <alyx@aleteoryx.me> | 2022-06-02 17:53:39 +0000 |
---|---|---|
committer | Aleteoryx <alyx@aleteoryx.me> | 2022-06-02 17:53:39 +0000 |
commit | 721a1f74a47d88d23d868f641bb606316c9e5a58 (patch) | |
tree | 44af4b9dcef984a20f8c242b9b59010bb8c5ae43 /lib | |
parent | c1e64bf0ccdaeb1b676f1a53967b0d0448e1ca44 (diff) | |
download | RRCUtils-721a1f74a47d88d23d868f641bb606316c9e5a58.tar.gz RRCUtils-721a1f74a47d88d23d868f641bb606316c9e5a58.tar.bz2 RRCUtils-721a1f74a47d88d23d868f641bb606316c9e5a58.zip |
homepage, typing, check June 6 changelog
Diffstat (limited to 'lib')
-rw-r--r-- | lib/types.js | 82 |
1 files changed, 80 insertions, 2 deletions
diff --git a/lib/types.js b/lib/types.js index ed83f12..3e37424 100644 --- a/lib/types.js +++ b/lib/types.js @@ -1,4 +1,82 @@ //Gods-awful type-checking logic. -//TypeName: string, Params: Array<string>|Object<string> -function workOutType()
\ No newline at end of file +//TypeName: string, Params: Array<string> +function Type(TypeName,Params=[]) { + this.typename = ""; + this.mode = ""; + //Union/Tuple + if (/^\(.+\)$/.test(TypeName)) { + const types = []; + var depth = 0; + var workspace = ""; + for (const c of /^\((.+)\)$/.exec(TypeName)[1]) { + switch (c) { + case '(': + case '<': + depth++; + break; + case ')': + case '>': + depth--; + break; + case ',': + if (depth == 0) { + this.mode = "tuple"; + types.push(workspace); + workspace = ""; + continue; + } + break; + case '|': + if (depth == 0) { + this.mode = "union"; + types.push(workspace); + workspace = ""; + continue; + } + break; + } + workspace += c; + } + if (workspace) types.push(workspace); + this.template = types.map(t => t.trim()).map(t => ["any", ...Params].includes(t) ? t : new Type(t, Params)); + + } + //Template + else if (/^[^<]+<.+>$/.test(TypeName)) { + this.typename = /^([^<]+)</.exec(TypeName)[1]; + this.mode = "templated"; + const types = []; + var depth = 0; + var workspace = ""; + for (const c of /^[^<]+<(.+)>$/.exec(TypeName)[1]) { + switch (c) { + case '(': + case '<': + depth++; + break; + case ')': + case '>': + depth--; + break; + case ',': + if (depth == 0) { + types.push(workspace); + workspace = ""; + continue; + } + break; + } + workspace += c; + } + if (workspace) types.push(workspace); + this.template = types.map(t => t.trim()).map(t => ["any", ...Params].includes(t) ? t : new Type(t, Params)); + } + //Standard Type + else if (/^[^()|<>,]+$/.test(TypeName)) { + this.typename = TypeName; + this.mode = "standard" + } + + this.params = Object.fromEntries(Params.map(p => [p, 'any'])); +}
\ No newline at end of file |