@designliquido/delegua 0.29.4 → 0.30.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.
Files changed (59) hide show
  1. package/bin/package.json +1 -1
  2. package/fontes/analisador-semantico/dialetos/analisador-semantico-birl.d.ts +2 -2
  3. package/fontes/analisador-semantico/dialetos/analisador-semantico-mapler.d.ts +2 -11
  4. package/fontes/analisador-semantico/dialetos/analisador-semantico-mapler.js.map +1 -1
  5. package/fontes/analisador-semantico/dialetos/analisador-semantico-visualg.d.ts +72 -0
  6. package/fontes/analisador-semantico/dialetos/analisador-semantico-visualg.js +280 -0
  7. package/fontes/analisador-semantico/dialetos/analisador-semantico-visualg.js.map +1 -0
  8. package/fontes/analisador-semantico/dialetos/index.d.ts +1 -0
  9. package/fontes/analisador-semantico/dialetos/index.js +1 -0
  10. package/fontes/analisador-semantico/dialetos/index.js.map +1 -1
  11. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-birl.js +2 -2
  12. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-birl.js.map +1 -1
  13. package/fontes/avaliador-sintatico/dialetos/potigol/avaliador-sintatico-potigol.js +1 -1
  14. package/fontes/avaliador-sintatico/dialetos/potigol/avaliador-sintatico-potigol.js.map +1 -1
  15. package/fontes/avaliador-sintatico/dialetos/visualg/avaliador-sintatico-visualg.d.ts +3 -0
  16. package/fontes/avaliador-sintatico/dialetos/visualg/avaliador-sintatico-visualg.js +32 -4
  17. package/fontes/avaliador-sintatico/dialetos/visualg/avaliador-sintatico-visualg.js.map +1 -1
  18. package/fontes/construtos/definir-valor.d.ts +4 -4
  19. package/fontes/construtos/definir-valor.js.map +1 -1
  20. package/fontes/construtos/funcao.d.ts +3 -2
  21. package/fontes/construtos/funcao.js.map +1 -1
  22. package/fontes/declaracoes/enquanto.d.ts +3 -2
  23. package/fontes/declaracoes/enquanto.js.map +1 -1
  24. package/fontes/declaracoes/fazer.d.ts +4 -2
  25. package/fontes/declaracoes/fazer.js.map +1 -1
  26. package/fontes/declaracoes/para.d.ts +2 -2
  27. package/fontes/declaracoes/tente.d.ts +2 -2
  28. package/fontes/formatadores/formatador-delegua.d.ts +72 -0
  29. package/fontes/formatadores/formatador-delegua.js +644 -0
  30. package/fontes/formatadores/formatador-delegua.js.map +1 -0
  31. package/fontes/formatadores/index.d.ts +1 -1
  32. package/fontes/formatadores/index.js +1 -1
  33. package/fontes/formatadores/index.js.map +1 -1
  34. package/fontes/interfaces/dialetos/interpretador-birl-interface.js.map +1 -0
  35. package/fontes/interfaces/funcao-hipotetica-interface.d.ts +3 -0
  36. package/fontes/interfaces/funcao-hipotetica-interface.js +3 -0
  37. package/fontes/interfaces/funcao-hipotetica-interface.js.map +1 -0
  38. package/fontes/interfaces/tipos-dados-interface.d.ts +1 -1
  39. package/fontes/interfaces/variavel-hipotetica-interface.d.ts +7 -0
  40. package/fontes/interfaces/variavel-hipotetica-interface.js +3 -0
  41. package/fontes/interfaces/variavel-hipotetica-interface.js.map +1 -0
  42. package/fontes/interpretador/dialetos/birl/comum.d.ts +1 -1
  43. package/fontes/interpretador/dialetos/birl/interpretador-birl-com-depuracao.d.ts +1 -1
  44. package/fontes/interpretador/dialetos/egua-classico/interpretador-egua-classico.d.ts +1 -1
  45. package/fontes/interpretador/dialetos/egua-classico/interpretador-egua-classico.js.map +1 -1
  46. package/fontes/interpretador/dialetos/visualg/comum.d.ts +3 -1
  47. package/fontes/interpretador/dialetos/visualg/comum.js +69 -1
  48. package/fontes/interpretador/dialetos/visualg/comum.js.map +1 -1
  49. package/fontes/interpretador/dialetos/visualg/interpretador-visualg-com-depuracao.js +2 -63
  50. package/fontes/interpretador/dialetos/visualg/interpretador-visualg-com-depuracao.js.map +1 -1
  51. package/fontes/interpretador/dialetos/visualg/interpretador-visualg.js +2 -63
  52. package/fontes/interpretador/dialetos/visualg/interpretador-visualg.js.map +1 -1
  53. package/package.json +1 -1
  54. package/fontes/formatadores/delegua.d.ts +0 -18
  55. package/fontes/formatadores/delegua.js +0 -83
  56. package/fontes/formatadores/delegua.js.map +0 -1
  57. package/fontes/interfaces/dialeto/interpretador-birl-interface.js.map +0 -1
  58. /package/fontes/interfaces/{dialeto → dialetos}/interpretador-birl-interface.d.ts +0 -0
  59. /package/fontes/interfaces/{dialeto → dialetos}/interpretador-birl-interface.js +0 -0
@@ -0,0 +1,644 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.FormatadorDelegua = void 0;
7
+ const construtos_1 = require("../construtos");
8
+ const delegua_1 = __importDefault(require("../tipos-de-simbolos/delegua"));
9
+ /**
10
+ * O formatador de código Delégua.
11
+ * Normalmente usado por IDEs, mas pode ser usado por linha de comando ou programaticamente.
12
+ */
13
+ class FormatadorDelegua {
14
+ constructor(quebraLinha, tamanhoIndentacao = 4) {
15
+ this.quebraLinha = quebraLinha;
16
+ this.tamanhoIndentacao = tamanhoIndentacao;
17
+ this.indentacaoAtual = 0;
18
+ this.codigoFormatado = '';
19
+ this.devePularLinha = true;
20
+ this.deveIndentar = true;
21
+ }
22
+ visitarDeclaracaoClasse(declaracao) {
23
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}classe ${declaracao.simbolo.lexema} {${this.quebraLinha}`;
24
+ this.indentacaoAtual += this.tamanhoIndentacao;
25
+ for (let propriedade of declaracao.propriedades) {
26
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}${propriedade.nome.lexema}: ${propriedade.tipo || 'qualquer'}${this.quebraLinha}`;
27
+ }
28
+ this.codigoFormatado += `${this.quebraLinha}`;
29
+ for (let metodo of declaracao.metodos) {
30
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}${metodo.simbolo.lexema}`;
31
+ this.visitarExpressaoFuncaoConstruto(metodo.funcao);
32
+ }
33
+ this.indentacaoAtual -= this.tamanhoIndentacao;
34
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}}${this.quebraLinha}`;
35
+ }
36
+ visitarDeclaracaoConst(declaracao) {
37
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}constante ${declaracao.simbolo.lexema}`;
38
+ if (declaracao.inicializador) {
39
+ this.codigoFormatado += ` = `;
40
+ this.formatarDeclaracaoOuConstruto(declaracao.inicializador);
41
+ }
42
+ if (this.devePularLinha) {
43
+ this.codigoFormatado += this.quebraLinha;
44
+ }
45
+ }
46
+ visitarDeclaracaoConstMultiplo(declaracao) {
47
+ // TODO: Até então o código nunca passa por aqui, porque o avaliador sintático
48
+ // converte `ConstMultiplo` em várias declarações `const`.
49
+ // Talvez mudar a avaliação sintática para não fazer mais isso.
50
+ console.log(declaracao);
51
+ }
52
+ visitarDeclaracaoDeAtribuicao(expressao) {
53
+ if ([
54
+ delegua_1.default.MAIS_IGUAL,
55
+ delegua_1.default.MENOS_IGUAL,
56
+ delegua_1.default.MULTIPLICACAO_IGUAL,
57
+ delegua_1.default.DIVISAO_IGUAL,
58
+ delegua_1.default.DIVISAO_INTEIRA_IGUAL,
59
+ delegua_1.default.MODULO_IGUAL,
60
+ ].includes(expressao.valor.operador.tipo)) {
61
+ this.visitarExpressaoBinaria(expressao.valor);
62
+ }
63
+ else {
64
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}`;
65
+ this.codigoFormatado += `${expressao.simbolo.lexema} = `;
66
+ this.formatarDeclaracaoOuConstruto(expressao.valor);
67
+ }
68
+ this.codigoFormatado += `${this.quebraLinha}`;
69
+ }
70
+ visitarDeclaracaoDeExpressao(declaracao) {
71
+ this.codigoFormatado += ' '.repeat(this.indentacaoAtual);
72
+ this.formatarDeclaracaoOuConstruto(declaracao.expressao);
73
+ }
74
+ visitarDeclaracaoDefinicaoFuncao(declaracao) {
75
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}função `;
76
+ if (declaracao.simbolo) {
77
+ this.codigoFormatado += `${declaracao.simbolo.lexema}`;
78
+ }
79
+ this.formatarDeclaracaoOuConstruto(declaracao.funcao);
80
+ }
81
+ visitarDeclaracaoEnquanto(declaracao) {
82
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}enquanto `;
83
+ this.formatarDeclaracaoOuConstruto(declaracao.condicao);
84
+ this.formatarDeclaracaoOuConstruto(declaracao.corpo);
85
+ }
86
+ visitarDeclaracaoEscolha(declaracao) {
87
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}escolha `;
88
+ this.formatarDeclaracaoOuConstruto(declaracao.identificadorOuLiteral);
89
+ this.codigoFormatado += ` {${this.quebraLinha}`;
90
+ this.indentacaoAtual += this.tamanhoIndentacao;
91
+ for (let caminho of declaracao.caminhos) {
92
+ for (let declaracoes of caminho.condicoes) {
93
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}caso `;
94
+ this.formatarDeclaracaoOuConstruto(declaracoes);
95
+ this.codigoFormatado += ':';
96
+ this.codigoFormatado += this.quebraLinha;
97
+ }
98
+ for (let declaracoes of caminho.declaracoes) {
99
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}`;
100
+ this.formatarDeclaracaoOuConstruto(declaracoes);
101
+ }
102
+ }
103
+ for (let padrao of declaracao.caminhoPadrao.declaracoes) {
104
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}padrao:`;
105
+ this.codigoFormatado += this.quebraLinha;
106
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}`;
107
+ this.formatarDeclaracaoOuConstruto(padrao);
108
+ }
109
+ this.indentacaoAtual -= this.tamanhoIndentacao;
110
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}}${this.quebraLinha}`;
111
+ }
112
+ visitarDeclaracaoEscreva(declaracao) {
113
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}escreva(`;
114
+ for (let argumento of declaracao.argumentos) {
115
+ this.formatarDeclaracaoOuConstruto(argumento);
116
+ }
117
+ this.codigoFormatado += `)${this.quebraLinha}`;
118
+ }
119
+ visitarDeclaracaoFazer(declaracao) {
120
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}fazer {${this.quebraLinha}`;
121
+ this.indentacaoAtual += this.tamanhoIndentacao;
122
+ for (let declaracaoBloco of declaracao.caminhoFazer.declaracoes) {
123
+ this.formatarDeclaracaoOuConstruto(declaracaoBloco);
124
+ }
125
+ this.indentacaoAtual -= this.tamanhoIndentacao;
126
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}} enquanto `;
127
+ this.formatarDeclaracaoOuConstruto(declaracao.condicaoEnquanto);
128
+ this.codigoFormatado += `${this.quebraLinha}`;
129
+ }
130
+ visitarDeclaracaoImportar(declaracao) {
131
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}importar(`;
132
+ this.formatarDeclaracaoOuConstruto(declaracao.caminho);
133
+ this.codigoFormatado += `)`;
134
+ }
135
+ visitarDeclaracaoPara(declaracao) {
136
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}para `;
137
+ this.devePularLinha = false;
138
+ if (declaracao.inicializador) {
139
+ if (Array.isArray(declaracao.inicializador)) {
140
+ this.deveIndentar = false;
141
+ for (let declaracaoInicializador of declaracao.inicializador) {
142
+ this.formatarDeclaracaoOuConstruto(declaracaoInicializador);
143
+ }
144
+ this.deveIndentar = true;
145
+ }
146
+ else {
147
+ this.formatarDeclaracaoOuConstruto(declaracao.inicializador);
148
+ }
149
+ }
150
+ this.codigoFormatado += `; `;
151
+ this.formatarDeclaracaoOuConstruto(declaracao.condicao);
152
+ this.codigoFormatado += `; `;
153
+ this.formatarDeclaracaoOuConstruto(declaracao.incrementar);
154
+ this.devePularLinha = true;
155
+ this.codigoFormatado += ` {${this.quebraLinha}`;
156
+ this.indentacaoAtual += this.tamanhoIndentacao;
157
+ for (let declaracaoBloco of declaracao.corpo.declaracoes) {
158
+ this.formatarDeclaracaoOuConstruto(declaracaoBloco);
159
+ }
160
+ this.indentacaoAtual -= this.tamanhoIndentacao;
161
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}}${this.quebraLinha}`;
162
+ }
163
+ visitarDeclaracaoParaCada(declaracao) {
164
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}para cada ${declaracao.nomeVariavelIteracao} de ${declaracao.vetor.simbolo.lexema}`;
165
+ this.visitarExpressaoBloco(declaracao.corpo);
166
+ }
167
+ visitarDeclaracaoSe(declaracao) {
168
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}se `;
169
+ this.formatarDeclaracaoOuConstruto(declaracao.condicao);
170
+ this.codigoFormatado += ` {${this.quebraLinha}`;
171
+ this.indentacaoAtual += this.tamanhoIndentacao;
172
+ for (let declaracaoBloco of declaracao.caminhoEntao.declaracoes) {
173
+ this.formatarDeclaracaoOuConstruto(declaracaoBloco);
174
+ }
175
+ this.indentacaoAtual -= this.tamanhoIndentacao;
176
+ if (declaracao.caminhoSenao) {
177
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}} senão {${this.quebraLinha}`;
178
+ this.indentacaoAtual += this.tamanhoIndentacao;
179
+ for (let declaracaoBloco of declaracao.caminhoSenao.declaracoes) {
180
+ this.formatarDeclaracaoOuConstruto(declaracaoBloco);
181
+ }
182
+ this.indentacaoAtual -= this.tamanhoIndentacao;
183
+ }
184
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}}${this.quebraLinha}`;
185
+ }
186
+ visitarDeclaracaoTente(declaracao) {
187
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}tente {${this.quebraLinha}`;
188
+ this.indentacaoAtual += this.tamanhoIndentacao;
189
+ for (let declaracaoBloco of declaracao.caminhoTente) {
190
+ this.formatarDeclaracaoOuConstruto(declaracaoBloco);
191
+ }
192
+ this.indentacaoAtual -= this.tamanhoIndentacao;
193
+ if (declaracao.caminhoPegue) {
194
+ this.codigoFormatado += `} pegue {${this.quebraLinha}`;
195
+ if (declaracao.caminhoPegue instanceof construtos_1.FuncaoConstruto) {
196
+ // Se tem um parâmetro de erro.
197
+ }
198
+ else {
199
+ // Se não tem um parâmetro de erro.
200
+ this.indentacaoAtual += this.tamanhoIndentacao;
201
+ for (let declaracaoBloco of declaracao.caminhoPegue) {
202
+ this.formatarDeclaracaoOuConstruto(declaracaoBloco);
203
+ }
204
+ }
205
+ }
206
+ this.indentacaoAtual -= this.tamanhoIndentacao;
207
+ if (declaracao.caminhoFinalmente) {
208
+ this.codigoFormatado += `} finalmente {${this.quebraLinha}`;
209
+ this.indentacaoAtual += this.tamanhoIndentacao;
210
+ for (let declaracaoBloco of declaracao.caminhoFinalmente) {
211
+ this.formatarDeclaracaoOuConstruto(declaracaoBloco);
212
+ }
213
+ }
214
+ this.indentacaoAtual -= this.tamanhoIndentacao;
215
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}}${this.quebraLinha}`;
216
+ }
217
+ visitarDeclaracaoVar(declaracao) {
218
+ if (this.deveIndentar) {
219
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}`;
220
+ }
221
+ this.codigoFormatado += `var ${declaracao.simbolo.lexema}`;
222
+ if (declaracao.inicializador) {
223
+ this.codigoFormatado += ` = `;
224
+ this.formatarDeclaracaoOuConstruto(declaracao.inicializador);
225
+ }
226
+ if (this.devePularLinha) {
227
+ this.codigoFormatado += this.quebraLinha;
228
+ }
229
+ }
230
+ visitarDeclaracaoVarMultiplo(declaracao) {
231
+ // TODO: Até então o código nunca passa por aqui, porque o avaliador sintático
232
+ // converte `VarMultiplo` em várias declarações `var`.
233
+ // Talvez mudar a avaliação sintática para não fazer mais isso.
234
+ console.log(declaracao);
235
+ }
236
+ visitarExpressaoAcessoIndiceVariavel(expressao) {
237
+ this.formatarDeclaracaoOuConstruto(expressao.entidadeChamada);
238
+ this.codigoFormatado += `[`;
239
+ this.formatarDeclaracaoOuConstruto(expressao.indice);
240
+ this.codigoFormatado += `]`;
241
+ }
242
+ visitarExpressaoAcessoMetodo(expressao) {
243
+ this.formatarDeclaracaoOuConstruto(expressao.objeto);
244
+ this.codigoFormatado += '.';
245
+ this.codigoFormatado += expressao.simbolo.lexema;
246
+ }
247
+ visitarExpressaoAgrupamento(expressao) {
248
+ this.codigoFormatado += '(';
249
+ this.formatarDeclaracaoOuConstruto(expressao.expressao);
250
+ this.codigoFormatado += ')';
251
+ }
252
+ visitarExpressaoAtribuicaoPorIndice(expressao) {
253
+ this.formatarDeclaracaoOuConstruto(expressao.objeto);
254
+ this.codigoFormatado += '[';
255
+ this.formatarDeclaracaoOuConstruto(expressao.indice);
256
+ this.codigoFormatado += '] = ';
257
+ this.formatarDeclaracaoOuConstruto(expressao.valor);
258
+ this.codigoFormatado += this.quebraLinha;
259
+ }
260
+ visitarExpressaoAtribuicaoPorIndicesMatriz(expressao) {
261
+ // Implementar somente para VisuAlg que tem atribuição diferente de Delégua - matriz[1, 2] = 1
262
+ throw new Error('Método não implementado.');
263
+ }
264
+ visitarExpressaoAcessoElementoMatriz(expressao) {
265
+ // Implementar somente para VisuAlg que tem acesso ao elemento da matriz diferente de Delégua - var valor = matriz[1, 2]
266
+ throw new Error('Método não implementado.');
267
+ }
268
+ visitarExpressaoBinaria(expressao) {
269
+ this.formatarDeclaracaoOuConstruto(expressao.esquerda);
270
+ switch (expressao.operador.tipo) {
271
+ case delegua_1.default.ADICAO:
272
+ this.codigoFormatado += ` + `;
273
+ break;
274
+ case delegua_1.default.DIVISAO:
275
+ this.codigoFormatado += ` / `;
276
+ break;
277
+ case delegua_1.default.DIVISAO_IGUAL:
278
+ this.codigoFormatado += ` /= `;
279
+ break;
280
+ case delegua_1.default.DIVISAO_INTEIRA:
281
+ this.codigoFormatado += ` \\ `;
282
+ break;
283
+ case delegua_1.default.DIVISAO_INTEIRA_IGUAL:
284
+ this.codigoFormatado += ` \\= `;
285
+ break;
286
+ case delegua_1.default.EXPONENCIACAO:
287
+ this.codigoFormatado += ` ** `;
288
+ break;
289
+ case delegua_1.default.IGUAL_IGUAL:
290
+ this.codigoFormatado += ` == `;
291
+ break;
292
+ case delegua_1.default.MAIOR:
293
+ this.codigoFormatado += ` > `;
294
+ break;
295
+ case delegua_1.default.MAIOR_IGUAL:
296
+ this.codigoFormatado += ` >= `;
297
+ break;
298
+ case delegua_1.default.MAIS_IGUAL:
299
+ this.codigoFormatado += ` += `;
300
+ break;
301
+ case delegua_1.default.MENOR:
302
+ this.codigoFormatado += ` < `;
303
+ break;
304
+ case delegua_1.default.MENOR_IGUAL:
305
+ this.codigoFormatado += ` <= `;
306
+ break;
307
+ case delegua_1.default.MENOS_IGUAL:
308
+ this.codigoFormatado += ` -= `;
309
+ break;
310
+ case delegua_1.default.MODULO:
311
+ this.codigoFormatado += ` % `;
312
+ break;
313
+ case delegua_1.default.MODULO_IGUAL:
314
+ this.codigoFormatado += ` %= `;
315
+ break;
316
+ case delegua_1.default.MULTIPLICACAO:
317
+ this.codigoFormatado += ` * `;
318
+ break;
319
+ case delegua_1.default.MULTIPLICACAO_IGUAL:
320
+ this.codigoFormatado += ` * `;
321
+ break;
322
+ case delegua_1.default.SUBTRACAO:
323
+ this.codigoFormatado += ` - `;
324
+ break;
325
+ }
326
+ this.formatarDeclaracaoOuConstruto(expressao.direita);
327
+ }
328
+ formatarBlocoOuVetorDeclaracoes(declaracoes) {
329
+ this.codigoFormatado += ` {${this.quebraLinha}`;
330
+ this.indentacaoAtual += this.tamanhoIndentacao;
331
+ for (let declaracaoBloco of declaracoes) {
332
+ this.formatarDeclaracaoOuConstruto(declaracaoBloco);
333
+ }
334
+ this.indentacaoAtual -= this.tamanhoIndentacao;
335
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}}${this.quebraLinha}`;
336
+ }
337
+ visitarExpressaoBloco(declaracao) {
338
+ this.formatarBlocoOuVetorDeclaracoes(declaracao.declaracoes);
339
+ }
340
+ visitarExpressaoContinua(declaracao) {
341
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}continua${this.quebraLinha}`;
342
+ }
343
+ visitarExpressaoDeChamada(expressao) {
344
+ this.formatarDeclaracaoOuConstruto(expressao.entidadeChamada);
345
+ this.codigoFormatado += '(';
346
+ for (let argumento of expressao.argumentos) {
347
+ this.formatarDeclaracaoOuConstruto(argumento);
348
+ this.codigoFormatado += ', ';
349
+ }
350
+ if (expressao.argumentos.length > 0) {
351
+ this.codigoFormatado = this.codigoFormatado.slice(0, -2);
352
+ }
353
+ this.codigoFormatado += ')';
354
+ }
355
+ visitarExpressaoDefinirValor(expressao) {
356
+ this.formatarDeclaracaoOuConstruto(expressao.objeto);
357
+ this.codigoFormatado += `.${expressao.nome.lexema} = `;
358
+ this.formatarDeclaracaoOuConstruto(expressao.valor);
359
+ this.codigoFormatado += `${this.quebraLinha}`;
360
+ }
361
+ visitarExpressaoDeleguaFuncao(expressao) {
362
+ throw new Error('Método não implementado.');
363
+ }
364
+ visitarExpressaoDeVariavel(expressao) {
365
+ this.codigoFormatado += expressao.simbolo.lexema;
366
+ }
367
+ visitarExpressaoDicionario(expressao) {
368
+ this.codigoFormatado += `{`;
369
+ for (let i = 0; i < expressao.chaves.length; i++) {
370
+ this.formatarDeclaracaoOuConstruto(expressao.chaves[i]);
371
+ this.codigoFormatado += `: `;
372
+ this.formatarDeclaracaoOuConstruto(expressao.valores[i]);
373
+ this.codigoFormatado += `, `;
374
+ }
375
+ if (expressao.chaves.length > 0) {
376
+ this.codigoFormatado = this.codigoFormatado.slice(0, -2);
377
+ }
378
+ this.codigoFormatado += `}`;
379
+ }
380
+ visitarExpressaoExpressaoRegular(expressao) {
381
+ this.codigoFormatado += `||${expressao.valor}||`;
382
+ }
383
+ visitarDeclaracaoEscrevaMesmaLinha(declaracao) {
384
+ throw new Error('Método não implementado.');
385
+ }
386
+ visitarExpressaoFalhar(expressao) {
387
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}falhar`;
388
+ if (expressao.explicacao) {
389
+ this.codigoFormatado += ` `;
390
+ this.formatarDeclaracaoOuConstruto(expressao.explicacao);
391
+ }
392
+ this.codigoFormatado += `${this.quebraLinha}`;
393
+ }
394
+ visitarExpressaoFimPara(declaracao) {
395
+ throw new Error('Método não implementado.');
396
+ }
397
+ visitarExpressaoFormatacaoEscrita(declaracao) {
398
+ throw new Error('Método não implementado.');
399
+ }
400
+ visitarExpressaoFuncaoConstruto(expressao) {
401
+ this.codigoFormatado += `(`;
402
+ for (let argumento of expressao.parametros) {
403
+ this.codigoFormatado += `${argumento.nome.lexema}${argumento.tipoDado && argumento.tipoDado.tipo ? `: ${argumento.tipoDado.tipo}, ` : ', '}`;
404
+ }
405
+ if (expressao.parametros.length > 0) {
406
+ this.codigoFormatado = this.codigoFormatado.slice(0, -2);
407
+ }
408
+ this.codigoFormatado += `) `;
409
+ this.formatarBlocoOuVetorDeclaracoes(expressao.corpo);
410
+ }
411
+ visitarExpressaoIsto(expressao) {
412
+ this.codigoFormatado += `isto`;
413
+ }
414
+ visitarExpressaoLeia(expressao) {
415
+ this.codigoFormatado += `leia(`;
416
+ for (let argumento of expressao.argumentos) {
417
+ this.formatarDeclaracaoOuConstruto(argumento);
418
+ this.codigoFormatado += `, `;
419
+ }
420
+ if (expressao.argumentos.length > 0) {
421
+ this.codigoFormatado = this.codigoFormatado.slice(0, -2);
422
+ }
423
+ this.codigoFormatado += `)`;
424
+ }
425
+ visitarExpressaoLeiaMultiplo(expressao) {
426
+ throw new Error('Método não implementado.');
427
+ }
428
+ visitarExpressaoLiteral(expressao) {
429
+ if (typeof expressao.valor === 'string') {
430
+ this.codigoFormatado += `'${expressao.valor}'`;
431
+ return;
432
+ }
433
+ this.codigoFormatado += expressao.valor;
434
+ }
435
+ visitarExpressaoLogica(expressao) {
436
+ this.formatarDeclaracaoOuConstruto(expressao.esquerda);
437
+ switch (expressao.operador.tipo) {
438
+ case delegua_1.default.E:
439
+ this.codigoFormatado += ` e `;
440
+ break;
441
+ case delegua_1.default.EM:
442
+ this.codigoFormatado += ` em `;
443
+ break;
444
+ case delegua_1.default.OU:
445
+ this.codigoFormatado += ` ou `;
446
+ break;
447
+ }
448
+ this.formatarDeclaracaoOuConstruto(expressao.direita);
449
+ }
450
+ visitarExpressaoRetornar(declaracao) {
451
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}retorna`;
452
+ if (declaracao.valor) {
453
+ this.codigoFormatado += ` `;
454
+ this.formatarDeclaracaoOuConstruto(declaracao.valor);
455
+ }
456
+ this.codigoFormatado += `${this.quebraLinha}`;
457
+ }
458
+ visitarExpressaoSuper(expressao) {
459
+ // TODO: `expressao.metodo` deveria ser um `Construto`, não um `Simbolo` aqui.
460
+ this.codigoFormatado += `super.${expressao.metodo.lexema}()`;
461
+ console.log(expressao);
462
+ }
463
+ visitarExpressaoSustar(declaracao) {
464
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}sustar${this.quebraLinha}`;
465
+ }
466
+ visitarExpressaoTipoDe(expressao) {
467
+ this.codigoFormatado += `tipo de `;
468
+ this.formatarDeclaracaoOuConstruto(expressao.valor);
469
+ }
470
+ visitarExpressaoUnaria(expressao) {
471
+ let operador;
472
+ switch (expressao.operador.tipo) {
473
+ case delegua_1.default.INCREMENTAR:
474
+ operador = `++`;
475
+ break;
476
+ case delegua_1.default.DECREMENTAR:
477
+ operador = `--`;
478
+ break;
479
+ }
480
+ switch (expressao.incidenciaOperador) {
481
+ case 'ANTES':
482
+ this.codigoFormatado += operador;
483
+ this.formatarDeclaracaoOuConstruto(expressao.operando);
484
+ break;
485
+ case 'DEPOIS':
486
+ this.formatarDeclaracaoOuConstruto(expressao.operando);
487
+ this.codigoFormatado += operador;
488
+ break;
489
+ }
490
+ if (this.devePularLinha) {
491
+ this.codigoFormatado += this.quebraLinha;
492
+ }
493
+ }
494
+ visitarExpressaoVetor(expressao) {
495
+ this.codigoFormatado += '[';
496
+ for (let valor of expressao.valores) {
497
+ this.formatarDeclaracaoOuConstruto(valor);
498
+ this.codigoFormatado += ', ';
499
+ }
500
+ if (expressao.valores.length > 0) {
501
+ this.codigoFormatado = this.codigoFormatado.slice(0, -2);
502
+ }
503
+ this.codigoFormatado += ']';
504
+ }
505
+ formatarDeclaracaoOuConstruto(declaracaoOuConstruto) {
506
+ switch (declaracaoOuConstruto.constructor.name) {
507
+ case 'AcessoIndiceVariavel':
508
+ this.visitarExpressaoAcessoIndiceVariavel(declaracaoOuConstruto);
509
+ break;
510
+ case 'AcessoMetodoOuPropriedade':
511
+ this.visitarExpressaoAcessoMetodo(declaracaoOuConstruto);
512
+ break;
513
+ case 'Agrupamento':
514
+ this.visitarExpressaoAgrupamento(declaracaoOuConstruto);
515
+ break;
516
+ case 'AtribuicaoPorIndice':
517
+ this.visitarExpressaoAtribuicaoPorIndice(declaracaoOuConstruto);
518
+ break;
519
+ case 'Atribuir':
520
+ this.visitarDeclaracaoDeAtribuicao(declaracaoOuConstruto);
521
+ break;
522
+ case 'Binario':
523
+ this.visitarExpressaoBinaria(declaracaoOuConstruto);
524
+ break;
525
+ case 'Bloco':
526
+ this.visitarExpressaoBloco(declaracaoOuConstruto);
527
+ break;
528
+ case 'Chamada':
529
+ this.visitarExpressaoDeChamada(declaracaoOuConstruto);
530
+ break;
531
+ case 'Classe':
532
+ this.visitarDeclaracaoClasse(declaracaoOuConstruto);
533
+ break;
534
+ case 'Continua':
535
+ this.visitarExpressaoContinua(declaracaoOuConstruto);
536
+ break;
537
+ case 'DefinirValor':
538
+ this.visitarExpressaoDefinirValor(declaracaoOuConstruto);
539
+ break;
540
+ case 'Dicionario':
541
+ this.visitarExpressaoDicionario(declaracaoOuConstruto);
542
+ break;
543
+ case 'Escolha':
544
+ this.visitarDeclaracaoEscolha(declaracaoOuConstruto);
545
+ break;
546
+ case 'Enquanto':
547
+ this.visitarDeclaracaoEnquanto(declaracaoOuConstruto);
548
+ break;
549
+ case 'Escreva':
550
+ this.visitarDeclaracaoEscreva(declaracaoOuConstruto);
551
+ break;
552
+ case 'Expressao':
553
+ this.visitarDeclaracaoDeExpressao(declaracaoOuConstruto);
554
+ break;
555
+ case 'ExpressaoRegular':
556
+ this.visitarExpressaoExpressaoRegular(declaracaoOuConstruto);
557
+ break;
558
+ case 'Falhar':
559
+ this.visitarExpressaoFalhar(declaracaoOuConstruto);
560
+ break;
561
+ case 'Fazer':
562
+ this.visitarDeclaracaoFazer(declaracaoOuConstruto);
563
+ break;
564
+ case 'FuncaoConstruto':
565
+ this.visitarExpressaoFuncaoConstruto(declaracaoOuConstruto);
566
+ break;
567
+ case 'FuncaoDeclaracao':
568
+ this.visitarDeclaracaoDefinicaoFuncao(declaracaoOuConstruto);
569
+ break;
570
+ case 'Importar':
571
+ this.visitarDeclaracaoImportar(declaracaoOuConstruto);
572
+ break;
573
+ case 'Isto':
574
+ this.visitarExpressaoIsto(declaracaoOuConstruto);
575
+ break;
576
+ case 'Leia':
577
+ this.visitarExpressaoLeia(declaracaoOuConstruto);
578
+ break;
579
+ case 'Literal':
580
+ this.visitarExpressaoLiteral(declaracaoOuConstruto);
581
+ break;
582
+ case 'Logico':
583
+ this.visitarExpressaoLogica(declaracaoOuConstruto);
584
+ break;
585
+ case 'Para':
586
+ this.visitarDeclaracaoPara(declaracaoOuConstruto);
587
+ break;
588
+ case 'ParaCada':
589
+ this.visitarDeclaracaoParaCada(declaracaoOuConstruto);
590
+ break;
591
+ case 'Retorna':
592
+ this.visitarExpressaoRetornar(declaracaoOuConstruto);
593
+ break;
594
+ case 'Se':
595
+ this.visitarDeclaracaoSe(declaracaoOuConstruto);
596
+ break;
597
+ case 'Super':
598
+ this.visitarExpressaoSuper(declaracaoOuConstruto);
599
+ break;
600
+ case 'Sustar':
601
+ this.visitarExpressaoSustar(declaracaoOuConstruto);
602
+ break;
603
+ case 'Tente':
604
+ this.visitarDeclaracaoTente(declaracaoOuConstruto);
605
+ break;
606
+ case 'TipoDe':
607
+ this.visitarExpressaoTipoDe(declaracaoOuConstruto);
608
+ break;
609
+ case 'Unario':
610
+ this.visitarExpressaoUnaria(declaracaoOuConstruto);
611
+ break;
612
+ case 'Const':
613
+ this.visitarDeclaracaoConst(declaracaoOuConstruto);
614
+ break;
615
+ case 'Var':
616
+ this.visitarDeclaracaoVar(declaracaoOuConstruto);
617
+ break;
618
+ case 'Variavel':
619
+ this.visitarExpressaoDeVariavel(declaracaoOuConstruto);
620
+ break;
621
+ case 'Vetor':
622
+ this.visitarExpressaoVetor(declaracaoOuConstruto);
623
+ break;
624
+ default:
625
+ console.log(declaracaoOuConstruto.constructor.name);
626
+ break;
627
+ }
628
+ }
629
+ /**
630
+ * Devolve código formatado de acordo com os símbolos encontrados.
631
+ * @param {Declaracao[]} declaracoes Um vetor de declarações.
632
+ * @returns Código Delégua formatado.
633
+ */
634
+ formatar(declaracoes) {
635
+ this.codigoFormatado = '';
636
+ this.indentacaoAtual = 0;
637
+ for (let declaracao of declaracoes) {
638
+ this.formatarDeclaracaoOuConstruto(declaracao);
639
+ }
640
+ return this.codigoFormatado;
641
+ }
642
+ }
643
+ exports.FormatadorDelegua = FormatadorDelegua;
644
+ //# sourceMappingURL=formatador-delegua.js.map