@designliquido/delegua 0.0.1 → 0.1.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 (153) hide show
  1. package/README.md +14 -7
  2. package/bin/delegua.cmd +1 -0
  3. package/bin/package.json +51 -0
  4. package/index.js +25 -12
  5. package/index.js.map +1 -0
  6. package/package.json +51 -37
  7. package/src/ambiente.js +49 -0
  8. package/src/ambiente.js.map +1 -0
  9. package/src/avaliador-sintatico/dialetos/egua-classico.js +635 -0
  10. package/src/avaliador-sintatico/dialetos/egua-classico.js.map +1 -0
  11. package/src/avaliador-sintatico/dialetos/index.js +14 -0
  12. package/src/avaliador-sintatico/dialetos/index.js.map +1 -0
  13. package/src/avaliador-sintatico/index.js +635 -0
  14. package/src/avaliador-sintatico/index.js.map +1 -0
  15. package/src/avaliador-sintatico/parser-error.js +27 -0
  16. package/src/avaliador-sintatico/parser-error.js.map +1 -0
  17. package/src/bibliotecas/bibliotecaGlobal.js +97 -0
  18. package/src/bibliotecas/bibliotecaGlobal.js.map +1 -0
  19. package/src/bibliotecas/importarBiblioteca.js +32 -0
  20. package/src/bibliotecas/importarBiblioteca.js.map +1 -0
  21. package/src/construtos/assign-subscript.js +35 -0
  22. package/src/construtos/assign-subscript.js.map +1 -0
  23. package/src/construtos/atribuir.js +34 -0
  24. package/src/construtos/atribuir.js.map +1 -0
  25. package/src/construtos/binario.js +35 -0
  26. package/src/construtos/binario.js.map +1 -0
  27. package/src/construtos/call.js +35 -0
  28. package/src/construtos/call.js.map +1 -0
  29. package/src/construtos/conjunto.js +35 -0
  30. package/src/construtos/conjunto.js.map +1 -0
  31. package/src/construtos/dicionario.js +34 -0
  32. package/src/construtos/dicionario.js.map +1 -0
  33. package/src/construtos/expr.js +11 -0
  34. package/src/construtos/expr.js.map +1 -0
  35. package/src/construtos/funcao.js +34 -0
  36. package/src/construtos/funcao.js.map +1 -0
  37. package/src/construtos/get.js +34 -0
  38. package/src/construtos/get.js.map +1 -0
  39. package/src/construtos/grouping.js +33 -0
  40. package/src/construtos/grouping.js.map +1 -0
  41. package/src/construtos/index.js +31 -0
  42. package/src/construtos/index.js.map +1 -0
  43. package/src/construtos/isto.js +33 -0
  44. package/src/construtos/isto.js.map +1 -0
  45. package/src/construtos/literal.js +33 -0
  46. package/src/construtos/literal.js.map +1 -0
  47. package/src/construtos/logical.js +35 -0
  48. package/src/construtos/logical.js.map +1 -0
  49. package/src/construtos/subscript.js +35 -0
  50. package/src/construtos/subscript.js.map +1 -0
  51. package/src/construtos/super.js +34 -0
  52. package/src/construtos/super.js.map +1 -0
  53. package/src/construtos/unario.js +34 -0
  54. package/src/construtos/unario.js.map +1 -0
  55. package/src/construtos/variavel.js +33 -0
  56. package/src/construtos/variavel.js.map +1 -0
  57. package/src/construtos/vetor.js +33 -0
  58. package/src/construtos/vetor.js.map +1 -0
  59. package/src/declaracoes/index.js +249 -0
  60. package/src/declaracoes/index.js.map +1 -0
  61. package/src/delegua.js +132 -0
  62. package/src/delegua.js.map +1 -0
  63. package/src/estruturas/callable.js +16 -0
  64. package/src/estruturas/callable.js.map +1 -0
  65. package/src/estruturas/classe.js +57 -0
  66. package/src/estruturas/classe.js.map +1 -0
  67. package/src/estruturas/funcao-padrao.js +38 -0
  68. package/src/estruturas/funcao-padrao.js.map +1 -0
  69. package/src/estruturas/funcao.js +81 -0
  70. package/src/estruturas/funcao.js.map +1 -0
  71. package/src/estruturas/index.js +19 -0
  72. package/src/estruturas/index.js.map +1 -0
  73. package/src/estruturas/instancia.js +28 -0
  74. package/src/estruturas/instancia.js.map +1 -0
  75. package/src/estruturas/modulo.js +15 -0
  76. package/src/estruturas/modulo.js.map +1 -0
  77. package/src/excecoes/break-exception.js +27 -0
  78. package/src/excecoes/break-exception.js.map +1 -0
  79. package/src/excecoes/continue-exception.js +27 -0
  80. package/src/excecoes/continue-exception.js.map +1 -0
  81. package/src/excecoes/erro-em-tempo-de-execucao.js +31 -0
  82. package/src/excecoes/erro-em-tempo-de-execucao.js.map +1 -0
  83. package/src/excecoes/index.js +17 -0
  84. package/src/excecoes/index.js.map +1 -0
  85. package/src/excecoes/return-exception.js +30 -0
  86. package/src/excecoes/return-exception.js.map +1 -0
  87. package/src/interfaces/avaliador-sintatico-interface.js +3 -0
  88. package/src/interfaces/avaliador-sintatico-interface.js.map +1 -0
  89. package/src/interfaces/index.js +19 -0
  90. package/src/interfaces/index.js.map +1 -0
  91. package/src/interfaces/interpretador-interface.js +3 -0
  92. package/src/interfaces/interpretador-interface.js.map +1 -0
  93. package/src/interfaces/lexador-interface.js +3 -0
  94. package/src/interfaces/lexador-interface.js.map +1 -0
  95. package/src/interfaces/pilha-interface.js +3 -0
  96. package/src/interfaces/pilha-interface.js.map +1 -0
  97. package/src/interfaces/resolvedor-interface.js +3 -0
  98. package/src/interfaces/resolvedor-interface.js.map +1 -0
  99. package/src/interfaces/simbolo-interface.js +3 -0
  100. package/src/interfaces/simbolo-interface.js.map +1 -0
  101. package/src/interpretador/dialetos/egua-classico.js +665 -0
  102. package/src/interpretador/dialetos/egua-classico.js.map +1 -0
  103. package/src/interpretador/dialetos/index.js +14 -0
  104. package/src/interpretador/dialetos/index.js.map +1 -0
  105. package/src/interpretador/index.js +665 -0
  106. package/src/interpretador/index.js.map +1 -0
  107. package/src/lexador/dialetos/egua-classico.js +287 -0
  108. package/src/lexador/dialetos/egua-classico.js.map +1 -0
  109. package/src/lexador/dialetos/index.js +14 -0
  110. package/src/lexador/dialetos/index.js.map +1 -0
  111. package/src/lexador/index.js +287 -0
  112. package/src/lexador/index.js.map +1 -0
  113. package/src/resolvedor/Pilha.js +27 -0
  114. package/src/resolvedor/Pilha.js.map +1 -0
  115. package/src/resolvedor/ResolverError.js +29 -0
  116. package/src/resolvedor/ResolverError.js.map +1 -0
  117. package/src/resolvedor/dialetos/egua-classico.js +331 -0
  118. package/src/resolvedor/dialetos/egua-classico.js.map +1 -0
  119. package/src/resolvedor/dialetos/index.js +14 -0
  120. package/src/resolvedor/dialetos/index.js.map +1 -0
  121. package/src/resolvedor/index.js +331 -0
  122. package/src/resolvedor/index.js.map +1 -0
  123. package/src/tiposDeSimbolos.js +69 -0
  124. package/src/tiposDeSimbolos.js.map +1 -0
  125. package/src/web.js +65 -69
  126. package/src/web.js.map +1 -0
  127. package/.vscode/launch.json +0 -29
  128. package/.vscode/settings.json +0 -3
  129. package/LICENSE +0 -21
  130. package/babel.config.js +0 -1
  131. package/index.html +0 -43
  132. package/src/egua.js +0 -102
  133. package/src/environment.js +0 -53
  134. package/src/errors.js +0 -17
  135. package/src/expr.js +0 -228
  136. package/src/interpreter.js +0 -798
  137. package/src/lexer.js +0 -315
  138. package/src/lib/__tests__/eguamat.test.js +0 -101
  139. package/src/lib/eguamat.js +0 -725
  140. package/src/lib/globalLib.js +0 -171
  141. package/src/lib/importStdlib.js +0 -41
  142. package/src/lib/tempo.js +0 -50
  143. package/src/parser.js +0 -826
  144. package/src/resolver.js +0 -425
  145. package/src/stmt.js +0 -215
  146. package/src/structures/callable.js +0 -5
  147. package/src/structures/class.js +0 -43
  148. package/src/structures/function.js +0 -62
  149. package/src/structures/instance.js +0 -27
  150. package/src/structures/module.js +0 -9
  151. package/src/structures/standardFn.js +0 -18
  152. package/src/tokenTypes.js +0 -67
  153. package/testes/testes.egua +0 -631
@@ -1,171 +0,0 @@
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");
6
-
7
-
8
- module.exports = function (interpreter, globals) {
9
- // Retorna um número aleatório entre 0 e 1.
10
- globals.defineVar(
11
- "aleatorio",
12
- new StandardFn(1, function () {
13
- return Math.random();
14
- })
15
- );
16
-
17
- // Retorna um número aleatório de acordo com o parâmetro passado.
18
- // MIN(inclusivo) - MAX(exclusivo)
19
- globals.defineVar(
20
- "aleatorioEntre",
21
- new StandardFn(1, function (min, max) {
22
- if (typeof min !== 'number' || typeof max !== 'number') {
23
- throw new RuntimeError(
24
- this.token,
25
- "Os dois parâmetros devem ser do tipo número."
26
- );
27
- }
28
-
29
- return Math.floor(Math.random() * (max - min)) + min;
30
- })
31
- );
32
-
33
- globals.defineVar(
34
- "inteiro",
35
- new StandardFn(1, function (value) {
36
- if (value === undefined || value === null) {
37
- throw new RuntimeError(
38
- this.token,
39
- "Somente números podem passar para inteiro."
40
- );
41
- }
42
-
43
- if (!/^-{0,1}\d+$/.test(value) && !/^\d+\.\d+$/.test(value)) {
44
- throw new RuntimeError(
45
- this.token,
46
- "Somente números podem passar para inteiro."
47
- );
48
- }
49
-
50
- return parseInt(value);
51
- })
52
- );
53
-
54
- globals.defineVar(
55
- "mapear",
56
- new StandardFn(1, function (array, callback) {
57
- if (!Array.isArray(array)) {
58
- throw new RuntimeError(
59
- this.token,
60
- "Parâmetro inválido. O primeiro parâmetro da função, deve ser um array."
61
- );
62
- }
63
-
64
- if (callback.constructor.name !== 'EguaFunction') {
65
- throw new RuntimeError(
66
- this.token,
67
- "Parâmetro inválido. O segundo parâmetro da função, deve ser uma função."
68
- );
69
- }
70
-
71
- let provisorio = [];
72
- for (let index = 0; index < array.length; ++index) {
73
- provisorio.push(
74
- callback.call(
75
- interpreter, [array[index]]
76
- )
77
- );
78
- }
79
-
80
- return provisorio;
81
- })
82
- );
83
-
84
- globals.defineVar(
85
- "ordenar",
86
- new StandardFn(1, function (obj) {
87
- if (Array.isArray(obj) == false) {
88
- throw new RuntimeError(
89
- this.token,
90
- "Valor Inválido. Objeto inserido não é um vetor."
91
- );
92
- }
93
-
94
- let trocado;
95
- let length = obj.length;
96
- do {
97
- trocado = false;
98
- for (var i = 0; i < length - 1; i++) {
99
- if (obj[i] > obj[i + 1]) {
100
- [obj[i], obj[i + 1]] = [obj[i + 1], obj[i]];
101
- trocado = true;
102
- }
103
- }
104
- } while (trocado);
105
- return obj;
106
- })
107
- );
108
-
109
- globals.defineVar(
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,
115
- "Somente números podem passar para real."
116
- );
117
- return parseFloat(value);
118
- })
119
- );
120
-
121
- globals.defineVar(
122
- "tamanho",
123
- new StandardFn(1, function (obj) {
124
- if (!isNaN(obj)) {
125
- throw new RuntimeError(
126
- this.token,
127
- "Não é possível encontrar o tamanho de um número."
128
- );
129
- }
130
-
131
- if (obj instanceof EguaInstance) {
132
- throw new RuntimeError(
133
- this.token,
134
- "Você não pode encontrar o tamanho de uma declaração."
135
- );
136
- }
137
-
138
- if (obj instanceof EguaFunction) {
139
- return obj.declaration.params.length;
140
- }
141
-
142
- if (obj instanceof StandardFn) {
143
- return obj.arityValue;
144
- }
145
-
146
- if (obj instanceof EguaClass) {
147
- let methods = obj.methods;
148
- let length = 0;
149
-
150
- if (methods.init && methods.init.isInitializer) {
151
- length = methods.init.declaration.params.length;
152
- }
153
-
154
- return length;
155
- }
156
-
157
- return obj.length;
158
- })
159
- );
160
-
161
- globals.defineVar(
162
- "texto",
163
- new StandardFn(1, function (value) {
164
- return `${value}`;
165
- })
166
- );
167
-
168
- globals.defineVar("exports", {});
169
-
170
- return globals;
171
- };
@@ -1,41 +0,0 @@
1
- const RuntimeError = require("../errors.js").RuntimeError,
2
- StandardFn = require("../structures/standardFn.js"),
3
- EguaModule = require("../structures/module.js");
4
-
5
- const loadModule = function (moduleName, modulePath) {
6
- let moduleData;
7
- try {
8
- moduleData = require(modulePath);
9
- } catch (erro) {
10
- throw new RuntimeError(moduleName, `Biblioteca ${moduleName} não encontrada para importação.`);
11
- }
12
-
13
- let newModule = new EguaModule(moduleName);
14
-
15
- let keys = Object.keys(moduleData);
16
- for (let i = 0; i < keys.length; i++) {
17
- let currentItem = moduleData[keys[i]];
18
-
19
- if (typeof currentItem === "function") {
20
- newModule[keys[i]] = new StandardFn(currentItem.length, currentItem);
21
- } else {
22
- newModule[keys[i]] = currentItem;
23
- }
24
- }
25
-
26
- return newModule;
27
- };
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
- }
41
- };
package/src/lib/tempo.js DELETED
@@ -1,50 +0,0 @@
1
- const RuntimeError = require("../errors.js").RuntimeError;
2
-
3
- // Retorna uma data completa
4
- module.exports.tempo = function () {
5
- return new Date();
6
- };
7
-
8
- // Retorna os segundos atuais do sistema
9
- module.exports.segundos = function () {
10
- return new Date().getSeconds();
11
- };
12
-
13
- // Retorna os minutos atuais do sistema
14
- module.exports.minutos = function () {
15
- return new Date().getMinutes();
16
- };
17
-
18
- // Retorna a hora atual do sistema
19
- module.exports.horas = function () {
20
- return new Date().getHours();
21
- };
22
-
23
- /**
24
- * Retorna uma instância de Date do JavaScript da data passada por parâmetro, no formato DD/MM/AAAA.
25
- * @param {string} dataComoTexto A data a ser convertida como texto, no formato DD/MM/AAAA.
26
- * @returns A data como um objeto Date to JavaScript.
27
- */
28
- module.exports.textoParaData = function (dataComoTexto) {
29
- const regex = /^(0[1-9]|[12][0-9]|3[01])[/](0[1-9]|1[012])[/](19|20)\d\d$/;
30
-
31
- if (typeof dataComoTexto !== 'string' || !regex.test(dataComoTexto)) {
32
- throw new RuntimeError(
33
- this.token,
34
- "O parâmetro passado deve ser um texto com a data no formato DD/MM/AAAA. Ex: '01/01/2014'"
35
- );
36
- }
37
-
38
- const date = new Date(converterDataPtParaIso(dataComoTexto));
39
- const timezoneOffset = date.getTimezoneOffset();
40
-
41
- return new Date(date.getTime() + timezoneOffset * 60 * 1000);
42
- }
43
-
44
- function converterDataPtParaIso(date) {
45
- const day = date.split("/")[0];
46
- const month = date.split("/")[1];
47
- const year = date.split("/")[2];
48
-
49
- return `${year}-${month}-${day}`;
50
- }