@eliyah/

Hosting

Nodejs

No description

fork
loading
Files
  • index.js
  • Content
  • plugins
  • package-lock.json
  • skript.3wl
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
const { exec } = require("child_process");
exec("killall node");
var WebSocketServer = require('ws').Server;
var http = require('http');
var fs = require("fs");
var server = http.createServer(function (req, res) {
  var l = true;
  if (fs.existsSync("./Content"+req.url)) {
    if (fs.lstatSync("./Content"+req.url).isFile()) {
      res.write(fs.readFileSync("./Content"+req.url));
      res.end();
      l = false;
    }
  }
  if (l) {
    if (fs.existsSync("./Content/index.html")) {
      res.write(fs.readFileSync("./Content/index.html"));
    } else {
      res.write("404");
    }
    res.end();
  }
}).listen(8080);
wss = new WebSocketServer({
  server
});


var skriptParser = e => {
  var memory = {};
  var keys = {'import':(a)=>{memorySet(a,require("./plugins/"+a))},'var':(a,e,c)=>{memorySet(a,e[0])},'fun':(a,e,c)=>{memorySet(a,JSON.stringify({c:c,a:e}))},'run':(a,e,c)=>{var f = JSON.parse(memoryGet(a));return run(f.c,f.a.map((s,i) => {return {e:s,v:e[i]}}))},'execute':(a,e,c)=>{return memoryGet(a)(e)},'return':(a,e,c)=>{return e}};

  
  var memoryGet = e => {
    var obj = memory;
    for (var o of pathSeparator(e)) {
      obj = obj[o];
    }
    return obj;
  }
  var memorySet = (e,v) => {
    var p = pathSeparator(e);
    var pp = p[0];
    var ppp = p.pop();
    var obj = v;
    for (var i in p) {
      var os = memoryGet(removePath(p.join("."),i));
      os[ppp] = obj;
      obj = os;
      ppp = removePath(p.join("."),i).pop();
    }
    memory[pp] = obj;
  }
  var removePath = (e,v) => {
    var p = pathSeparator(e);
    return p.splice(p.length-v,v);
  }
  var pathSeparator = e => {
    return e.split(".");
  }
  var spaceBeforeCaracter = e => {
    for (var i = 0; i < e.length; i++) {
      var o = e[i];
      if (o != " ") {
        return i;
      }
    }
  }
  var spaceControl = e => {
    var beginIndent = -2;
    for (var o of e) {
      if (spaceBeforeCaracter(o) > beginIndent+2) {
        return false;
      }
      beginIndent = spaceBeforeCaracter(o);
    }
    return true;
  }
  var a = e.split("\n");
  var parseArguments = e => {
    e = e.substr(1,e.length-2);
    var stringToArguments = e => {
      var args = [];
      var bs = "";
      var ina = false;
      for (var i in e) {
        if ((e[i] == '[' || e[i] == ']' || e[i] == '"') && !ina) {
          ina = true;
          bs += e[i];
          continue;
        }
        if (e[i] != "," || ina) {
          bs += e[i];
        }
        if (!ina && e[i] == ",") {
          args.push(bs);
          bs = "";
        }
        if ((e[i] == '[' || e[i] == ']' || e[i] == '"') && ina) {
          ina = false;
        }
      }
      args.push(bs);
      return args;
    }
    var parseArgument = e => {
      if (e[0] == '"') {
        return e.substr(1,e.length-2)
      }
      if (keys[e.split(" ")[0]]) {
        return run(parse([e]));
      }
      return memoryGet(e);
    }
    return stringToArguments(e).map(parseArgument);
  }
  var beginParse = e => {
    var na = [];
    for (o of e) {
      var i = spaceBeforeCaracter(o);
      var o = (""+o).substr(i).split(" ");
      na.push({skript:o.shift(),name:o.shift(),childs:[],indent:i,args:o.join(" ")});
    }
    return na;
  }
  var structurize = e => {
    for (var i = e.length-1; i >= 0; i--) {
      if (e[i].indent > 0) {
        for (var v = i; v >= 0; v--) {
          if (e[v].indent < e[i].indent) {
            e[v].childs.push(e[i]);
            break;
          }
        }
        e.splice(i,1);
      }
    }
    return e;
  }
  var parse = e => {
    if (!spaceControl(e)) {
      return "error"
    }
    e = beginParse(e);
    e = structurize(e);
    return e;
  }
  var runcmd = e => {
    e.args = parseArguments(e.args);
    return keys[e.skript](e.name,e.args,e.childs);
  }
  var run = (e,v=[]) => {
    for (var o of v) {
      memorySet(""+o.e,o.v)
    }
    for (var o of e) {
      var r = runcmd(o);
      if (r) {
        return r;
      }
    }
  };
  return run(parse(a));
}
var result = skriptParser(fs.readFileSync("./skript.3wl").toString());
node v10.16.0