From 721a1f74a47d88d23d868f641bb606316c9e5a58 Mon Sep 17 00:00:00 2001 From: alyx Date: Thu, 2 Jun 2022 17:53:39 +0000 Subject: homepage, typing, check June 6 changelog --- lib/types.js | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 2 deletions(-) (limited to 'lib') 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|Object -function workOutType() \ No newline at end of file +//TypeName: string, Params: Array +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]) { + 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 -- cgit v1.2.3-54-g00ecf