@designliquido/delegua 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/.github/CONTRIBUTING.md +0 -0
  2. package/.github/workflows/principal.yml +20 -0
  3. package/.release-it.json +8 -0
  4. package/.vscode/launch.json +2 -2
  5. package/README.md +5 -6
  6. package/bin/delegua +1 -1
  7. package/bin/delegua.cmd +1 -0
  8. package/indice.js +14 -0
  9. package/package.json +46 -37
  10. package/src/ambiente.js +53 -0
  11. package/src/{egua.js → delegua.js} +20 -20
  12. package/src/erro.js +18 -0
  13. package/src/estruturas/callable.js +5 -0
  14. package/src/estruturas/classe.js +43 -0
  15. package/src/estruturas/funcao.js +62 -0
  16. package/src/estruturas/funcaoPadrao.js +18 -0
  17. package/src/estruturas/instancia.js +27 -0
  18. package/src/estruturas/modulo.js +9 -0
  19. package/src/expr.js +52 -52
  20. package/src/interpretador.js +802 -0
  21. package/src/lexer.js +90 -89
  22. package/src/lib/globalLib.js +63 -63
  23. package/src/lib/importStdlib.js +18 -27
  24. package/src/parser.js +219 -223
  25. package/src/resolver.js +93 -93
  26. package/src/stmt.js +34 -34
  27. package/src/{tokenTypes.js → tiposDeSimbolos.js} +21 -21
  28. package/src/web.js +41 -41
  29. package/testes/testes.egua +363 -364
  30. package/index.html +0 -43
  31. package/index.js +0 -14
  32. package/src/environment.js +0 -53
  33. package/src/errors.js +0 -17
  34. package/src/interpreter.js +0 -798
  35. package/src/lib/__tests__/eguamat.test.js +0 -101
  36. package/src/lib/eguamat.js +0 -725
  37. package/src/lib/tempo.js +0 -50
  38. package/src/structures/callable.js +0 -5
  39. package/src/structures/class.js +0 -43
  40. package/src/structures/function.js +0 -62
  41. package/src/structures/instance.js +0 -27
  42. package/src/structures/module.js +0 -9
  43. package/src/structures/standardFn.js +0 -18
package/src/lexer.js CHANGED
@@ -1,38 +1,38 @@
1
- const tokenTypes = require("./tokenTypes.js");
1
+ const tiposDeSimbolos = require("./tiposDeSimbolos.js");
2
2
 
3
3
  const palavrasReservadas = {
4
- e: tokenTypes.E,
5
- em: tokenTypes.EM,
6
- classe: tokenTypes.CLASSE,
7
- senao: tokenTypes.SENAO,
8
- falso: tokenTypes.FALSO,
9
- para: tokenTypes.PARA,
10
- funcao: tokenTypes.FUNCAO,
11
- se: tokenTypes.SE,
12
- senaose: tokenTypes.SENAOSE,
13
- nulo: tokenTypes.NULO,
14
- ou: tokenTypes.OU,
15
- escreva: tokenTypes.ESCREVA,
16
- retorna: tokenTypes.RETORNA,
17
- super: tokenTypes.SUPER,
18
- isto: tokenTypes.ISTO,
19
- verdadeiro: tokenTypes.VERDADEIRO,
20
- var: tokenTypes.VAR,
21
- fazer: tokenTypes.FAZER,
22
- enquanto: tokenTypes.ENQUANTO,
23
- pausa: tokenTypes.PAUSA,
24
- continua: tokenTypes.CONTINUA,
25
- escolha: tokenTypes.ESCOLHA,
26
- caso: tokenTypes.CASO,
27
- padrao: tokenTypes.PADRAO,
28
- importar: tokenTypes.IMPORTAR,
29
- tente: tokenTypes.TENTE,
30
- pegue: tokenTypes.PEGUE,
31
- finalmente: tokenTypes.FINALMENTE,
32
- herda: tokenTypes.HERDA
4
+ e: tiposDeSimbolos.E,
5
+ em: tiposDeSimbolos.EM,
6
+ classe: tiposDeSimbolos.CLASSE,
7
+ senao: tiposDeSimbolos.SENAO,
8
+ falso: tiposDeSimbolos.FALSO,
9
+ para: tiposDeSimbolos.PARA,
10
+ funcao: tiposDeSimbolos.FUNCAO,
11
+ se: tiposDeSimbolos.SE,
12
+ senaose: tiposDeSimbolos.SENAOSE,
13
+ nulo: tiposDeSimbolos.NULO,
14
+ ou: tiposDeSimbolos.OU,
15
+ escreva: tiposDeSimbolos.ESCREVA,
16
+ retorna: tiposDeSimbolos.RETORNA,
17
+ super: tiposDeSimbolos.SUPER,
18
+ isto: tiposDeSimbolos.ISTO,
19
+ verdadeiro: tiposDeSimbolos.VERDADEIRO,
20
+ var: tiposDeSimbolos.VAR,
21
+ fazer: tiposDeSimbolos.FAZER,
22
+ enquanto: tiposDeSimbolos.ENQUANTO,
23
+ pausa: tiposDeSimbolos.PAUSA,
24
+ continua: tiposDeSimbolos.CONTINUA,
25
+ escolha: tiposDeSimbolos.ESCOLHA,
26
+ caso: tiposDeSimbolos.CASO,
27
+ padrao: tiposDeSimbolos.PADRAO,
28
+ importar: tiposDeSimbolos.IMPORTAR,
29
+ tente: tiposDeSimbolos.TENTE,
30
+ pegue: tiposDeSimbolos.PEGUE,
31
+ finalmente: tiposDeSimbolos.FINALMENTE,
32
+ herda: tiposDeSimbolos.HERDA
33
33
  };
34
34
 
35
- class Token {
35
+ class Simbolo {
36
36
  constructor(tipo, lexeme, literal, linha) {
37
37
  this.tipo = tipo;
38
38
  this.lexeme = lexeme;
@@ -52,8 +52,8 @@ class Token {
52
52
  * estruturas, tais como nomes de variáveis, funções, literais, classes e assim por diante.
53
53
  */
54
54
  module.exports = class Lexer {
55
- constructor(codigo, Egua) {
56
- this.Egua = Egua;
55
+ constructor(codigo, Delegua) {
56
+ this.Delegua = Delegua;
57
57
  this.codigo = codigo;
58
58
 
59
59
  this.simbolos = [];
@@ -63,19 +63,19 @@ module.exports = class Lexer {
63
63
  this.linha = 1;
64
64
  }
65
65
 
66
- eDigito(c) {
67
- return c >= "0" && c <= "9";
66
+ eDigito(caractere) {
67
+ return caractere >= "0" && caractere <= "9";
68
68
  }
69
69
 
70
- eAlfabeto(c) {
71
- return (c >= "a" && c <= "z") || (c >= "A" && c <= "Z") || c == "_";
70
+ eAlfabeto(caractere) {
71
+ return (caractere >= "a" && caractere <= "z") || (caractere >= "A" && caractere <= "Z") || caractere == "_";
72
72
  }
73
73
 
74
- eAlfabetoOuDigito(c) {
75
- return this.eDigito(c) || this.eAlfabeto(c);
74
+ eAlfabetoOuDigito(caractere) {
75
+ return this.eDigito(caractere) || this.eAlfabeto(caractere);
76
76
  }
77
77
 
78
- endOfCode() {
78
+ eFinalDoCodigo() {
79
79
  return this.atual >= this.codigo.length;
80
80
  }
81
81
 
@@ -86,11 +86,11 @@ module.exports = class Lexer {
86
86
 
87
87
  adicionarSimbolo(tipo, literal = null) {
88
88
  const texto = this.codigo.substring(this.inicio, this.atual);
89
- this.simbolos.push(new Token(tipo, texto, literal, this.linha));
89
+ this.simbolos.push(new Simbolo(tipo, texto, literal, this.linha));
90
90
  }
91
91
 
92
92
  match(esperado) {
93
- if (this.endOfCode()) {
93
+ if (this.eFinalDoCodigo()) {
94
94
  return false;
95
95
  }
96
96
 
@@ -103,7 +103,7 @@ module.exports = class Lexer {
103
103
  }
104
104
 
105
105
  peek() {
106
- if (this.endOfCode()) return "\0";
106
+ if (this.eFinalDoCodigo()) return "\0";
107
107
  return this.codigo.charAt(this.atual);
108
108
  }
109
109
 
@@ -116,14 +116,14 @@ module.exports = class Lexer {
116
116
  return this.codigo.charAt(this.atual - 1);
117
117
  }
118
118
 
119
- analisarTexto(stringChar = '"') {
120
- while (this.peek() !== stringChar && !this.endOfCode()) {
119
+ analisarTexto(texto = '"') {
120
+ while (this.peek() !== texto && !this.eFinalDoCodigo()) {
121
121
  if (this.peek() === "\n") this.linha = +1;
122
122
  this.avancar();
123
123
  }
124
124
 
125
- if (this.endOfCode()) {
126
- this.Egua.lexerError(
125
+ if (this.eFinalDoCodigo()) {
126
+ this.Delegua.lexerError(
127
127
  this.linha,
128
128
  this.voltar(),
129
129
  "Texto não finalizado."
@@ -134,7 +134,7 @@ module.exports = class Lexer {
134
134
  this.avancar();
135
135
 
136
136
  const valor = this.codigo.substring(this.inicio + 1, this.atual - 1);
137
- this.adicionarSimbolo(tokenTypes.STRING, valor);
137
+ this.adicionarSimbolo(tiposDeSimbolos.TEXTO, valor);
138
138
  }
139
139
 
140
140
  analisarNumero() {
@@ -151,7 +151,7 @@ module.exports = class Lexer {
151
151
  }
152
152
 
153
153
  const numeroCompleto = this.codigo.substring(this.inicio, this.atual);
154
- this.adicionarSimbolo(tokenTypes.NUMBER, parseFloat(numeroCompleto));
154
+ this.adicionarSimbolo(tiposDeSimbolos.NUMERO, parseFloat(numeroCompleto));
155
155
  }
156
156
 
157
157
  identificarPalavraChave() {
@@ -159,121 +159,121 @@ module.exports = class Lexer {
159
159
  this.avancar();
160
160
  }
161
161
 
162
- const c = this.codigo.substring(this.inicio, this.atual);
163
- const tipo = c in palavrasReservadas ? palavrasReservadas[c] : tokenTypes.IDENTIFIER;
162
+ const codigo = this.codigo.substring(this.inicio, this.atual);
163
+ const tipo = codigo in palavrasReservadas ? palavrasReservadas[codigo] : tiposDeSimbolos.IDENTIFICADOR;
164
164
 
165
165
  this.adicionarSimbolo(tipo);
166
166
  }
167
167
 
168
168
  scanToken() {
169
- const char = this.avancar();
169
+ const caractere = this.avancar();
170
170
 
171
- switch (char) {
171
+ switch (caractere) {
172
172
  case "[":
173
- this.adicionarSimbolo(tokenTypes.LEFT_SQUARE_BRACKET);
173
+ this.adicionarSimbolo(tiposDeSimbolos.COLCHETE_ESQUERDO);
174
174
  break;
175
175
  case "]":
176
- this.adicionarSimbolo(tokenTypes.RIGHT_SQUARE_BRACKET);
176
+ this.adicionarSimbolo(tiposDeSimbolos.COLCHETE_DIREITO);
177
177
  break;
178
178
  case "(":
179
- this.adicionarSimbolo(tokenTypes.LEFT_PAREN);
179
+ this.adicionarSimbolo(tiposDeSimbolos.PARENTESE_ESQUERDO);
180
180
  break;
181
181
  case ")":
182
- this.adicionarSimbolo(tokenTypes.RIGHT_PAREN);
182
+ this.adicionarSimbolo(tiposDeSimbolos.PARENTESE_DIREITO);
183
183
  break;
184
184
  case "{":
185
- this.adicionarSimbolo(tokenTypes.LEFT_BRACE);
185
+ this.adicionarSimbolo(tiposDeSimbolos.CHAVE_ESQUERDA);
186
186
  break;
187
187
  case "}":
188
- this.adicionarSimbolo(tokenTypes.RIGHT_BRACE);
188
+ this.adicionarSimbolo(tiposDeSimbolos.CHAVE_DIREITA);
189
189
  break;
190
190
  case ",":
191
- this.adicionarSimbolo(tokenTypes.COMMA);
191
+ this.adicionarSimbolo(tiposDeSimbolos.COMMA);
192
192
  break;
193
193
  case ".":
194
- this.adicionarSimbolo(tokenTypes.DOT);
194
+ this.adicionarSimbolo(tiposDeSimbolos.DOT);
195
195
  break;
196
196
  case "-":
197
197
  if (this.match("=")) {
198
- this.adicionarSimbolo(tokenTypes.MENOR_IGUAL);
198
+ this.adicionarSimbolo(tiposDeSimbolos.MENOR_IGUAL);
199
199
  }
200
- this.adicionarSimbolo(tokenTypes.MINUS);
200
+ this.adicionarSimbolo(tiposDeSimbolos.SUBTRACAO);
201
201
  break;
202
202
  case "+":
203
203
  if (this.match("=")) {
204
- this.adicionarSimbolo(tokenTypes.MAIS_IGUAL);
204
+ this.adicionarSimbolo(tiposDeSimbolos.MAIS_IGUAL);
205
205
  }
206
- this.adicionarSimbolo(tokenTypes.PLUS);
206
+ this.adicionarSimbolo(tiposDeSimbolos.ADICAO);
207
207
  break;
208
208
  case ":":
209
- this.adicionarSimbolo(tokenTypes.COLON);
209
+ this.adicionarSimbolo(tiposDeSimbolos.COLON);
210
210
  break;
211
211
  case ";":
212
- this.adicionarSimbolo(tokenTypes.SEMICOLON);
212
+ this.adicionarSimbolo(tiposDeSimbolos.SEMICOLON);
213
213
  break;
214
214
  case "%":
215
- this.adicionarSimbolo(tokenTypes.MODULUS);
215
+ this.adicionarSimbolo(tiposDeSimbolos.MODULUS);
216
216
  break;
217
217
  case "*":
218
218
  if (this.peek() === "*") {
219
219
  this.avancar();
220
- this.adicionarSimbolo(tokenTypes.STAR_STAR);
220
+ this.adicionarSimbolo(tiposDeSimbolos.STAR_STAR);
221
221
  break;
222
222
  }
223
- this.adicionarSimbolo(tokenTypes.STAR);
223
+ this.adicionarSimbolo(tiposDeSimbolos.STAR);
224
224
  break;
225
225
  case "!":
226
226
  this.adicionarSimbolo(
227
- this.match("=") ? tokenTypes.BANG_EQUAL : tokenTypes.BANG
227
+ this.match("=") ? tiposDeSimbolos.DIFERENTE : tiposDeSimbolos.NEGACAO
228
228
  );
229
229
  break;
230
230
  case "=":
231
231
  this.adicionarSimbolo(
232
- this.match("=") ? tokenTypes.EQUAL_EQUAL : tokenTypes.EQUAL
232
+ this.match("=") ? tiposDeSimbolos.IGUAL_IGUAL : tiposDeSimbolos.IGUAL
233
233
  );
234
234
  break;
235
235
 
236
236
  case "&":
237
- this.adicionarSimbolo(tokenTypes.BIT_AND);
237
+ this.adicionarSimbolo(tiposDeSimbolos.BIT_AND);
238
238
  break;
239
239
 
240
240
  case "~":
241
- this.adicionarSimbolo(tokenTypes.BIT_NOT);
241
+ this.adicionarSimbolo(tiposDeSimbolos.BIT_NOT);
242
242
  break;
243
243
 
244
244
  case "|":
245
- this.adicionarSimbolo(tokenTypes.BIT_OR);
245
+ this.adicionarSimbolo(tiposDeSimbolos.BIT_OR);
246
246
  break;
247
247
 
248
248
  case "^":
249
- this.adicionarSimbolo(tokenTypes.BIT_XOR);
249
+ this.adicionarSimbolo(tiposDeSimbolos.BIT_XOR);
250
250
  break;
251
251
 
252
252
  case "<":
253
253
  if (this.match("=")) {
254
- this.adicionarSimbolo(tokenTypes.LESS_EQUAL);
254
+ this.adicionarSimbolo(tiposDeSimbolos.MENOR_IGUAL);
255
255
  } else if (this.match("<")) {
256
- this.adicionarSimbolo(tokenTypes.LESSER_LESSER);
256
+ this.adicionarSimbolo(tiposDeSimbolos.MENOR_MENOR);
257
257
  } else {
258
- this.adicionarSimbolo(tokenTypes.LESS);
258
+ this.adicionarSimbolo(tiposDeSimbolos.MENOR);
259
259
  }
260
260
  break;
261
261
 
262
262
  case ">":
263
263
  if (this.match("=")) {
264
- this.adicionarSimbolo(tokenTypes.GREATER_EQUAL);
264
+ this.adicionarSimbolo(tiposDeSimbolos.MAIOR_IGUAL);
265
265
  } else if (this.match(">")) {
266
- this.adicionarSimbolo(tokenTypes.GREATER_GREATER);
266
+ this.adicionarSimbolo(tiposDeSimbolos.MAIOR_MAIOR);
267
267
  } else {
268
- this.adicionarSimbolo(tokenTypes.GREATER);
268
+ this.adicionarSimbolo(tiposDeSimbolos.MAIOR);
269
269
  }
270
270
  break;
271
271
 
272
272
  case "/":
273
273
  if (this.match("/")) {
274
- while (this.peek() != "\n" && !this.endOfCode()) this.avancar();
274
+ while (this.peek() != "\n" && !this.eFinalDoCodigo()) this.avancar();
275
275
  } else {
276
- this.adicionarSimbolo(tokenTypes.SLASH);
276
+ this.adicionarSimbolo(tiposDeSimbolos.SLASH);
277
277
  }
278
278
  break;
279
279
 
@@ -297,19 +297,20 @@ module.exports = class Lexer {
297
297
  break;
298
298
 
299
299
  default:
300
- if (this.eDigito(char)) this.analisarNumero();
301
- else if (this.eAlfabeto(char)) this.identificarPalavraChave();
302
- else this.Egua.lexerError(this.linha, char, "Caractere inesperado.");
300
+ if (this.eDigito(caractere)) this.analisarNumero();
301
+ else if (this.eAlfabeto(caractere)) this.identificarPalavraChave();
302
+ else this.Delegua.lexerError(this.linha, caractere, "Caractere inesperado.");
303
303
  }
304
304
  }
305
305
 
306
306
  scan() {
307
- while (!this.endOfCode()) {
307
+ while (!this.eFinalDoCodigo()) {
308
308
  this.inicio = this.atual;
309
309
  this.scanToken();
310
310
  }
311
311
 
312
- this.simbolos.push(new Token(tokenTypes.EOF, "", null, this.linha));
312
+ this.simbolos.push(new Simbolo(tiposDeSimbolos.EOF, "", null, this.linha));
313
+
313
314
  return this.simbolos;
314
315
  }
315
316
  };
@@ -1,27 +1,27 @@
1
- const RuntimeError = require("../errors.js").RuntimeError,
2
- EguaFunction = require("../structures/function.js"),
3
- EguaInstance = require("../structures/instance.js"),
4
- StandardFn = require("../structures/standardFn.js"),
5
- EguaClass = require("../structures/class.js");
1
+ const ErroEmTempoDeExecucao = require("../erro.js").ErroEmTempoDeExecucao,
2
+ DeleguaFuncao = require("../estruturas/funcao.js"),
3
+ DeleguaInstancia = require("../estruturas/instancia.js"),
4
+ FuncaoPadrao = require("../estruturas/funcaoPadrao.js"),
5
+ DeleguaClasse = require("../estruturas/classe.js");
6
6
 
7
7
 
8
- module.exports = function (interpreter, globals) {
8
+ module.exports = function (interpretador, globals) {
9
9
  // Retorna um número aleatório entre 0 e 1.
10
- globals.defineVar(
10
+ globals.definirVariavel(
11
11
  "aleatorio",
12
- new StandardFn(1, function () {
12
+ new FuncaoPadrao(1, function () {
13
13
  return Math.random();
14
14
  })
15
15
  );
16
16
 
17
17
  // Retorna um número aleatório de acordo com o parâmetro passado.
18
18
  // MIN(inclusivo) - MAX(exclusivo)
19
- globals.defineVar(
19
+ globals.definirVariavel(
20
20
  "aleatorioEntre",
21
- new StandardFn(1, function (min, max) {
21
+ new FuncaoPadrao(1, function (min, max) {
22
22
  if (typeof min !== 'number' || typeof max !== 'number') {
23
- throw new RuntimeError(
24
- this.token,
23
+ throw new ErroEmTempoDeExecucao(
24
+ this.simbolo,
25
25
  "Os dois parâmetros devem ser do tipo número."
26
26
  );
27
27
  }
@@ -30,49 +30,49 @@ module.exports = function (interpreter, globals) {
30
30
  })
31
31
  );
32
32
 
33
- globals.defineVar(
33
+ globals.definirVariavel(
34
34
  "inteiro",
35
- new StandardFn(1, function (value) {
36
- if (value === undefined || value === null) {
37
- throw new RuntimeError(
38
- this.token,
35
+ new FuncaoPadrao(1, function (valor) {
36
+ if (valor === undefined || valor === null) {
37
+ throw new ErroEmTempoDeExecucao(
38
+ this.simbolo,
39
39
  "Somente números podem passar para inteiro."
40
40
  );
41
41
  }
42
42
 
43
- if (!/^-{0,1}\d+$/.test(value) && !/^\d+\.\d+$/.test(value)) {
44
- throw new RuntimeError(
45
- this.token,
43
+ if (!/^-{0,1}\d+$/.test(valor) && !/^\d+\.\d+$/.test(valor)) {
44
+ throw new ErroEmTempoDeExecucao(
45
+ this.simbolo,
46
46
  "Somente números podem passar para inteiro."
47
47
  );
48
48
  }
49
49
 
50
- return parseInt(value);
50
+ return parseInt(valor);
51
51
  })
52
52
  );
53
53
 
54
- globals.defineVar(
54
+ globals.definirVariavel(
55
55
  "mapear",
56
- new StandardFn(1, function (array, callback) {
56
+ new FuncaoPadrao(1, function (array, callback) {
57
57
  if (!Array.isArray(array)) {
58
- throw new RuntimeError(
59
- this.token,
58
+ throw new ErroEmTempoDeExecucao(
59
+ this.simbolo,
60
60
  "Parâmetro inválido. O primeiro parâmetro da função, deve ser um array."
61
61
  );
62
62
  }
63
63
 
64
- if (callback.constructor.name !== 'EguaFunction') {
65
- throw new RuntimeError(
66
- this.token,
64
+ if (callback.constructor.nome !== 'DeleguaFuncao') {
65
+ throw new ErroEmTempoDeExecucao(
66
+ this.simbolo,
67
67
  "Parâmetro inválido. O segundo parâmetro da função, deve ser uma função."
68
68
  );
69
69
  }
70
70
 
71
71
  let provisorio = [];
72
- for (let index = 0; index < array.length; ++index) {
72
+ for (let indice = 0; indice < array.length; ++indice) {
73
73
  provisorio.push(
74
74
  callback.call(
75
- interpreter, [array[index]]
75
+ interpretador, [array[indice]]
76
76
  )
77
77
  );
78
78
  }
@@ -81,12 +81,12 @@ module.exports = function (interpreter, globals) {
81
81
  })
82
82
  );
83
83
 
84
- globals.defineVar(
84
+ globals.definirVariavel(
85
85
  "ordenar",
86
- new StandardFn(1, function (obj) {
86
+ new FuncaoPadrao(1, function (obj) {
87
87
  if (Array.isArray(obj) == false) {
88
- throw new RuntimeError(
89
- this.token,
88
+ throw new ErroEmTempoDeExecucao(
89
+ this.simbolo,
90
90
  "Valor Inválido. Objeto inserido não é um vetor."
91
91
  );
92
92
  }
@@ -106,66 +106,66 @@ module.exports = function (interpreter, globals) {
106
106
  })
107
107
  );
108
108
 
109
- globals.defineVar(
109
+ globals.definirVariavel(
110
110
  "real",
111
- new StandardFn(1, function (value) {
112
- if (!/^-{0,1}\d+$/.test(value) && !/^\d+\.\d+$/.test(value))
113
- throw new RuntimeError(
114
- this.token,
111
+ new FuncaoPadrao(1, function (valor) {
112
+ if (!/^-{0,1}\d+$/.test(valor) && !/^\d+\.\d+$/.test(valor))
113
+ throw new ErroEmTempoDeExecucao(
114
+ this.simbolo,
115
115
  "Somente números podem passar para real."
116
116
  );
117
- return parseFloat(value);
117
+ return parseFloat(valor);
118
118
  })
119
119
  );
120
120
 
121
- globals.defineVar(
121
+ globals.definirVariavel(
122
122
  "tamanho",
123
- new StandardFn(1, function (obj) {
124
- if (!isNaN(obj)) {
125
- throw new RuntimeError(
126
- this.token,
123
+ new FuncaoPadrao(1, function (objeto) {
124
+ if (!isNaN(objeto)) {
125
+ throw new ErroEmTempoDeExecucao(
126
+ this.simbolo,
127
127
  "Não é possível encontrar o tamanho de um número."
128
128
  );
129
129
  }
130
130
 
131
- if (obj instanceof EguaInstance) {
132
- throw new RuntimeError(
133
- this.token,
131
+ if (objeto instanceof DeleguaInstancia) {
132
+ throw new ErroEmTempoDeExecucao(
133
+ this.simbolo,
134
134
  "Você não pode encontrar o tamanho de uma declaração."
135
135
  );
136
136
  }
137
137
 
138
- if (obj instanceof EguaFunction) {
139
- return obj.declaration.params.length;
138
+ if (objeto instanceof DeleguaFuncao) {
139
+ return objeto.declaracao.parametros.length;
140
140
  }
141
141
 
142
- if (obj instanceof StandardFn) {
143
- return obj.arityValue;
142
+ if (objeto instanceof FuncaoPadrao) {
143
+ return objeto.valorAridade;
144
144
  }
145
145
 
146
- if (obj instanceof EguaClass) {
147
- let methods = obj.methods;
148
- let length = 0;
146
+ if (objeto instanceof DeleguaClasse) {
147
+ let metodos = objeto.metodos;
148
+ let tamanho = 0;
149
149
 
150
- if (methods.init && methods.init.isInitializer) {
151
- length = methods.init.declaration.params.length;
150
+ if (metodos.init && metodos.init.eInicializador) {
151
+ tamanho = metodos.init.declaracao.parametros.length;
152
152
  }
153
153
 
154
- return length;
154
+ return tamanho;
155
155
  }
156
156
 
157
- return obj.length;
157
+ return objeto.length;
158
158
  })
159
159
  );
160
160
 
161
- globals.defineVar(
161
+ globals.definirVariavel(
162
162
  "texto",
163
- new StandardFn(1, function (value) {
164
- return `${value}`;
163
+ new FuncaoPadrao(1, function (valor) {
164
+ return `${valor}`;
165
165
  })
166
166
  );
167
167
 
168
- globals.defineVar("exports", {});
168
+ globals.definirVariavel("exports", {});
169
169
 
170
170
  return globals;
171
171
  };
@@ -1,41 +1,32 @@
1
- const RuntimeError = require("../errors.js").RuntimeError,
2
- StandardFn = require("../structures/standardFn.js"),
3
- EguaModule = require("../structures/module.js");
1
+ const ErroEmTempoDeExecucao = require("../erro.js").ErroEmTempoDeExecucao,
2
+ FuncaoPadrao = require("../estruturas/funcaoPadrao.js"),
3
+ DeleguaModulo = require("../estruturas/modulo.js");
4
4
 
5
- const loadModule = function (moduleName, modulePath) {
6
- let moduleData;
5
+ const carregarModulo = function (nomeDoModulo, caminhoDoModulo) {
6
+ let dadosDoModulo;
7
7
  try {
8
- moduleData = require(modulePath);
8
+ dadosDoModulo = require(caminhoDoModulo);
9
9
  } catch (erro) {
10
- throw new RuntimeError(moduleName, `Biblioteca ${moduleName} não encontrada para importação.`);
10
+ throw new ErroEmTempoDeExecucao(nomeDoModulo, `Biblioteca ${nomeDoModulo} não encontrada para importação.`);
11
11
  }
12
12
 
13
- let newModule = new EguaModule(moduleName);
13
+ let novoModulo = new DeleguaModulo(nomeDoModulo);
14
14
 
15
- let keys = Object.keys(moduleData);
16
- for (let i = 0; i < keys.length; i++) {
17
- let currentItem = moduleData[keys[i]];
15
+ let chaves = Object.keys(dadosDoModulo);
16
+ for (let i = 0; i < chaves.length; i++) {
17
+ const moduloAtual = dadosDoModulo[chaves[i]];
18
18
 
19
- if (typeof currentItem === "function") {
20
- newModule[keys[i]] = new StandardFn(currentItem.length, currentItem);
19
+ if (typeof moduloAtual === "function") {
20
+ novoModulo[chaves[i]] = new FuncaoPadrao(moduloAtual.length, moduloAtual);
21
21
  } else {
22
- newModule[keys[i]] = currentItem;
22
+ novoModulo[chaves[i]] = moduloAtual;
23
23
  }
24
24
  }
25
25
 
26
- return newModule;
26
+ return novoModulo;
27
27
  };
28
28
 
29
- require("./tempo.js");
30
- require("./eguamat.js");
31
-
32
- module.exports = function (name) {
33
- switch (name) {
34
- case "tempo":
35
- return loadModule("tempo", "./tempo.js");
36
- case "eguamat":
37
- return loadModule("eguamat", "./eguamat.js");
38
- default:
39
- return loadModule(name, name);
40
- }
29
+ module.exports = function (nome) {
30
+ //TODO:Samuel: Precisa testar ainda.
31
+ return carregarModulo(nome, nome);
41
32
  };