@designliquido/delegua 0.0.1

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.
@@ -0,0 +1,29 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "type": "node",
9
+ "request": "launch",
10
+ "name": "REPL",
11
+ "skipFiles": [
12
+ "<node_internals>/**"
13
+ ],
14
+ "console": "integratedTerminal",
15
+ "program": "${workspaceFolder}\\index.js"
16
+ },
17
+ {
18
+ "type": "node",
19
+ "request": "launch",
20
+ "name": "Testes",
21
+ "skipFiles": [
22
+ "<node_internals>/**"
23
+ ],
24
+ "args": ["${workspaceFolder}\\tests\\tests.egua"],
25
+ "console": "integratedTerminal",
26
+ "program": "${workspaceFolder}\\index.js"
27
+ }
28
+ ]
29
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "liveServer.settings.port": 5501
3
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Linguagem Egua
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,59 @@
1
+ <br>
2
+ <p align="center">
3
+ <img src="./web/assets/egua.png" alt="egua" width="auto" height="80px">
4
+
5
+ <h3 align="center">Linguagem Delégua</h3>
6
+
7
+ <p align="center">
8
+ Linguagem de programação, derivada da linguagem Égua
9
+ <br />
10
+ <a href="https://egua.tech/docs/egua" target="_blank"><strong>Documentação da Linguagem Égua »</strong></a>
11
+ <br />
12
+ <br />
13
+ <a href="https://egua.tech/egua/" target="_blank">IDEgua (Ambiente de Desenvolvimento Integrado da Linguagem Égua)</a>
14
+ ·
15
+ </p>
16
+ </p>
17
+
18
+ ## Introdução
19
+
20
+ Delégua é uma variação da linguagem Égua, usada para fins educacionais e comerciais pela Design Líquido.
21
+
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.
23
+
24
+ ## Características
25
+
26
+ - **Simples e Completa.** Podendo ser usadas por pessoas com ou sem experiência em programação.
27
+ - **Totalmente em Português.** Desenvolvida totalmente em português para quebrar a barreira do inglês.
28
+ - **Grátis.** Sem planos, sem limitações e sem propaganda.
29
+ - **Código aberto (open-source).** Todo código fonte disponível para estudar, modificar e contribuir.
30
+ - **Constantes Atualizações.** Junto à nossa comunidade, para trazermos melhorias e inovações.
31
+ - **Linguagem Científica.** Apoiamos e encorajamos o desenvolvimento e aprimoramento da ciência e da educação.
32
+
33
+ ### Usando como LAIR (Leia-Avalie-Imprima-Repita) em console
34
+
35
+ [Você deve ter o Node.js instalado em seu ambiente](https://dicasdejavascript.com.br/instalacao-do-nodejs-e-npm-no-windows-passo-a-passo).
36
+
37
+ Com o Node.js instalado, execute o seguinte comando em um prompt de comando (Terminal, PowerShell ou `cmd` no Windows, Terminal ou `bash` em Mac e Linux):
38
+
39
+ ```
40
+ npm install -g @designliquido/delegua
41
+ ```
42
+
43
+ Feito isso, execute o seguinte comando:
44
+
45
+ ```
46
+ delegua
47
+ ```
48
+
49
+ Você terá um interpretador Egua que avalia expressões linha a linha.
50
+
51
+ Para finalizar a execução do interpretador LAIR Delégua, use o atalho <key>Ctrl</key> + <key>C</key> (todos os sistemas operacionais).
52
+
53
+ ## Documentação
54
+
55
+ - Para acessar nossa documentação, visite o [site de documentação](https://egua.tech/docs).
56
+
57
+ ## Contruibuições
58
+
59
+ * Para contribuições, por favor, leia o nosso [Guia de Contribuição](.github/CONTRIBUTING.md) antes de submeter uma Pull Request.
@@ -0,0 +1 @@
1
+ module.exports = {presets: ['@babel/preset-env']}
package/bin/delegua ADDED
@@ -0,0 +1,3 @@
1
+ #! /usr/bin/env node
2
+
3
+ require('../index.js');
package/index.html ADDED
@@ -0,0 +1,43 @@
1
+ <html lang="pt-br">
2
+
3
+ <head>
4
+ <!-- Global site tag (gtag.js) - Google Analytics -->
5
+ <script async src="https://www.googletagmanager.com/gtag/js?id=UA-147268561-3"></script>
6
+ <script>
7
+ window.dataLayer = window.dataLayer || [];
8
+ function gtag() { dataLayer.push(arguments); }
9
+ gtag('js', new Date());
10
+
11
+ gtag('config', 'UA-147268561-3');
12
+ </script>
13
+
14
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
15
+ <meta charset="UTF-8">
16
+
17
+ <title>IDEgua - Linguagem egua</title>
18
+ <link rel="stylesheet" href="./web/style.css" />
19
+ <link rel="stylesheet" href="./web/theme.css">
20
+ <link href="https://fonts.googleapis.com/css?family=Roboto+Mono&display=swap" rel="stylesheet" />
21
+ <link rel="shortcut icon" href="./web/assets/logo2.svg">
22
+ </head>
23
+
24
+ <body>
25
+ <div id="container">
26
+ <div id="left"><select id="demoSelector"></select></div>
27
+ <div id="middle"><img src="web/assets/egua.png" alt="egua" width="100px" height="auto"></div>
28
+ <div id="right"><button id="runBtn">Executar</button></div>
29
+ </div>
30
+
31
+ <div id="editor"></div>
32
+ <div id="output" aria-live="polite"></div>
33
+
34
+ <script src="web/dist.js"></script>
35
+
36
+ <!-- framework do editor do código -->
37
+ <script src="./web/codeflask.min.js"></script>
38
+
39
+ <script src="web/demos.js"></script>
40
+ <script src="web/index.js"></script>
41
+ </body>
42
+
43
+ </html>
package/index.js ADDED
@@ -0,0 +1,14 @@
1
+ const Egua = require("./src/egua.js").Egua;
2
+
3
+ const main = function() {
4
+ let args = process.argv;
5
+
6
+ const egua = new Egua();
7
+ if (args.length === 2) {
8
+ egua.runPrompt();
9
+ } else {
10
+ egua.runfile(args[2]);
11
+ }
12
+ };
13
+
14
+ main();
package/package.json ADDED
@@ -0,0 +1,37 @@
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
+ }
package/src/egua.js ADDED
@@ -0,0 +1,102 @@
1
+ const Lexer = require("./lexer.js");
2
+ const Parser = require("./parser.js");
3
+ const Resolver = require("./resolver.js");
4
+ const Interpreter = require("./interpreter.js");
5
+ const tokenTypes = require("./tokenTypes.js");
6
+ const fs = require("fs");
7
+ const path = require("path");
8
+ const readline = require("readline");
9
+
10
+ module.exports.Egua = class Egua {
11
+ constructor(nomeArquivo) {
12
+ this.nomeArquivo = nomeArquivo;
13
+
14
+ this.teveErro = false;
15
+ this.teveErroEmTempoDeExecucao = false;
16
+ }
17
+
18
+ runPrompt() {
19
+ const interpreter = new Interpreter(this, process.cwd(), undefined);
20
+ console.log("Console da Linguagem Delégua v1.1.15");
21
+ const leiaLinha = readline.createInterface({
22
+ input: process.stdin,
23
+ output: process.stdout,
24
+ prompt: "\negua> "
25
+ });
26
+
27
+ leiaLinha.prompt();
28
+
29
+ leiaLinha.on("line", linha => {
30
+ this.teveErro = false;
31
+ this.teveErroEmTempoDeExecucao = false;
32
+
33
+ this.run(linha, interpreter);
34
+ leiaLinha.prompt();
35
+ });
36
+ }
37
+
38
+ runfile(nomeArquivo) {
39
+ this.nomeArquivo = path.basename(nomeArquivo);
40
+ const interpretador = new Interpreter(this, process.cwd());
41
+
42
+ const dadosDoArquivo = fs.readFileSync(nomeArquivo).toString();
43
+ this.run(dadosDoArquivo, interpretador);
44
+
45
+ if (this.teveErro) process.exit(65);
46
+ if (this.teveErroEmTempoDeExecucao) process.exit(70);
47
+ }
48
+
49
+ run(code, interpretador) {
50
+ const lexer = new Lexer(code, this);
51
+ const simbolos = lexer.scan();
52
+
53
+ if (this.teveErro === true) return;
54
+
55
+ const analisar = new Parser(simbolos, this);
56
+ const declaracoes = analisar.analisar();
57
+
58
+ if (this.teveErro === true) return;
59
+
60
+ const resolver = new Resolver(interpretador, this);
61
+ resolver.resolver(declaracoes);
62
+
63
+ if (this.teveErro === true) return;
64
+
65
+ interpretador.interpretar(declaracoes);
66
+ }
67
+
68
+ reportar(linha, onde, mensagem) {
69
+ if (this.nomeArquivo)
70
+ console.error(
71
+ `[Arquivo: ${this.nomeArquivo}] [Linha: ${linha}] Erro${onde}: ${mensagem}`
72
+ );
73
+ else console.error(`[Linha: ${linha}] Erro${onde}: ${mensagem}`);
74
+ this.teveErro = true;
75
+ }
76
+
77
+ error(simbolo, mensagemDeErro) {
78
+ if (simbolo.type === tokenTypes.EOF) {
79
+ this.reportar(simbolo.line, " no final", mensagemDeErro);
80
+ } else {
81
+ this.reportar(simbolo.line, ` no '${simbolo.lexeme}'`, mensagemDeErro);
82
+ }
83
+ }
84
+
85
+ lexerError(linha, caractere, mensagem) {
86
+ this.reportar(linha, ` no '${caractere}'`, mensagem);
87
+ }
88
+
89
+ runtimeError(erro) {
90
+ const linha = erro.token.line;
91
+ if (erro.token && linha) {
92
+ if (this.nomeArquivo)
93
+ console.error(
94
+ `Erro: [Arquivo: ${this.nomeArquivo}] [Linha: ${erro.token.line}] ${erro.message}`
95
+ );
96
+ else console.error(`Erro: [Linha: ${erro.token.line}] ${erro.message}`);
97
+ } else {
98
+ console.error(`Erro: ${erro.message}`);
99
+ }
100
+ this.teveErroEmTempoDeExecucao = true;
101
+ }
102
+ };
@@ -0,0 +1,53 @@
1
+ const RuntimeError = require("./errors.js").RuntimeError;
2
+
3
+ module.exports = class Environment {
4
+ constructor(enclosing) {
5
+ this.enclosing = enclosing || null;
6
+ this.values = {};
7
+ }
8
+
9
+ defineVar(varName, value) {
10
+ this.values[varName] = value;
11
+ }
12
+
13
+ assignVarAt(distance, name, value) {
14
+ this.ancestor(distance).values[name.lexeme] = value;
15
+ }
16
+
17
+ assignVar(name, value) {
18
+ if (this.values[name.lexeme] !== undefined) {
19
+ this.values[name.lexeme] = value;
20
+ return;
21
+ }
22
+
23
+ if (this.enclosing != null) {
24
+ this.enclosing.assignVar(name, value);
25
+ return;
26
+ }
27
+
28
+ throw new RuntimeError(name, "Variável não definida '" + name.lexeme + "'.");
29
+ }
30
+
31
+ ancestor(distance) {
32
+ let environment = this;
33
+ for (let i = 0; i < distance; i++) {
34
+ environment = environment.enclosing;
35
+ }
36
+
37
+ return environment;
38
+ }
39
+
40
+ getVarAt(distance, name) {
41
+ return this.ancestor(distance).values[name];
42
+ }
43
+
44
+ getVar(token) {
45
+ if (this.values[token.lexeme] !== undefined) {
46
+ return this.values[token.lexeme];
47
+ }
48
+
49
+ if (this.enclosing !== null) return this.enclosing.getVar(token);
50
+
51
+ throw new RuntimeError(token, "Variável não definida '" + token.lexeme + "'.");
52
+ }
53
+ };
package/src/errors.js ADDED
@@ -0,0 +1,17 @@
1
+ module.exports.RuntimeError = class RuntimeError extends Error {
2
+ constructor(token, message) {
3
+ super(message);
4
+ this.token = token;
5
+ }
6
+ };
7
+
8
+ module.exports.ContinueException = class ContinueException extends Error { };
9
+
10
+ module.exports.BreakException = class BreakException extends Error { };
11
+
12
+ module.exports.ReturnException = class ReturnException extends Error {
13
+ constructor(value) {
14
+ super(value);
15
+ this.value = value;
16
+ }
17
+ };
package/src/expr.js ADDED
@@ -0,0 +1,228 @@
1
+ class Expr {
2
+ aceitar(visitor) {}
3
+ }
4
+
5
+ class Assign extends Expr {
6
+ constructor(name, value) {
7
+ super();
8
+ this.name = name;
9
+ this.value = value;
10
+ }
11
+
12
+ aceitar(visitor) {
13
+ return visitor.visitAssignExpr(this);
14
+ }
15
+ }
16
+
17
+ class Binary extends Expr {
18
+ constructor(left, operator, right) {
19
+ super();
20
+ this.left = left;
21
+ this.operator = operator;
22
+ this.right = right;
23
+ }
24
+
25
+ aceitar(visitor) {
26
+ return visitor.visitBinaryExpr(this);
27
+ }
28
+ }
29
+
30
+ class Funcao extends Expr {
31
+ constructor(params, body) {
32
+ super();
33
+ this.params = params;
34
+ this.body = body;
35
+ }
36
+
37
+ aceitar(visitor) {
38
+ return visitor.visitFunctionExpr(this);
39
+ }
40
+ }
41
+
42
+ class Call extends Expr {
43
+ constructor(callee, paren, args) {
44
+ super();
45
+ this.callee = callee;
46
+ this.paren = paren;
47
+ this.args = args;
48
+ }
49
+
50
+ aceitar(visitor) {
51
+ return visitor.visitCallExpr(this);
52
+ }
53
+ }
54
+
55
+ class Get extends Expr {
56
+ constructor(object, name) {
57
+ super();
58
+ this.object = object;
59
+ this.name = name;
60
+ }
61
+
62
+ aceitar(visitor) {
63
+ return visitor.visitGetExpr(this);
64
+ }
65
+ }
66
+
67
+ class Grouping extends Expr {
68
+ constructor(expression) {
69
+ super();
70
+ this.expression = expression;
71
+ }
72
+
73
+ aceitar(visitor) {
74
+ return visitor.visitGroupingExpr(this);
75
+ }
76
+ }
77
+
78
+ class Literal extends Expr {
79
+ constructor(value) {
80
+ super();
81
+ this.value = value;
82
+ }
83
+
84
+ aceitar(visitor) {
85
+ return visitor.visitLiteralExpr(this);
86
+ }
87
+ }
88
+
89
+ class Array extends Expr {
90
+ constructor(values) {
91
+ super();
92
+ this.values = values;
93
+ }
94
+
95
+ aceitar(visitor) {
96
+ return visitor.visitArrayExpr(this);
97
+ }
98
+ }
99
+
100
+ class Dictionary extends Expr {
101
+ constructor(keys, values) {
102
+ super();
103
+ this.keys = keys;
104
+ this.values = values;
105
+ }
106
+
107
+ aceitar(visitor) {
108
+ return visitor.visitDictionaryExpr(this);
109
+ }
110
+ }
111
+
112
+ class Subscript extends Expr {
113
+ constructor(callee, index, closeBracket) {
114
+ super();
115
+ this.callee = callee;
116
+ this.index = index;
117
+ this.closeBracket = closeBracket;
118
+ }
119
+
120
+ aceitar(visitor) {
121
+ return visitor.visitSubscriptExpr(this);
122
+ }
123
+ }
124
+
125
+ class Assignsubscript extends Expr {
126
+ constructor(obj, index, value) {
127
+ super();
128
+ this.obj = obj;
129
+ this.index = index;
130
+ this.value = value;
131
+ }
132
+
133
+ aceitar(visitor) {
134
+ return visitor.visitAssignsubscriptExpr(this);
135
+ }
136
+ }
137
+
138
+ class Logical extends Expr {
139
+ constructor(left, operator, right) {
140
+ super();
141
+ this.left = left;
142
+ this.operator = operator;
143
+ this.right = right;
144
+ }
145
+
146
+ aceitar(visitor) {
147
+ return visitor.visitLogicalExpr(this);
148
+ }
149
+ }
150
+
151
+ class Set extends Expr {
152
+ constructor(object, name, value) {
153
+ super();
154
+ this.object = object;
155
+ this.name = name;
156
+ this.value = value;
157
+ }
158
+
159
+ aceitar(visitor) {
160
+ return visitor.visitSetExpr(this);
161
+ }
162
+ }
163
+
164
+ class Super extends Expr {
165
+ constructor(keyword, method) {
166
+ super();
167
+ this.keyword = keyword;
168
+ this.method = method;
169
+ }
170
+
171
+ aceitar(visitor) {
172
+ return visitor.visitSuperExpr(this);
173
+ }
174
+ }
175
+
176
+ class Isto extends Expr {
177
+ constructor(keyword) {
178
+ super();
179
+ this.keyword = keyword;
180
+ }
181
+
182
+ aceitar(visitor) {
183
+ return visitor.visitThisExpr(this);
184
+ }
185
+ }
186
+
187
+ class Unary extends Expr {
188
+ constructor(operator, right) {
189
+ super();
190
+ this.operator = operator;
191
+ this.right = right;
192
+ }
193
+
194
+ aceitar(visitor) {
195
+ return visitor.visitUnaryExpr(this);
196
+ }
197
+ }
198
+
199
+ class Variable extends Expr {
200
+ constructor(name) {
201
+ super();
202
+ this.name = name;
203
+ }
204
+
205
+ aceitar(visitor) {
206
+ return visitor.visitVariableExpr(this);
207
+ }
208
+ }
209
+
210
+ module.exports = {
211
+ Assign,
212
+ Binary,
213
+ Funcao,
214
+ Call,
215
+ Get,
216
+ Grouping,
217
+ Literal,
218
+ Array,
219
+ Dictionary,
220
+ Subscript,
221
+ Assignsubscript,
222
+ Logical,
223
+ Set,
224
+ Super,
225
+ Isto,
226
+ Unary,
227
+ Variable
228
+ };