@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
File without changes
@@ -0,0 +1,20 @@
1
+ name: Commit e PR - Principal
2
+
3
+ on:
4
+ pull_request:
5
+ branches: [ principal ]
6
+
7
+ jobs:
8
+ teste_desenvolvimento:
9
+ runs-on: ubuntu-latest
10
+
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - uses: actions/setup-node@v2-beta
14
+ with:
15
+ node-version: '16'
16
+
17
+ - name: Testes da Linguagem
18
+ run: |
19
+ sudo chmod +x ./bin/delegua
20
+ sudo npm run testes
@@ -0,0 +1,8 @@
1
+ {
2
+ "git": {
3
+ "commitMessage": "Lançamento da versão v${version}"
4
+ },
5
+ "github": {
6
+ "release": true
7
+ }
8
+ }
@@ -12,7 +12,7 @@
12
12
  "<node_internals>/**"
13
13
  ],
14
14
  "console": "integratedTerminal",
15
- "program": "${workspaceFolder}\\index.js"
15
+ "program": "${workspaceFolder}\\indice.js"
16
16
  },
17
17
  {
18
18
  "type": "node",
@@ -23,7 +23,7 @@
23
23
  ],
24
24
  "args": ["${workspaceFolder}\\tests\\tests.egua"],
25
25
  "console": "integratedTerminal",
26
- "program": "${workspaceFolder}\\index.js"
26
+ "program": "${workspaceFolder}\\indice.js"
27
27
  }
28
28
  ]
29
29
  }
package/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  <br>
2
2
  <p align="center">
3
- <img src="./web/assets/egua.png" alt="egua" width="auto" height="80px">
4
-
5
3
  <h3 align="center">Linguagem Delégua</h3>
6
4
 
7
5
  <p align="center">
@@ -17,9 +15,9 @@
17
15
 
18
16
  ## Introdução
19
17
 
20
- Delégua é uma variação da linguagem Égua, usada para fins educacionais e comerciais pela Design Líquido.
18
+ Delégua é uma variação da linguagem Égua, usada para fins educacionais e comerciais pela Design Líquido. A variação começou na versão 1.2.0 de Égua.
21
19
 
22
- Por ora, Delégua tem retrocompatibilidade com a linguagem Égua. Em outras palavras, todo programa escrito em Égua funciona em Delégua, mas Delégua tem capacidades a mais, conforme mencionado em documentação.
20
+ Delégua tem retrocompatibilidade com a linguagem Égua e usa a mesma extensão de arquivo (`.egua`). Em outras palavras, todo programa escrito em Égua funciona em Delégua, mas Delégua tem capacidades a mais, [conforme mencionado em documentação](https://github.com/DesignLiquido/delegua/wiki).
23
21
 
24
22
  ## Características
25
23
 
@@ -52,8 +50,9 @@ Para finalizar a execução do interpretador LAIR Delégua, use o atalho <key>Ct
52
50
 
53
51
  ## Documentação
54
52
 
55
- - Para acessar nossa documentação, visite o [site de documentação](https://egua.tech/docs).
53
+ - Para acessar a documentação da linguagem Égua, visite https://egua.tech/docs.
54
+ - [Delégua é documentada na Wiki deste GitHub](https://github.com/DesignLiquido/delegua/wiki).
56
55
 
57
- ## Contruibuições
56
+ ## Contribuições
58
57
 
59
58
  * Para contribuições, por favor, leia o nosso [Guia de Contribuição](.github/CONTRIBUTING.md) antes de submeter uma Pull Request.
package/bin/delegua CHANGED
@@ -1,3 +1,3 @@
1
1
  #! /usr/bin/env node
2
2
 
3
- require('../index.js');
3
+ require('../indice.js');
@@ -0,0 +1 @@
1
+ node indice.js %*
package/indice.js ADDED
@@ -0,0 +1,14 @@
1
+ const Delegua = require("./src/delegua.js").Delegua;
2
+
3
+ const principal = function() {
4
+ const argumentos = process.argv;
5
+
6
+ const delegua = new Delegua();
7
+ if (argumentos.length === 2) {
8
+ delegua.runPrompt();
9
+ } else {
10
+ delegua.runfile(argumentos[2]);
11
+ }
12
+ };
13
+
14
+ principal();
package/package.json CHANGED
@@ -1,37 +1,46 @@
1
- {
2
- "name": "@designliquido/delegua",
3
- "version": "0.0.1",
4
- "description": "Linguagem de programação simples e moderna usando português",
5
- "main": "index.js",
6
- "scripts": {
7
- "npm-publish": "npm publish --access public",
8
- "testes": "./bin/delegua testes/testes.egua",
9
- "testes-unitarios": "jest",
10
- "production": "npm run npm-publish"
11
- },
12
- "repository": {
13
- "type": "git",
14
- "url": "git+https://github.com/DesignLiquido/delegua.git"
15
- },
16
- "bin": {
17
- "delegua": "./bin/delegua"
18
- },
19
- "keywords": [
20
- "egua",
21
- "delegua"
22
- ],
23
- "author": "Leonel Sanches da Silva",
24
- "contributors": [
25
- "Leonel Sanches da Silva <leonel@designliquido.com.br> (https://www.linkedin.com/in/leonelsanchesdasilva/)"
26
- ],
27
- "license": "MIT",
28
- "bugs": {
29
- "url": "https://github.com/DesignLiquido/delegua/issues"
30
- },
31
- "homepage": "https://github.com/DesignLiquido/delegua#readme",
32
- "devDependencies": {
33
- "@babel/preset-env": "^7.12.1",
34
- "jest": "^26.6.1"
35
- },
36
- "dependencies": {}
37
- }
1
+ {
2
+ "name": "@designliquido/delegua",
3
+ "version": "0.0.2",
4
+ "description": "Linguagem de programação simples e moderna usando português",
5
+ "main": "indice.js",
6
+ "scripts": {
7
+ "npm-publish": "npm publish --access public",
8
+ "testes": "./bin/delegua testes/testes.egua",
9
+ "testes-unitarios": "jest",
10
+ "production": "npm run npm-publish",
11
+ "release": "release-it"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/DesignLiquido/delegua.git"
16
+ },
17
+ "bin": {
18
+ "delegua": "./bin/delegua"
19
+ },
20
+ "keywords": [
21
+ "egua",
22
+ "delegua"
23
+ ],
24
+ "author": "Leonel Sanches da Silva",
25
+ "contributors": [
26
+ {
27
+ "name": "Leonel Sanches da Silva",
28
+ "url": "https://www.linkedin.com/in/leonelsanchesdasilva/"
29
+ },
30
+ {
31
+ "name": "Samuel Renan Gonçalves Vaz",
32
+ "url": "https://www.linkedin.com/in/samuel-renan-gon%C3%A7alves-vaz-b6b83a103/"
33
+ }
34
+ ],
35
+ "license": "MIT",
36
+ "bugs": {
37
+ "url": "https://github.com/DesignLiquido/delegua/issues"
38
+ },
39
+ "homepage": "https://github.com/DesignLiquido/delegua#readme",
40
+ "devDependencies": {
41
+ "@babel/preset-env": "^7.12.1",
42
+ "jest": "^26.6.1",
43
+ "release-it": "^14.11.8"
44
+ },
45
+ "dependencies": {}
46
+ }
@@ -0,0 +1,53 @@
1
+ const ErroEmTempoDeExecucao = require("./erro.js").ErroEmTempoDeExecucao;
2
+
3
+ module.exports = class Ambiente {
4
+ constructor(enclosing) {
5
+ this.enclosing = enclosing || null;
6
+ this.valores = {};
7
+ }
8
+
9
+ definirVariavel(nomeVariavel, valor) {
10
+ this.valores[nomeVariavel] = valor;
11
+ }
12
+
13
+ atribuirVariavelEm(distancia, nome, valor) {
14
+ this.ancestor(distancia).valores[nome.lexeme] = valor;
15
+ }
16
+
17
+ atribuirVariavel(nome, valor) {
18
+ if (this.valores[nome.lexeme] !== undefined) {
19
+ this.valores[nome.lexeme] = valor;
20
+ return;
21
+ }
22
+
23
+ if (this.enclosing != null) {
24
+ this.enclosing.atribuirVariavel(nome, valor);
25
+ return;
26
+ }
27
+
28
+ throw new ErroEmTempoDeExecucao(nome, "Variável não definida '" + nome.lexeme + "'.");
29
+ }
30
+
31
+ ancestor(distancia) {
32
+ let ambiente = this;
33
+ for (let i = 0; i < distancia; i++) {
34
+ ambiente = ambiente.enclosing;
35
+ }
36
+
37
+ return ambiente;
38
+ }
39
+
40
+ obterVariavelEm(distancia, nome) {
41
+ return this.ancestor(distancia).valores[nome];
42
+ }
43
+
44
+ obterVariavel(simbolo) {
45
+ if (this.valores[simbolo.lexeme] !== undefined) {
46
+ return this.valores[simbolo.lexeme];
47
+ }
48
+
49
+ if (this.enclosing !== null) return this.enclosing.obterVariavel(simbolo);
50
+
51
+ throw new ErroEmTempoDeExecucao(simbolo, "Variável não definida '" + simbolo.lexeme + "'.");
52
+ }
53
+ };
@@ -1,13 +1,13 @@
1
1
  const Lexer = require("./lexer.js");
2
2
  const Parser = require("./parser.js");
3
3
  const Resolver = require("./resolver.js");
4
- const Interpreter = require("./interpreter.js");
5
- const tokenTypes = require("./tokenTypes.js");
4
+ const Interpretador = require("./interpretador.js");
5
+ const tiposDeSimbolos = require("./tiposDeSimbolos.js");
6
6
  const fs = require("fs");
7
- const path = require("path");
7
+ const caminho = require("path");
8
8
  const readline = require("readline");
9
9
 
10
- module.exports.Egua = class Egua {
10
+ module.exports.Delegua = class Delegua {
11
11
  constructor(nomeArquivo) {
12
12
  this.nomeArquivo = nomeArquivo;
13
13
 
@@ -16,12 +16,12 @@ module.exports.Egua = class Egua {
16
16
  }
17
17
 
18
18
  runPrompt() {
19
- const interpreter = new Interpreter(this, process.cwd(), undefined);
20
- console.log("Console da Linguagem Delégua v1.1.15");
19
+ const interpretador = new Interpretador(this, process.cwd(), undefined);
20
+ console.log("Console da Linguagem Delégua v0.0.1");
21
21
  const leiaLinha = readline.createInterface({
22
22
  input: process.stdin,
23
23
  output: process.stdout,
24
- prompt: "\negua> "
24
+ prompt: "\ndelegua> "
25
25
  });
26
26
 
27
27
  leiaLinha.prompt();
@@ -30,14 +30,14 @@ module.exports.Egua = class Egua {
30
30
  this.teveErro = false;
31
31
  this.teveErroEmTempoDeExecucao = false;
32
32
 
33
- this.run(linha, interpreter);
33
+ this.run(linha, interpretador);
34
34
  leiaLinha.prompt();
35
35
  });
36
36
  }
37
37
 
38
38
  runfile(nomeArquivo) {
39
- this.nomeArquivo = path.basename(nomeArquivo);
40
- const interpretador = new Interpreter(this, process.cwd());
39
+ this.nomeArquivo = caminho.basename(nomeArquivo);
40
+ const interpretador = new Interpretador(this, process.cwd());
41
41
 
42
42
  const dadosDoArquivo = fs.readFileSync(nomeArquivo).toString();
43
43
  this.run(dadosDoArquivo, interpretador);
@@ -46,8 +46,8 @@ module.exports.Egua = class Egua {
46
46
  if (this.teveErroEmTempoDeExecucao) process.exit(70);
47
47
  }
48
48
 
49
- run(code, interpretador) {
50
- const lexer = new Lexer(code, this);
49
+ run(codigo, interpretador) {
50
+ const lexer = new Lexer(codigo, this);
51
51
  const simbolos = lexer.scan();
52
52
 
53
53
  if (this.teveErro === true) return;
@@ -74,8 +74,8 @@ module.exports.Egua = class Egua {
74
74
  this.teveErro = true;
75
75
  }
76
76
 
77
- error(simbolo, mensagemDeErro) {
78
- if (simbolo.type === tokenTypes.EOF) {
77
+ erro(simbolo, mensagemDeErro) {
78
+ if (simbolo.tipo === tiposDeSimbolos.EOF) {
79
79
  this.reportar(simbolo.line, " no final", mensagemDeErro);
80
80
  } else {
81
81
  this.reportar(simbolo.line, ` no '${simbolo.lexeme}'`, mensagemDeErro);
@@ -86,16 +86,16 @@ module.exports.Egua = class Egua {
86
86
  this.reportar(linha, ` no '${caractere}'`, mensagem);
87
87
  }
88
88
 
89
- runtimeError(erro) {
90
- const linha = erro.token.line;
91
- if (erro.token && linha) {
89
+ erroEmTempoDeExecucao(erro) {
90
+ const linha = erro.simbolo.linha;
91
+ if (erro.simbolo && linha) {
92
92
  if (this.nomeArquivo)
93
93
  console.error(
94
- `Erro: [Arquivo: ${this.nomeArquivo}] [Linha: ${erro.token.line}] ${erro.message}`
94
+ `Erro: [Arquivo: ${this.nomeArquivo}] [Linha: ${erro.simbolo.linha}] ${erro.mensagem}`
95
95
  );
96
- else console.error(`Erro: [Linha: ${erro.token.line}] ${erro.message}`);
96
+ else console.error(`Erro: [Linha: ${erro.simbolo.linha}] ${erro.mensagem}`);
97
97
  } else {
98
- console.error(`Erro: ${erro.message}`);
98
+ console.error(`Erro: ${erro.mensagem}`);
99
99
  }
100
100
  this.teveErroEmTempoDeExecucao = true;
101
101
  }
package/src/erro.js ADDED
@@ -0,0 +1,18 @@
1
+ module.exports.ErroEmTempoDeExecucao = class ErroEmTempoDeExecucao extends Error {
2
+ constructor(simbolo, mensagem) {
3
+ super(mensagem);
4
+ this.simbolo = simbolo;
5
+ this.mensagem = mensagem;
6
+ }
7
+ };
8
+
9
+ module.exports.ContinueException = class ContinueException extends Error { };
10
+
11
+ module.exports.BreakException = class BreakException extends Error { };
12
+
13
+ module.exports.ReturnException = class ReturnException extends Error {
14
+ constructor(valor) {
15
+ super(valor);
16
+ this.valor = valor;
17
+ }
18
+ };
@@ -0,0 +1,5 @@
1
+ module.exports = class Callable {
2
+ aridade() {
3
+ return this.valorAridade;
4
+ }
5
+ };
@@ -0,0 +1,43 @@
1
+ const Callable = require("./callable.js");
2
+ const DeleguaInstancia = require("./instancia.js");
3
+
4
+ module.exports = class DeleguaClasse extends Callable {
5
+ constructor(nome, superClasse, metodos) {
6
+ super();
7
+ this.nome = nome;
8
+ this.superClasse = superClasse;
9
+ this.metodos = metodos;
10
+ }
11
+
12
+ encontrarMetodo(nome) {
13
+ if (this.metodos.hasOwnProperty(nome)) {
14
+ return this.metodos[nome];
15
+ }
16
+
17
+ if (this.superClasse !== null) {
18
+ return this.superClasse.encontrarMetodo(nome);
19
+ }
20
+
21
+ return undefined;
22
+ }
23
+
24
+ toString() {
25
+ return `<classe ${this.nome}>`;
26
+ }
27
+
28
+ aridade() {
29
+ let inicializador = this.encontrarMetodo("construtor");
30
+ return inicializador ? inicializador.aridade() : 0;
31
+ }
32
+
33
+ call(interpretador, argumentos) {
34
+ let instancia = new DeleguaInstancia(this);
35
+
36
+ let inicializador = this.encontrarMetodo("construtor");
37
+ if (inicializador) {
38
+ inicializador.bind(instancia).call(interpretador, argumentos);
39
+ }
40
+
41
+ return instancia;
42
+ }
43
+ };
@@ -0,0 +1,62 @@
1
+ const Callable = require("./callable.js");
2
+ const Ambiente = require("../ambiente.js");
3
+ const ReturnExpection = require("../erro.js").ReturnException;
4
+
5
+ module.exports = class DeleguaFuncao extends Callable {
6
+ constructor(nome, declaracao, closure, eInicializador = false) {
7
+ super();
8
+ this.nome = nome;
9
+ this.declaracao = declaracao;
10
+ this.closure = closure;
11
+ this.eInicializador = eInicializador;
12
+ }
13
+
14
+ aridade() {
15
+ return this.declaracao.parametros.length;
16
+ }
17
+
18
+ toString() {
19
+ if (this.nome === null) return "<função>";
20
+ return `<função ${this.nome}>`;
21
+ }
22
+
23
+ call(interpretador, argumentos) {
24
+ let ambiente = new Ambiente(this.closure);
25
+ let parametros = this.declaracao.parametros;
26
+ for (let i = 0; i < parametros.length; i++) {
27
+ const param = parametros[i];
28
+
29
+ const nome = param["nome"].lexeme;
30
+ let valor = argumentos[i];
31
+ if (argumentos[i] === null) {
32
+ valor = param["padrao"] ? param["padrao"].valor : null;
33
+ }
34
+ ambiente.definirVariavel(nome, valor);
35
+ }
36
+
37
+ try {
38
+ interpretador.executeBlock(this.declaracao.corpo, ambiente);
39
+ } catch (erro) {
40
+ if (erro instanceof ReturnExpection) {
41
+ if (this.eInicializador) return this.closure.obterVariavelEm(0, "isto");
42
+ return erro.valor;
43
+ } else {
44
+ throw erro;
45
+ }
46
+ }
47
+
48
+ if (this.eInicializador) return this.closure.obterVariavelEm(0, "isto");
49
+ return null;
50
+ }
51
+
52
+ bind(instancia) {
53
+ let ambiente = new Ambiente(this.closure);
54
+ ambiente.definirVariavel("isto", instancia);
55
+ return new DeleguaFuncao(
56
+ this.nome,
57
+ this.declaracao,
58
+ ambiente,
59
+ this.eInicializador
60
+ );
61
+ }
62
+ };
@@ -0,0 +1,18 @@
1
+ const Callable = require("./callable.js");
2
+
3
+ module.exports = class FuncaoPadrao extends Callable {
4
+ constructor(valorAridade, funcao) {
5
+ super();
6
+ this.valorAridade = valorAridade;
7
+ this.funcao = funcao;
8
+ }
9
+
10
+ chamar(interpretador, argumentos, simbolo) {
11
+ this.simbolo = simbolo;
12
+ return this.funcao.apply(this, argumentos);
13
+ }
14
+
15
+ toString() {
16
+ return "<função>";
17
+ }
18
+ };
@@ -0,0 +1,27 @@
1
+ const ErroEmTempoDeExecucao = require("../erro.js").ErroEmTempoDeExecucao;
2
+
3
+ module.exports = class DeleguaInstancia {
4
+ constructor(criarClasse) {
5
+ this.criarClasse = criarClasse;
6
+ this.campos = {};
7
+ }
8
+
9
+ get(nome) {
10
+ if (this.campos.hasOwnProperty(nome.lexeme)) {
11
+ return this.campos[nome.lexeme];
12
+ }
13
+
14
+ let metodo = this.criarClasse.encontrarMetodo(nome.lexeme);
15
+ if (metodo) return metodo.bind(this);
16
+
17
+ throw new ErroEmTempoDeExecucao(nome, "Método indefinido não recuperado.");
18
+ }
19
+
20
+ set(nome, valor) {
21
+ this.campos[nome.lexeme] = valor;
22
+ }
23
+
24
+ toString() {
25
+ return "<Objeto " + this.criarClasse.nome + ">";
26
+ }
27
+ };
@@ -0,0 +1,9 @@
1
+ module.exports = class DeleguaModulo {
2
+ constructor(nome) {
3
+ if (nome !== undefined) this.nome = nome;
4
+ }
5
+
6
+ toString() {
7
+ return this.nome ? `<modulo ${this.nome}>` : "<modulo>";
8
+ }
9
+ };