@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
@@ -1,31 +1,39 @@
1
- class Stmt {
1
+ export class Stmt {
2
2
  aceitar(visitor) { }
3
3
  }
4
4
 
5
- class Expressao extends Stmt {
5
+ export class Expressao extends Stmt {
6
+ expressao: any;
7
+
6
8
  constructor(expressao) {
7
9
  super();
8
10
  this.expressao = expressao;
9
11
  }
10
12
 
11
- aceitar(visitor) {
13
+ aceitar(visitor: any) {
12
14
  return visitor.visitExpressionStmt(this)
13
15
  }
14
16
  }
15
17
 
16
- class Funcao extends Stmt {
17
- constructor(nome, funcao) {
18
+ export class Funcao extends Stmt {
19
+ nome: string;
20
+ funcao: any;
21
+
22
+ constructor(nome: any, funcao: any) {
18
23
  super();
19
24
  this.nome = nome;
20
25
  this.funcao = funcao;
21
26
  }
22
27
 
23
- aceitar(visitor) {
28
+ aceitar(visitor: any) {
24
29
  return visitor.visitFunctionStmt(this);
25
30
  }
26
31
  }
27
32
 
28
- class Retorna extends Stmt {
33
+ export class Retorna extends Stmt {
34
+ palavraChave: string;
35
+ valor: any;
36
+
29
37
  constructor(palavraChave, valor) {
30
38
  super();
31
39
  this.palavraChave = palavraChave;
@@ -37,20 +45,26 @@ class Retorna extends Stmt {
37
45
  }
38
46
  }
39
47
 
40
- class Classe extends Stmt {
41
- constructor(nome, superClasse, metodos) {
48
+ export class Classe extends Stmt {
49
+ nome: string;
50
+ superClasse: any;
51
+ metodos: any;
52
+
53
+ constructor(nome: any, superClasse: any, metodos: any) {
42
54
  super();
43
55
  this.nome = nome;
44
56
  this.superClasse = superClasse;
45
57
  this.metodos = metodos;
46
58
  }
47
59
 
48
- aceitar(visitor) {
60
+ aceitar(visitor: any) {
49
61
  return visitor.visitClassStmt(this);
50
62
  }
51
63
  }
52
64
 
53
- class Block extends Stmt {
65
+ export class Block extends Stmt {
66
+ declaracoes: any;
67
+
54
68
  constructor(declaracoes) {
55
69
  super();
56
70
  this.declaracoes = declaracoes;
@@ -61,7 +75,9 @@ class Block extends Stmt {
61
75
  }
62
76
  }
63
77
 
64
- class Escreva extends Stmt {
78
+ export class Escreva extends Stmt {
79
+ expressao: any;
80
+
65
81
  constructor(expressao) {
66
82
  super();
67
83
  this.expressao = expressao;
@@ -72,7 +88,10 @@ class Escreva extends Stmt {
72
88
  }
73
89
  }
74
90
 
75
- class Importar extends Stmt {
91
+ export class Importar extends Stmt {
92
+ caminho: string;
93
+ closeBracket: any;
94
+
76
95
  constructor(caminho, closeBracket) {
77
96
  super();
78
97
  this.caminho = caminho;
@@ -84,19 +103,25 @@ class Importar extends Stmt {
84
103
  }
85
104
  }
86
105
 
87
- class Fazer extends Stmt {
106
+ export class Fazer extends Stmt {
107
+ doBranch: any;
108
+ whileCondition: any;
109
+
88
110
  constructor(doBranch, whileCondition) {
89
- super();
90
- this.doBranch = doBranch;
91
- this.whileCondition = whileCondition;
111
+ super();
112
+ this.doBranch = doBranch;
113
+ this.whileCondition = whileCondition;
92
114
  }
93
-
115
+
94
116
  aceitar(visitor) {
95
- return visitor.visitDoStmt(this);
117
+ return visitor.visitDoStmt(this);
96
118
  }
97
- }
119
+ }
120
+
121
+ export class Enquanto extends Stmt {
122
+ condicao: any;
123
+ corpo: any;
98
124
 
99
- class Enquanto extends Stmt {
100
125
  constructor(condicao, corpo) {
101
126
  super();
102
127
  this.condicao = condicao;
@@ -108,7 +133,12 @@ class Enquanto extends Stmt {
108
133
  }
109
134
  }
110
135
 
111
- class Para extends Stmt {
136
+ export class Para extends Stmt {
137
+ inicializador: any;
138
+ condicao: any;
139
+ incrementar: any;
140
+ corpo: any;
141
+
112
142
  constructor(inicializador, condicao, incrementar, corpo) {
113
143
  super();
114
144
  this.inicializador = inicializador;
@@ -122,8 +152,13 @@ class Para extends Stmt {
122
152
  }
123
153
  }
124
154
 
125
- class Tente extends Stmt {
126
- constructor(tryBranch, catchBranch, elseBranch, finallyBranch) {
155
+ export class Tente extends Stmt {
156
+ tryBranch: any;
157
+ catchBranch: any;
158
+ elseBranch: any;
159
+ finallyBranch: any;
160
+
161
+ constructor(tryBranch: any, catchBranch: any, elseBranch: any, finallyBranch: any) {
127
162
  super();
128
163
  this.tryBranch = tryBranch;
129
164
  this.catchBranch = catchBranch;
@@ -131,12 +166,17 @@ class Tente extends Stmt {
131
166
  this.finallyBranch = finallyBranch;
132
167
  }
133
168
 
134
- aceitar(visitor) {
169
+ aceitar(visitor: any) {
135
170
  return visitor.visitTryStmt(this);
136
171
  }
137
172
  }
138
173
 
139
- class Se extends Stmt {
174
+ export class Se extends Stmt {
175
+ condicao: any;
176
+ thenBranch: any;
177
+ elifBranches: any;
178
+ elseBranch: any;
179
+
140
180
  constructor(condicao, thenBranch, elifBranches, elseBranch) {
141
181
  super();
142
182
  this.condicao = condicao;
@@ -150,7 +190,11 @@ class Se extends Stmt {
150
190
  }
151
191
  }
152
192
 
153
- class Escolha extends Stmt {
193
+ export class Escolha extends Stmt {
194
+ condicao: any;
195
+ branches: any;
196
+ defaultBranch: any;
197
+
154
198
  constructor(condicao, branches, defaultBranch) {
155
199
  super();
156
200
  this.condicao = condicao;
@@ -163,7 +207,7 @@ class Escolha extends Stmt {
163
207
  }
164
208
  }
165
209
 
166
- class Pausa extends Stmt {
210
+ export class Pausa extends Stmt {
167
211
  constructor() {
168
212
  super();
169
213
  }
@@ -173,7 +217,7 @@ class Pausa extends Stmt {
173
217
  }
174
218
  }
175
219
 
176
- class Continua extends Stmt {
220
+ export class Continua extends Stmt {
177
221
  constructor() {
178
222
  super();
179
223
  }
@@ -183,33 +227,17 @@ class Continua extends Stmt {
183
227
  }
184
228
  }
185
229
 
186
- class Var extends Stmt {
187
- constructor(nome, inicializador) {
230
+ export class Var extends Stmt {
231
+ nome: any;
232
+ inicializador: any;
233
+
234
+ constructor(nome: any, inicializador: any) {
188
235
  super();
189
236
  this.nome = nome;
190
237
  this.inicializador = inicializador;
191
238
  }
192
239
 
193
- aceitar(visitor) {
240
+ aceitar(visitor: any) {
194
241
  return visitor.visitVarStmt(this);
195
242
  }
196
243
  }
197
-
198
- module.exports = {
199
- Expressao,
200
- Funcao,
201
- Retorna,
202
- Classe,
203
- Block,
204
- Escreva,
205
- Importar,
206
- Fazer,
207
- Enquanto,
208
- Para,
209
- Tente,
210
- Se,
211
- Escolha,
212
- Pausa,
213
- Continua,
214
- Var
215
- };
package/src/delegua.ts ADDED
@@ -0,0 +1,156 @@
1
+ import * as fs from "fs";
2
+ import * as caminho from "path";
3
+ import * as readline from "readline";
4
+
5
+ import { Lexer } from "./lexador";
6
+ import { Parser } from "./avaliador-sintatico";
7
+ import { Resolver } from "./resolvedor";
8
+ import { Interpretador } from "./interpretador";
9
+ import tiposDeSimbolos from "./tiposDeSimbolos";
10
+
11
+ import { ReturnException } from "./excecoes";
12
+ import { AvaliadorSintaticoInterface, InterpretadorInterface, LexadorInterface } from "./interfaces";
13
+ import { ResolvedorInterface } from "./interfaces/resolvedor-interface";
14
+ import { InterpretadorEguaClassico } from "./interpretador/dialetos/egua-classico";
15
+ import { ResolverEguaClassico } from "./resolvedor/dialetos/egua-classico";
16
+ import { ParserEguaClassico } from "./avaliador-sintatico/dialetos/egua-classico";
17
+ import { LexerEguaClassico } from "./lexador/dialetos/egua-classico";
18
+
19
+ export class Delegua {
20
+ nomeArquivo: any;
21
+ teveErro: any;
22
+ teveErroEmTempoDeExecucao: any;
23
+ dialeto: string;
24
+
25
+ interpretador: InterpretadorInterface;
26
+ lexador: LexadorInterface;
27
+ avaliadorSintatico: AvaliadorSintaticoInterface;
28
+ resolvedor: ResolvedorInterface;
29
+
30
+ constructor(dialeto: string = 'delegua', nomeArquivo?: string) {
31
+ this.nomeArquivo = nomeArquivo;
32
+
33
+ this.teveErro = false;
34
+ this.teveErroEmTempoDeExecucao = false;
35
+
36
+ switch (dialeto) {
37
+ case 'egua':
38
+ this.interpretador = new InterpretadorEguaClassico(this, process.cwd());
39
+ this.lexador = new LexerEguaClassico(this);
40
+ this.avaliadorSintatico = new ParserEguaClassico(this);
41
+ this.resolvedor = new ResolverEguaClassico(this, this.interpretador);
42
+ console.log('Usando dialeto: Égua');
43
+ break;
44
+ case 'eguac':
45
+ this.interpretador = new Interpretador(this, process.cwd());
46
+ this.lexador = new Lexer(this);
47
+ this.avaliadorSintatico = new Parser(this);
48
+ this.resolvedor = new Resolver(this, this.interpretador);
49
+ console.log('Usando dialeto: ÉguaC');
50
+ break;
51
+ case 'eguap':
52
+ this.interpretador = new Interpretador(this, process.cwd());
53
+ this.lexador = new Lexer(this);
54
+ this.avaliadorSintatico = new Parser(this);
55
+ this.resolvedor = new Resolver(this, this.interpretador);
56
+ console.log('Usando dialeto: ÉguaP');
57
+ break;
58
+ default:
59
+ this.interpretador = new Interpretador(this, process.cwd());
60
+ this.lexador = new Lexer(this);
61
+ this.avaliadorSintatico = new Parser(this);
62
+ this.resolvedor = new Resolver(this, this.interpretador);
63
+ console.log('Usando dialeto: padrão');
64
+ break;
65
+ }
66
+ }
67
+
68
+ versao() {
69
+ return JSON.parse(fs.readFileSync('./package.json', { encoding: 'utf8' })).version || ''
70
+ }
71
+
72
+ iniciarDelegua() {
73
+ const interpretador = new Interpretador(this, process.cwd());
74
+ console.log(`Console da Linguagem Delégua v${this.versao()}`);
75
+ const leiaLinha = readline.createInterface({
76
+ input: process.stdin,
77
+ output: process.stdout,
78
+ prompt: "\ndelegua> "
79
+ });
80
+
81
+ leiaLinha.prompt();
82
+
83
+ leiaLinha.on("line", linha => {
84
+ this.teveErro = false;
85
+ this.teveErroEmTempoDeExecucao = false;
86
+
87
+ this.run(linha, interpretador);
88
+ leiaLinha.prompt();
89
+ });
90
+ }
91
+
92
+ carregarArquivo(nomeArquivo: any) {
93
+ this.nomeArquivo = caminho.basename(nomeArquivo);
94
+ const interpretador = new Interpretador(this, process.cwd());
95
+
96
+ const dadosDoArquivo = fs.readFileSync(nomeArquivo).toString();
97
+ this.run(dadosDoArquivo, interpretador);
98
+
99
+ if (this.teveErro) process.exit(65);
100
+ if (this.teveErroEmTempoDeExecucao) process.exit(70);
101
+ }
102
+
103
+ run(codigo: any, interpretador: any) {
104
+ const lexer = new Lexer(this);
105
+ const simbolos = lexer.scan(codigo);
106
+
107
+ if (this.teveErro === true) return;
108
+
109
+ const analisar = new Parser(this);
110
+ const declaracoes = analisar.analisar(simbolos);
111
+
112
+ if (this.teveErro === true) return;
113
+
114
+ const resolver = new Resolver(this, interpretador);
115
+ resolver.resolver(declaracoes);
116
+
117
+ if (this.teveErro === true) return;
118
+
119
+ interpretador.interpretar(declaracoes);
120
+ }
121
+
122
+ reportar(linha: any, onde: any, mensagem: any) {
123
+ if (this.nomeArquivo)
124
+ console.error(
125
+ `[Arquivo: ${this.nomeArquivo}] [Linha: ${linha}] Erro${onde}: ${mensagem}`
126
+ );
127
+ else console.error(`[Linha: ${linha}] Erro${onde}: ${mensagem}`);
128
+ this.teveErro = true;
129
+ }
130
+
131
+ erro(simbolo: any, mensagemDeErro: any) {
132
+ if (simbolo.tipo === tiposDeSimbolos.EOF) {
133
+ this.reportar(simbolo.line, " no final", mensagemDeErro);
134
+ } else {
135
+ this.reportar(simbolo.line, ` no '${simbolo.lexema}'`, mensagemDeErro);
136
+ }
137
+ }
138
+
139
+ lexerError(linha: any, caractere: any, mensagem: any) {
140
+ this.reportar(linha, ` no '${caractere}'`, mensagem);
141
+ }
142
+
143
+ erroEmTempoDeExecucao(erro: any) {
144
+ if (erro & erro.simbolo && erro.simbolo.linha) {
145
+ if (this.nomeArquivo)
146
+ console.error(
147
+ `Erro: [Arquivo: ${this.nomeArquivo}] [Linha: ${erro.simbolo.linha}] ${erro.mensagem}`
148
+ );
149
+ else console.error(`Erro: [Linha: ${erro.simbolo.linha}] ${erro.mensagem}`);
150
+ } else if (!(erro instanceof ReturnException)) { // TODO: Ao se livrar de ReturnException, remover isto.
151
+ console.error(`Erro: ${erro.mensagem}`);
152
+ }
153
+
154
+ this.teveErroEmTempoDeExecucao = true;
155
+ }
156
+ };
@@ -0,0 +1,11 @@
1
+ export class Callable {
2
+ valorAridade: any;
3
+
4
+ aridade() {
5
+ return this.valorAridade;
6
+ }
7
+
8
+ chamar(interpretador?: any, argumentos?: any, simbolo?: any) {
9
+ throw new Error("Este método não deveria ser chamado.");
10
+ }
11
+ }
@@ -1,15 +1,19 @@
1
- const Callable = require("./callable.js");
2
- const DeleguaInstancia = require("./instancia.js");
1
+ import { Callable } from "./callable";
2
+ import { DeleguaInstancia } from "./instancia";
3
3
 
4
- module.exports = class DeleguaClasse extends Callable {
5
- constructor(nome, superClasse, metodos) {
4
+ export class DeleguaClasse extends Callable {
5
+ nome: any;
6
+ superClasse: any;
7
+ metodos: any;
8
+
9
+ constructor(nome?: any, superClasse?: any, metodos?: any) {
6
10
  super();
7
11
  this.nome = nome;
8
12
  this.superClasse = superClasse;
9
13
  this.metodos = metodos;
10
14
  }
11
15
 
12
- encontrarMetodo(nome) {
16
+ encontrarMetodo(nome: any) {
13
17
  if (this.metodos.hasOwnProperty(nome)) {
14
18
  return this.metodos[nome];
15
19
  }
@@ -30,7 +34,7 @@ module.exports = class DeleguaClasse extends Callable {
30
34
  return inicializador ? inicializador.aridade() : 0;
31
35
  }
32
36
 
33
- call(interpretador, argumentos) {
37
+ chamar(interpretador: any, argumentos: any) {
34
38
  let instancia = new DeleguaInstancia(this);
35
39
 
36
40
  let inicializador = this.encontrarMetodo("construtor");
@@ -40,4 +44,4 @@ module.exports = class DeleguaClasse extends Callable {
40
44
 
41
45
  return instancia;
42
46
  }
43
- };
47
+ }
@@ -1,13 +1,17 @@
1
- const Callable = require("./callable.js");
1
+ import { Callable } from "./callable";
2
+
3
+ export class FuncaoPadrao extends Callable {
4
+ valorAridade: any;
5
+ funcao: any;
6
+ simbolo: any;
2
7
 
3
- module.exports = class FuncaoPadrao extends Callable {
4
8
  constructor(valorAridade, funcao) {
5
9
  super();
6
10
  this.valorAridade = valorAridade;
7
11
  this.funcao = funcao;
8
12
  }
9
13
 
10
- chamar(interpretador, argumentos, simbolo) {
14
+ chamar(interpretador: any, argumentos: any, simbolo: any) {
11
15
  this.simbolo = simbolo;
12
16
  return this.funcao.apply(this, argumentos);
13
17
  }
@@ -15,4 +19,4 @@ module.exports = class FuncaoPadrao extends Callable {
15
19
  toString() {
16
20
  return "<função>";
17
21
  }
18
- };
22
+ }
@@ -0,0 +1,70 @@
1
+ import { Callable } from "./callable";
2
+ import { Ambiente } from "../ambiente";
3
+ import { ReturnException } from "../excecoes";
4
+
5
+ export class DeleguaFuncao extends Callable {
6
+ nome: any;
7
+ declaracao: any;
8
+ closure: any;
9
+ eInicializador: any;
10
+
11
+ constructor(nome: any, declaracao: any, closure: any, eInicializador = false) {
12
+ super();
13
+ this.nome = nome;
14
+ this.declaracao = declaracao;
15
+ this.closure = closure;
16
+ this.eInicializador = eInicializador;
17
+ }
18
+
19
+ aridade() {
20
+ return this.declaracao?.parametros?.length || 0;
21
+ }
22
+
23
+ toString() {
24
+ if (this.nome === null) return "<função>";
25
+ return `<função ${this.nome}>`;
26
+ }
27
+
28
+ chamar(interpretador: any, argumentos: any) {
29
+ let ambiente = new Ambiente(this.closure);
30
+ let parametros = this.declaracao.parametros;
31
+
32
+ if (parametros && parametros.length) {
33
+ for (let i = 0; i < parametros.length; i++) {
34
+ const param = parametros[i];
35
+
36
+ const nome = param["nome"].lexema;
37
+ let valor = argumentos[i];
38
+ if (argumentos[i] === null) {
39
+ valor = param["padrao"] ? param["padrao"].valor : null;
40
+ }
41
+ ambiente.definirVariavel(nome, valor);
42
+ }
43
+ }
44
+
45
+ try {
46
+ interpretador.executeBlock(this.declaracao.funcao, ambiente);
47
+ } catch (erro) {
48
+ if (erro instanceof ReturnException) {
49
+ if (this.eInicializador) return this.closure.obterVariavelEm(0, "isto");
50
+ return erro.valor;
51
+ } else {
52
+ throw erro;
53
+ }
54
+ }
55
+
56
+ if (this.eInicializador) return this.closure.obterVariavelEm(0, "isto");
57
+ return null;
58
+ }
59
+
60
+ bind(instancia: any) {
61
+ let ambiente = new Ambiente(this.closure);
62
+ ambiente.definirVariavel("isto", instancia);
63
+ return new DeleguaFuncao(
64
+ this.nome,
65
+ this.declaracao,
66
+ ambiente,
67
+ this.eInicializador
68
+ );
69
+ }
70
+ }
@@ -0,0 +1,6 @@
1
+ export * from "./callable";
2
+ export * from "./classe";
3
+ export * from "./funcao-padrao";
4
+ export * from "./funcao";
5
+ export * from "./instancia";
6
+ export * from "./modulo";
@@ -1,27 +1,30 @@
1
- const ErroEmTempoDeExecucao = require("../erro.js").ErroEmTempoDeExecucao;
1
+ import { ErroEmTempoDeExecucao } from "../excecoes";
2
+
3
+ export class DeleguaInstancia {
4
+ criarClasse: any;
5
+ campos: any;
2
6
 
3
- module.exports = class DeleguaInstancia {
4
7
  constructor(criarClasse) {
5
8
  this.criarClasse = criarClasse;
6
9
  this.campos = {};
7
10
  }
8
11
 
9
- get(nome) {
10
- if (this.campos.hasOwnProperty(nome.lexeme)) {
11
- return this.campos[nome.lexeme];
12
+ get(nome: any) {
13
+ if (this.campos.hasOwnProperty(nome.lexema)) {
14
+ return this.campos[nome.lexema];
12
15
  }
13
16
 
14
- let metodo = this.criarClasse.encontrarMetodo(nome.lexeme);
17
+ let metodo = this.criarClasse.encontrarMetodo(nome.lexema);
15
18
  if (metodo) return metodo.bind(this);
16
19
 
17
20
  throw new ErroEmTempoDeExecucao(nome, "Método indefinido não recuperado.");
18
21
  }
19
22
 
20
- set(nome, valor) {
21
- this.campos[nome.lexeme] = valor;
23
+ set(nome: any, valor: any) {
24
+ this.campos[nome.lexema] = valor;
22
25
  }
23
26
 
24
27
  toString() {
25
28
  return "<Objeto " + this.criarClasse.nome + ">";
26
29
  }
27
- };
30
+ }
@@ -0,0 +1,11 @@
1
+ export class DeleguaModulo {
2
+ nome: string;
3
+
4
+ constructor(nome?: string) {
5
+ if (nome) this.nome = nome;
6
+ }
7
+
8
+ toString() {
9
+ return this.nome ? `<modulo ${this.nome}>` : "<modulo>";
10
+ }
11
+ }
@@ -0,0 +1 @@
1
+ export class BreakException extends Error { }
@@ -0,0 +1 @@
1
+ export class ContinueException extends Error { }
@@ -0,0 +1,11 @@
1
+ export class ErroEmTempoDeExecucao extends Error {
2
+ simbolo: any;
3
+ mensagem: string;
4
+
5
+ constructor(simbolo?: any, mensagem?: string) {
6
+ super(mensagem);
7
+ this.simbolo = simbolo;
8
+ this.mensagem = mensagem;
9
+ Object.setPrototypeOf(this, ErroEmTempoDeExecucao.prototype);
10
+ }
11
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./break-exception";
2
+ export * from "./continue-exception";
3
+ export * from "./erro-em-tempo-de-execucao";
4
+ export * from "./return-exception";
@@ -0,0 +1,10 @@
1
+
2
+ export class ReturnException extends Error {
3
+ valor: any;
4
+
5
+ constructor(valor: any) {
6
+ super(valor);
7
+ this.valor = valor;
8
+ Object.setPrototypeOf(this, ReturnException.prototype);
9
+ }
10
+ }