@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/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
- }
@@ -1,5 +0,0 @@
1
- module.exports = class Callable {
2
- arity() {
3
- return this.arityValue;
4
- }
5
- };
@@ -1,43 +0,0 @@
1
- const Callable = require("./callable.js");
2
- const EguaInstance = require("./instance.js");
3
-
4
- module.exports = class EguaClass extends Callable {
5
- constructor(name, superclass, methods) {
6
- super();
7
- this.name = name;
8
- this.superclass = superclass;
9
- this.methods = methods;
10
- }
11
-
12
- findMethod(name) {
13
- if (this.methods.hasOwnProperty(name)) {
14
- return this.methods[name];
15
- }
16
-
17
- if (this.superclass !== null) {
18
- return this.superclass.findMethod(name);
19
- }
20
-
21
- return undefined;
22
- }
23
-
24
- toString() {
25
- return `<classe ${this.name}>`;
26
- }
27
-
28
- arity() {
29
- let initializer = this.findMethod("construtor");
30
- return initializer ? initializer.arity() : 0;
31
- }
32
-
33
- call(interpreter, args) {
34
- let instance = new EguaInstance(this);
35
-
36
- let initializer = this.findMethod("construtor");
37
- if (initializer) {
38
- initializer.bind(instance).call(interpreter, args);
39
- }
40
-
41
- return instance;
42
- }
43
- };
@@ -1,62 +0,0 @@
1
- const Callable = require("./callable.js");
2
- const Environment = require("../environment.js");
3
- const ReturnExpection = require("../errors.js").ReturnException;
4
-
5
- module.exports = class EguaFunction extends Callable {
6
- constructor(name, declaration, closure, isInitializer = false) {
7
- super();
8
- this.name = name;
9
- this.declaration = declaration;
10
- this.closure = closure;
11
- this.isInitializer = isInitializer;
12
- }
13
-
14
- arity() {
15
- return this.declaration.params.length;
16
- }
17
-
18
- toString() {
19
- if (this.name === null) return "<função>";
20
- return `<função ${this.name}>`;
21
- }
22
-
23
- call(interpreter, args) {
24
- let environment = new Environment(this.closure);
25
- let params = this.declaration.params;
26
- for (let i = 0; i < params.length; i++) {
27
- let param = params[i];
28
-
29
- let name = param["name"].lexeme;
30
- let value = args[i];
31
- if (args[i] === null) {
32
- value = param["default"] ? param["default"].value : null;
33
- }
34
- environment.defineVar(name, value);
35
- }
36
-
37
- try {
38
- interpreter.executeBlock(this.declaration.body, environment);
39
- } catch (error) {
40
- if (error instanceof ReturnExpection) {
41
- if (this.isInitializer) return this.closure.getVarAt(0, "isto");
42
- return error.value;
43
- } else {
44
- throw error;
45
- }
46
- }
47
-
48
- if (this.isInitializer) return this.closure.getVarAt(0, "isto");
49
- return null;
50
- }
51
-
52
- bind(instance) {
53
- let environment = new Environment(this.closure);
54
- environment.defineVar("isto", instance);
55
- return new EguaFunction(
56
- this.name,
57
- this.declaration,
58
- environment,
59
- this.isInitializer
60
- );
61
- }
62
- };
@@ -1,27 +0,0 @@
1
- const RuntimeError = require("../errors.js").RuntimeError;
2
-
3
- module.exports = class EguaInstance {
4
- constructor(creatorClass) {
5
- this.creatorClass = creatorClass;
6
- this.fields = {};
7
- }
8
-
9
- get(name) {
10
- if (this.fields.hasOwnProperty(name.lexeme)) {
11
- return this.fields[name.lexeme];
12
- }
13
-
14
- let method = this.creatorClass.findMethod(name.lexeme);
15
- if (method) return method.bind(this);
16
-
17
- throw new RuntimeError(name, "Método indefinido não recuperado.");
18
- }
19
-
20
- set(name, value) {
21
- this.fields[name.lexeme] = value;
22
- }
23
-
24
- toString() {
25
- return "<Objeto " + this.creatorClass.name + ">";
26
- }
27
- };
@@ -1,9 +0,0 @@
1
- module.exports = class EguaModule {
2
- constructor(name) {
3
- if (name !== undefined) this.name = name;
4
- }
5
-
6
- toString() {
7
- return this.name ? `<module ${this.name}>` : "<module>";
8
- }
9
- };
@@ -1,18 +0,0 @@
1
- const Callable = require("./callable.js");
2
-
3
- module.exports = class StandardFn extends Callable {
4
- constructor(arityValue, func) {
5
- super();
6
- this.arityValue = arityValue;
7
- this.func = func;
8
- }
9
-
10
- call(interpreter, args, token) {
11
- this.token = token;
12
- return this.func.apply(this, args);
13
- }
14
-
15
- toString() {
16
- return "<função>";
17
- }
18
- };