@designliquido/delegua 0.0.2 → 0.1.0

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 (81) hide show
  1. package/.github/CONTRIBUTING.md +37 -0
  2. package/.github/workflows/principal.yml +3 -1
  3. package/.release-it.json +2 -1
  4. package/.vscode/launch.json +43 -8
  5. package/README.md +9 -1
  6. package/bin/delegua +2 -2
  7. package/bin/delegua.cmd +1 -1
  8. package/index.ts +29 -0
  9. package/package.json +9 -4
  10. package/src/ambiente.ts +56 -0
  11. package/src/avaliador-sintatico/dialetos/egua-classico.ts +983 -0
  12. package/src/avaliador-sintatico/dialetos/index.ts +1 -0
  13. package/src/avaliador-sintatico/index.ts +983 -0
  14. package/src/avaliador-sintatico/parser-error.ts +1 -0
  15. package/src/{lib/globalLib.js → bibliotecas/bibliotecaGlobal.ts} +34 -34
  16. package/src/{lib/importStdlib.js → bibliotecas/importarBiblioteca.ts} +9 -9
  17. package/src/construtos/assign-subscript.ts +19 -0
  18. package/src/construtos/atribuir.ts +17 -0
  19. package/src/construtos/binario.ts +19 -0
  20. package/src/construtos/call.ts +19 -0
  21. package/src/construtos/conjunto.ts +19 -0
  22. package/src/construtos/dicionario.ts +17 -0
  23. package/src/construtos/expr.ts +3 -0
  24. package/src/construtos/funcao.ts +17 -0
  25. package/src/construtos/get.ts +17 -0
  26. package/src/construtos/grouping.ts +15 -0
  27. package/src/construtos/index.ts +18 -0
  28. package/src/construtos/isto.ts +15 -0
  29. package/src/construtos/literal.ts +15 -0
  30. package/src/construtos/logical.ts +19 -0
  31. package/src/construtos/subscript.ts +19 -0
  32. package/src/construtos/super.ts +17 -0
  33. package/src/construtos/unario.ts +17 -0
  34. package/src/construtos/variavel.ts +15 -0
  35. package/src/construtos/vetor.ts +15 -0
  36. package/src/{stmt.js → declaracoes/index.ts} +79 -51
  37. package/src/delegua.ts +156 -0
  38. package/src/estruturas/callable.ts +11 -0
  39. package/src/estruturas/{classe.js → classe.ts} +11 -7
  40. package/src/estruturas/{funcaoPadrao.js → funcao-padrao.ts} +8 -4
  41. package/src/estruturas/funcao.ts +70 -0
  42. package/src/estruturas/index.ts +6 -0
  43. package/src/estruturas/{instancia.js → instancia.ts} +12 -9
  44. package/src/estruturas/modulo.ts +11 -0
  45. package/src/excecoes/break-exception.ts +1 -0
  46. package/src/excecoes/continue-exception.ts +1 -0
  47. package/src/excecoes/erro-em-tempo-de-execucao.ts +11 -0
  48. package/src/excecoes/index.ts +4 -0
  49. package/src/excecoes/return-exception.ts +10 -0
  50. package/src/interfaces/avaliador-sintatico-interface.ts +58 -0
  51. package/src/interfaces/index.ts +6 -0
  52. package/src/interfaces/interpretador-interface.ts +52 -0
  53. package/src/interfaces/lexador-interface.ts +24 -0
  54. package/src/interfaces/pilha-interface.ts +7 -0
  55. package/src/interfaces/resolvedor-interface.ts +49 -0
  56. package/src/interfaces/simbolo-interface.ts +6 -0
  57. package/src/interpretador/dialetos/egua-classico.ts +825 -0
  58. package/src/interpretador/dialetos/index.ts +1 -0
  59. package/src/interpretador/index.ts +825 -0
  60. package/src/lexador/dialetos/egua-classico.ts +333 -0
  61. package/src/lexador/dialetos/index.ts +1 -0
  62. package/src/{lexer.js → lexador/index.ts} +38 -21
  63. package/src/resolvedor/Pilha.ts +29 -0
  64. package/src/resolvedor/ResolverError.ts +8 -0
  65. package/src/resolvedor/dialetos/egua-classico.ts +412 -0
  66. package/src/resolvedor/dialetos/index.ts +1 -0
  67. package/src/{resolver.js → resolvedor/index.ts} +101 -114
  68. package/src/{tiposDeSimbolos.js → tiposDeSimbolos.ts} +21 -22
  69. package/src/web.ts +75 -0
  70. package/tsconfig.json +11 -0
  71. package/indice.js +0 -14
  72. package/src/ambiente.js +0 -53
  73. package/src/delegua.js +0 -102
  74. package/src/erro.js +0 -18
  75. package/src/estruturas/callable.js +0 -5
  76. package/src/estruturas/funcao.js +0 -62
  77. package/src/estruturas/modulo.js +0 -9
  78. package/src/expr.js +0 -228
  79. package/src/interpretador.js +0 -802
  80. package/src/parser.js +0 -822
  81. package/src/web.js +0 -70
@@ -0,0 +1,37 @@
1
+ # Contribuindo
2
+
3
+ Qualquer pessoa pode sugerir melhoramentos para a linguagem ou correções de bugs. Uma recomendação é abrir uma _issue_ no GitHub antes, para colher a opinião da comunidade e evitar rejeições de contribuições.
4
+
5
+ Seguimos o padrão do GitHub para modificações. Modificações são feitas por meio de _Pull Requests_, que nos mostram quais partes do código mudaram da versão atual para a proposta de modificação.
6
+
7
+ Havendo aprovação dos mantenedores do projeto, juntamos a modificação ao código atual (_merge_) e lançamos novas versões de tempos em tempos.
8
+
9
+ ## Conhecimentos e Recomendações
10
+
11
+ O ambiente em que executamos é o Node.js que, basicamente, executa código JavaScript. Ou seja, se você tem conhecimento em JavaScript, é um primeiro passo para poder colaborar conosco. Por padrão, o Node.js vem com o NPM instalado, mas não o usamos. Usamos o Yarn, mais moderno e rápido. Você pode instalar o Yarn usando o comando abaixo (já tendo o NPM instalado):
12
+
13
+ ```bash
14
+ npm install -g yarn
15
+ ```
16
+
17
+ Feito isso, no diretório raiz do projeto, execute:
18
+
19
+ ```bash
20
+ yarn
21
+ ```
22
+
23
+ Isso deve baixar e instalar os pacotes que Delégua precisa para ser desenvolvida.
24
+
25
+ Delégua funciona em qualquer sistema operacional que tenha uma versão de Node.js compatível.
26
+
27
+ Para os fontes, usamos [TypeScript](https://www.typescriptlang.org/) (versão mais recente). Normalmente desenvolvemos em Visual Studio Code, e, ao abrir o projeto nele, já temos as configurações para depurar (debugar) Delégua. Outros editores podem ser usados, mas não temos arquivos de suporte a todos eles.
28
+
29
+ ### Trabalhando na sua modificação
30
+
31
+ Recomendamos fazer um _fork_ do projeto (ou seja, uma cópia em separado), modificar essa cópia e abrir uma _Pull Request_ da sua cópia para o repositório oficial. [Este vídeo pode ajudar](https://www.youtube.com/watch?v=l1rwvDvD1og).
32
+
33
+ Ao abrir uma _Pull Request_, fazemos alguns testes automatizados para verificar se sua modificação tem ou não problemas. Você pode fazer os mesmos testes no seu ambiente local usando o comando:
34
+
35
+ ```bash
36
+ yarn testes
37
+ ```
@@ -13,7 +13,9 @@ jobs:
13
13
  - uses: actions/setup-node@v2-beta
14
14
  with:
15
15
  node-version: '16'
16
-
16
+ - name: NPM - Dependências
17
+ run: |
18
+ sudo npm install
17
19
  - name: Testes da Linguagem
18
20
  run: |
19
21
  sudo chmod +x ./bin/delegua
package/.release-it.json CHANGED
@@ -4,5 +4,6 @@
4
4
  },
5
5
  "github": {
6
6
  "release": true
7
- }
7
+ },
8
+ "npm.publishPath": "dist"
8
9
  }
@@ -7,23 +7,58 @@
7
7
  {
8
8
  "type": "node",
9
9
  "request": "launch",
10
- "name": "REPL",
10
+ "name": "REPL (Delégua)",
11
11
  "skipFiles": [
12
- "<node_internals>/**"
12
+ "<node_internals>/**",
13
+ "node_modules/**"
13
14
  ],
15
+ "cwd": "${workspaceRoot}",
14
16
  "console": "integratedTerminal",
15
- "program": "${workspaceFolder}\\indice.js"
17
+ "args": ["${workspaceFolder}\\index.ts"],
18
+ "runtimeExecutable": "node",
19
+ "runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"],
16
20
  },
17
21
  {
18
22
  "type": "node",
19
23
  "request": "launch",
20
- "name": "Testes",
24
+ "name": "REPL (Égua Clássico)",
21
25
  "skipFiles": [
22
- "<node_internals>/**"
26
+ "<node_internals>/**",
27
+ "node_modules/**"
23
28
  ],
24
- "args": ["${workspaceFolder}\\tests\\tests.egua"],
29
+ "cwd": "${workspaceRoot}",
25
30
  "console": "integratedTerminal",
26
- "program": "${workspaceFolder}\\indice.js"
27
- }
31
+ "args": ["${workspaceFolder}\\index.ts", "--dialeto", "egua"],
32
+ "runtimeExecutable": "node",
33
+ "runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"],
34
+ },
35
+ {
36
+ "type": "node",
37
+ "request": "launch",
38
+ "name": "Testes (Delégua)",
39
+ "skipFiles": [
40
+ "<node_internals>/**",
41
+ "node_modules/**"
42
+ ],
43
+ "cwd": "${workspaceRoot}",
44
+ "console": "integratedTerminal",
45
+ "args": ["${workspaceFolder}\\index.ts", "./testes/testes.egua"],
46
+ "runtimeExecutable": "node",
47
+ "runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"],
48
+ },
49
+ {
50
+ "type": "node",
51
+ "request": "launch",
52
+ "name": "Testes (Égua Clássico)",
53
+ "skipFiles": [
54
+ "<node_internals>/**",
55
+ "node_modules/**"
56
+ ],
57
+ "cwd": "${workspaceRoot}",
58
+ "console": "integratedTerminal",
59
+ "args": ["${workspaceFolder}\\index.ts", "--dialeto", "egua", "./testes/testes.egua"],
60
+ "runtimeExecutable": "node",
61
+ "runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"],
62
+ },
28
63
  ]
29
64
  }
package/README.md CHANGED
@@ -9,7 +9,15 @@
9
9
  <br />
10
10
  <br />
11
11
  <a href="https://egua.tech/egua/" target="_blank">IDEgua (Ambiente de Desenvolvimento Integrado da Linguagem Égua)</a>
12
- ·
12
+ </p>
13
+
14
+ <p align="center">
15
+ <img src="https://img.shields.io/github/issues/Designliquido/delegua" />
16
+ <img src="https://img.shields.io/github/stars/Designliquido/delegua" />
17
+ <img src="https://img.shields.io/github/forks/Designliquido/delegua" />
18
+ <img src="https://img.shields.io/npm/v/@designliquido/delegua" />
19
+ <img src="https://img.shields.io/github/license/Designliquido/delegua" />
20
+ <br>
13
21
  </p>
14
22
  </p>
15
23
 
package/bin/delegua CHANGED
@@ -1,3 +1,3 @@
1
- #! /usr/bin/env node
1
+ #! /usr/bin/env ts-node
2
2
 
3
- require('../indice.js');
3
+ require('../index');
package/bin/delegua.cmd CHANGED
@@ -1 +1 @@
1
- node indice.js %*
1
+ ts-node index.ts %*
package/index.ts ADDED
@@ -0,0 +1,29 @@
1
+ import { Delegua } from "./src/delegua";
2
+ import { Command } from "commander";
3
+
4
+ const principal = function () {
5
+ const analisadorArgumentos = new Command();
6
+ let nomeArquivo;
7
+
8
+ analisadorArgumentos
9
+ .option("-d, --dialeto <dialeto>", "Dialeto a ser usado. Padrão: delegua", "delegua")
10
+ .argument('[arquivos...]', 'Nomes dos arquivos (opcional)')
11
+ .action((arquivos) => {
12
+ if (arquivos.length > 0) {
13
+ nomeArquivo = arquivos[0];
14
+ }
15
+ });
16
+
17
+ analisadorArgumentos.parse();
18
+ const opcoes = analisadorArgumentos.opts();
19
+
20
+ const delegua = new Delegua(opcoes.dialeto);
21
+
22
+ if (!nomeArquivo) {
23
+ delegua.iniciarDelegua();
24
+ } else {
25
+ delegua.carregarArquivo(nomeArquivo);
26
+ }
27
+ };
28
+
29
+ principal();
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@designliquido/delegua",
3
- "version": "0.0.2",
3
+ "version": "0.1.0",
4
4
  "description": "Linguagem de programação simples e moderna usando português",
5
5
  "main": "indice.js",
6
6
  "scripts": {
7
+ "empacotar": "tsc && copyfiles -V ./bin/* ./dist/bin/",
7
8
  "npm-publish": "npm publish --access public",
8
9
  "testes": "./bin/delegua testes/testes.egua",
9
10
  "testes-unitarios": "jest",
10
- "production": "npm run npm-publish",
11
11
  "release": "release-it"
12
12
  },
13
13
  "repository": {
@@ -39,8 +39,13 @@
39
39
  "homepage": "https://github.com/DesignLiquido/delegua#readme",
40
40
  "devDependencies": {
41
41
  "@babel/preset-env": "^7.12.1",
42
+ "copyfiles": "^2.4.1",
42
43
  "jest": "^26.6.1",
43
- "release-it": "^14.11.8"
44
+ "release-it": "^14.11.8",
45
+ "ts-node": "^10.4.0",
46
+ "typescript": "^4.5.4"
44
47
  },
45
- "dependencies": {}
48
+ "dependencies": {
49
+ "commander": "^8.3.0"
50
+ }
46
51
  }
@@ -0,0 +1,56 @@
1
+ import { ErroEmTempoDeExecucao } from "./excecoes";
2
+
3
+ export class Ambiente {
4
+ enclosing: any;
5
+ valores: any;
6
+
7
+ constructor(enclosing?: any) {
8
+ this.enclosing = enclosing || null;
9
+ this.valores = {};
10
+ }
11
+
12
+ definirVariavel(nomeVariavel: any, valor: any) {
13
+ this.valores[nomeVariavel] = valor;
14
+ }
15
+
16
+ atribuirVariavelEm(distancia: any, nome: any, valor: any) {
17
+ this.ancestor(distancia).valores[nome.lexema] = valor;
18
+ }
19
+
20
+ atribuirVariavel(nome: any, valor: any) {
21
+ if (this.valores[nome.lexema] !== undefined) {
22
+ this.valores[nome.lexema] = valor;
23
+ return;
24
+ }
25
+
26
+ if (this.enclosing != null) {
27
+ this.enclosing.atribuirVariavel(nome, valor);
28
+ return;
29
+ }
30
+
31
+ throw new ErroEmTempoDeExecucao(nome, "Variável não definida '" + nome.lexema + "'.");
32
+ }
33
+
34
+ ancestor(distancia: any) {
35
+ let ambiente = this;
36
+ for (let i = 0; i < distancia; i++) {
37
+ ambiente = ambiente.enclosing;
38
+ }
39
+
40
+ return ambiente;
41
+ }
42
+
43
+ obterVariavelEm(distancia: any, nome: any) {
44
+ return this.ancestor(distancia).valores[nome];
45
+ }
46
+
47
+ obterVariavel(simbolo: any) {
48
+ if (this.valores[simbolo.lexema] !== undefined) {
49
+ return this.valores[simbolo.lexema];
50
+ }
51
+
52
+ if (this.enclosing !== null) return this.enclosing.obterVariavel(simbolo);
53
+
54
+ throw new ErroEmTempoDeExecucao(simbolo, "Variável não definida '" + simbolo.lexema + "'.");
55
+ }
56
+ };