@designliquido/potigol 0.8.18 → 0.9.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 (98) hide show
  1. package/analisador-semantico/analisador-semantico-potigol.d.ts +18 -3
  2. package/analisador-semantico/analisador-semantico-potigol.d.ts.map +1 -1
  3. package/analisador-semantico/analisador-semantico-potigol.js +255 -3
  4. package/analisador-semantico/analisador-semantico-potigol.js.map +1 -1
  5. package/avaliador-sintatico/avaliador-sintatico-potigol.d.ts +9 -2
  6. package/avaliador-sintatico/avaliador-sintatico-potigol.d.ts.map +1 -1
  7. package/avaliador-sintatico/avaliador-sintatico-potigol.js +147 -45
  8. package/avaliador-sintatico/avaliador-sintatico-potigol.js.map +1 -1
  9. package/bibliotecas/biblioteca-global.d.ts +2 -2
  10. package/bibliotecas/biblioteca-global.d.ts.map +1 -1
  11. package/bibliotecas/biblioteca-global.js +27 -4
  12. package/bibliotecas/biblioteca-global.js.map +1 -1
  13. package/bibliotecas/primitivas-cubo.d.ts +10 -0
  14. package/bibliotecas/primitivas-cubo.d.ts.map +1 -0
  15. package/bibliotecas/primitivas-cubo.js +14 -0
  16. package/bibliotecas/primitivas-cubo.js.map +1 -0
  17. package/bibliotecas/primitivas-matriz.d.ts +9 -0
  18. package/bibliotecas/primitivas-matriz.d.ts.map +1 -0
  19. package/bibliotecas/primitivas-matriz.js +13 -0
  20. package/bibliotecas/primitivas-matriz.js.map +1 -0
  21. package/bibliotecas/primitivas-numero.d.ts +2 -2
  22. package/bibliotecas/primitivas-numero.d.ts.map +1 -1
  23. package/bibliotecas/primitivas-numero.js +5 -1
  24. package/bibliotecas/primitivas-numero.js.map +1 -1
  25. package/bibliotecas/primitivas-texto.d.ts +29 -25
  26. package/bibliotecas/primitivas-texto.d.ts.map +1 -1
  27. package/bibliotecas/primitivas-texto.js +115 -4
  28. package/bibliotecas/primitivas-texto.js.map +1 -1
  29. package/bibliotecas/primitivas-vetor.d.ts +6 -3
  30. package/bibliotecas/primitivas-vetor.d.ts.map +1 -1
  31. package/bibliotecas/primitivas-vetor.js +49 -10
  32. package/bibliotecas/primitivas-vetor.js.map +1 -1
  33. package/declaracoes/alias-tipo.d.ts +11 -0
  34. package/declaracoes/alias-tipo.d.ts.map +1 -0
  35. package/declaracoes/alias-tipo.js +19 -0
  36. package/declaracoes/alias-tipo.js.map +1 -0
  37. package/declaracoes/index.d.ts +2 -0
  38. package/declaracoes/index.d.ts.map +1 -1
  39. package/declaracoes/index.js +2 -0
  40. package/declaracoes/index.js.map +1 -1
  41. package/declaracoes/para-gere.d.ts +16 -0
  42. package/declaracoes/para-gere.d.ts.map +1 -0
  43. package/declaracoes/para-gere.js +23 -0
  44. package/declaracoes/para-gere.js.map +1 -0
  45. package/formatador/formatador-potigol.d.ts +16 -12
  46. package/formatador/formatador-potigol.d.ts.map +1 -1
  47. package/formatador/formatador-potigol.js +262 -89
  48. package/formatador/formatador-potigol.js.map +1 -1
  49. package/interfaces/visitante-comum-potigol-interface.d.ts +3 -1
  50. package/interfaces/visitante-comum-potigol-interface.d.ts.map +1 -1
  51. package/interpretador/comum.d.ts +4 -2
  52. package/interpretador/comum.d.ts.map +1 -1
  53. package/interpretador/comum.js +159 -11
  54. package/interpretador/comum.js.map +1 -1
  55. package/interpretador/estruturas/cubo.d.ts +47 -0
  56. package/interpretador/estruturas/cubo.d.ts.map +1 -0
  57. package/interpretador/estruturas/cubo.js +106 -0
  58. package/interpretador/estruturas/cubo.js.map +1 -0
  59. package/interpretador/estruturas/index.d.ts +2 -0
  60. package/interpretador/estruturas/index.d.ts.map +1 -1
  61. package/interpretador/estruturas/index.js +2 -0
  62. package/interpretador/estruturas/index.js.map +1 -1
  63. package/interpretador/estruturas/matriz.d.ts +40 -0
  64. package/interpretador/estruturas/matriz.d.ts.map +1 -0
  65. package/interpretador/estruturas/matriz.js +84 -0
  66. package/interpretador/estruturas/matriz.js.map +1 -0
  67. package/interpretador/inferenciador.d.ts +1 -1
  68. package/interpretador/inferenciador.d.ts.map +1 -1
  69. package/interpretador/inferenciador.js +20 -2
  70. package/interpretador/inferenciador.js.map +1 -1
  71. package/interpretador/interpretador-potigol-com-depuracao.d.ts +5 -2
  72. package/interpretador/interpretador-potigol-com-depuracao.d.ts.map +1 -1
  73. package/interpretador/interpretador-potigol-com-depuracao.js +9 -0
  74. package/interpretador/interpretador-potigol-com-depuracao.js.map +1 -1
  75. package/interpretador/interpretador-potigol.d.ts +7 -2
  76. package/interpretador/interpretador-potigol.d.ts.map +1 -1
  77. package/interpretador/interpretador-potigol.js +44 -0
  78. package/interpretador/interpretador-potigol.js.map +1 -1
  79. package/lexador/lexador-potigol.d.ts.map +1 -1
  80. package/lexador/lexador-potigol.js +13 -1
  81. package/lexador/lexador-potigol.js.map +1 -1
  82. package/lexador/palavras-reservadas.d.ts +9 -0
  83. package/lexador/palavras-reservadas.d.ts.map +1 -1
  84. package/lexador/palavras-reservadas.js +9 -0
  85. package/lexador/palavras-reservadas.js.map +1 -1
  86. package/package.json +4 -4
  87. package/tipos-de-dados.d.ts +3 -0
  88. package/tipos-de-dados.d.ts.map +1 -1
  89. package/tipos-de-dados.js +3 -0
  90. package/tipos-de-dados.js.map +1 -1
  91. package/tipos-de-simbolos/lexico-regular.d.ts +8 -0
  92. package/tipos-de-simbolos/lexico-regular.d.ts.map +1 -1
  93. package/tipos-de-simbolos/lexico-regular.js +8 -0
  94. package/tipos-de-simbolos/lexico-regular.js.map +1 -1
  95. package/tipos-de-simbolos/micro-lexico.d.ts +1 -0
  96. package/tipos-de-simbolos/micro-lexico.d.ts.map +1 -1
  97. package/tipos-de-simbolos/micro-lexico.js +1 -0
  98. package/tipos-de-simbolos/micro-lexico.js.map +1 -1
@@ -18,33 +18,64 @@ class FormatadorPotigol {
18
18
  this.devePularLinha = true;
19
19
  this.deveIndentar = true;
20
20
  }
21
- /* istanbul ignore next */
21
+ normalizarTipo(tipo) {
22
+ if (!tipo) {
23
+ return undefined;
24
+ }
25
+ switch (tipo.toUpperCase()) {
26
+ case lexico_regular_1.default.TEXTO:
27
+ return 'Caractere';
28
+ case lexico_regular_1.default.INTEIRO:
29
+ return 'Inteiro';
30
+ case 'NUMERO':
31
+ case lexico_regular_1.default.REAL:
32
+ return 'Real';
33
+ case lexico_regular_1.default.LOGICO:
34
+ case lexico_regular_1.default.LÓGICO:
35
+ return 'Lógico';
36
+ default:
37
+ return tipo;
38
+ }
39
+ }
22
40
  visitarExpressaoTuplaN(expressao) {
23
- throw new Error('Método não implementado.');
41
+ this.codigoFormatado += '(';
42
+ for (let indice = 0; indice < expressao.elementos.length; indice++) {
43
+ this.formatarDeclaracaoOuConstruto(expressao.elementos[indice]);
44
+ if (indice < expressao.elementos.length - 1) {
45
+ this.codigoFormatado += ', ';
46
+ }
47
+ }
48
+ this.codigoFormatado += ')';
24
49
  }
25
50
  /* istanbul ignore next */
26
51
  visitarExpressaoAcessoIntervaloVariavel(expressao) {
27
- throw new Error('Método não implementado.');
52
+ // Fatiamento/slicing (a[1:5]) não é uma construção de Potigol. Use pegue() e descarte().
53
+ throw new Error('Fatiamento de intervalos não é uma construção de Potigol.');
28
54
  }
29
55
  /* istanbul ignore next */
30
56
  visitarDeclaracaoTextoDocumentacao(declaracao) {
31
- throw new Error('Método não implementado.');
57
+ // Documentação inline não existe em Potigol.
58
+ throw new Error('TextoDocumentacao não é uma construção de Potigol.');
32
59
  }
33
60
  /* istanbul ignore next */
34
61
  visitarExpressaoComentario(expressao) {
35
- throw new Error('Método não implementado.');
62
+ // Comentário como construto não existe em Potigol.
63
+ throw new Error('ComentarioComoConstruto não é uma construção de Potigol.');
36
64
  }
37
65
  /* istanbul ignore next */
38
66
  visitarExpressaoSeparador(expressao) {
39
- throw new Error('Método não implementado.');
67
+ // Separador não existe em Potigol.
68
+ throw new Error('Separador não é uma construção de Potigol.');
40
69
  }
41
70
  /* istanbul ignore next */
42
71
  visitarExpressaoArgumentoReferenciaFuncao(expressao) {
43
- throw new Error('Método não implementado.');
72
+ // Referência de argumento de função como construto não existe em Potigol.
73
+ throw new Error('ArgumentoReferenciaFuncao não é uma construção de Potigol.');
44
74
  }
45
75
  /* istanbul ignore next */
46
76
  visitarExpressaoReferenciaFuncao(expressao) {
47
- throw new Error('Método não implementado.');
77
+ // Referência de função como construto não existe em Potigol.
78
+ throw new Error('ReferenciaFuncao não é uma construção de Potigol.');
48
79
  }
49
80
  visitarDeclaracaoLeiaInteiro(declaracao) {
50
81
  this.codigoFormatado += 'leia_inteiro';
@@ -79,13 +110,13 @@ class FormatadorPotigol {
79
110
  this.codigoFormatado += ')';
80
111
  }
81
112
  }
82
- /* istanbul ignore next */
83
113
  visitarExpressaoAcessoMetodoOuPropriedade(expressao) {
84
- throw new Error('Método não implementado.');
114
+ this.formatarDeclaracaoOuConstruto(expressao.objeto);
115
+ this.codigoFormatado += `.${expressao.simbolo.lexema}`;
85
116
  }
86
- /* istanbul ignore next */
87
117
  visitarExpressaoAcessoPropriedade(expressao) {
88
- throw new Error('Método não implementado.');
118
+ this.formatarDeclaracaoOuConstruto(expressao.objeto);
119
+ this.codigoFormatado += `.${expressao.nomePropriedade}`;
89
120
  }
90
121
  visitarDeclaracaoReatribuicaoVariavel(declaracao) {
91
122
  if (this.deveIndentar) {
@@ -112,30 +143,56 @@ class FormatadorPotigol {
112
143
  }
113
144
  /* istanbul ignore next */
114
145
  visitarDeclaracaoTendoComo(declaracao) {
115
- throw new Error('Método não implementado.');
146
+ // TendoComo (with...as) não existe em Potigol.
147
+ throw new Error('TendoComo não é uma construção de Potigol.');
116
148
  }
117
149
  /* istanbul ignore next */
118
150
  visitarDeclaracaoInicioAlgoritmo(declaracao) {
119
- throw new Error('Método não implementado.');
151
+ // InicioAlgoritmo não existe em Potigol.
152
+ throw new Error('InicioAlgoritmo não é uma construção de Potigol.');
120
153
  }
121
154
  /* istanbul ignore next */
122
155
  visitarDeclaracaoCabecalhoPrograma(declaracao) {
123
- throw new Error('Método não implementado.');
156
+ // CabecalhoPrograma não existe em Potigol.
157
+ throw new Error('CabecalhoPrograma não é uma construção de Potigol.');
124
158
  }
125
- /* istanbul ignore next */
126
159
  visitarExpressaoTupla(expressao) {
127
- throw new Error('Método não implementado.');
160
+ const elementos = expressao.elementos;
161
+ if (Array.isArray(elementos)) {
162
+ this.codigoFormatado += '(';
163
+ for (let indice = 0; indice < elementos.length; indice++) {
164
+ this.formatarDeclaracaoOuConstruto(elementos[indice]);
165
+ if (indice < elementos.length - 1) {
166
+ this.codigoFormatado += ', ';
167
+ }
168
+ }
169
+ this.codigoFormatado += ')';
170
+ }
128
171
  }
129
172
  visitarDeclaracaoClasse(declaracao) {
130
- this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}tipo ${declaracao.simbolo.lexema}${this.quebraLinha}`;
131
- this.formatarBlocoOuVetorDeclaracoes(declaracao.propriedades);
132
- this.formatarBlocoOuVetorDeclaracoes(declaracao.metodos);
173
+ const prefixoAbstrato = declaracao.abstrata ? ' abstrato' : '';
174
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}tipo${prefixoAbstrato} ${declaracao.simbolo.lexema}${this.quebraLinha}`;
175
+ this.indentacaoAtual += this.tamanhoIndentacao;
176
+ for (const propriedade of declaracao.propriedades) {
177
+ this.formatarDeclaracaoOuConstruto(propriedade);
178
+ }
179
+ for (const metodo of declaracao.metodos) {
180
+ const tamanhoAntes = this.codigoFormatado.length;
181
+ this.formatarDeclaracaoOuConstruto(metodo);
182
+ if (this.codigoFormatado.length > tamanhoAntes && !this.codigoFormatado.endsWith(this.quebraLinha)) {
183
+ this.codigoFormatado += this.quebraLinha;
184
+ }
185
+ }
186
+ this.indentacaoAtual -= this.tamanhoIndentacao;
133
187
  this.codigoFormatado += `fim${this.quebraLinha}`;
134
188
  }
189
+ visitarDeclaracaoAliasTipo(declaracao) {
190
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}tipo ${declaracao.simbolo.lexema} = ${declaracao.tipoOriginal}${this.quebraLinha}`;
191
+ }
135
192
  visitarExpressaoPropriedadeClasse(expressao) {
136
193
  this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}${expressao.nome.lexema}: `;
137
194
  if (expressao.tipo) {
138
- this.codigoFormatado += `${expressao.tipo}`;
195
+ this.codigoFormatado += `${this.normalizarTipo(expressao.tipo)}`;
139
196
  }
140
197
  this.codigoFormatado += this.quebraLinha;
141
198
  }
@@ -145,21 +202,9 @@ class FormatadorPotigol {
145
202
  }
146
203
  this.codigoFormatado += `${declaracao.simbolo.lexema}`;
147
204
  if (declaracao.tipoExplicito) {
148
- switch (declaracao.tipo.toUpperCase()) {
149
- case lexico_regular_1.default.TEXTO:
150
- this.codigoFormatado += ': Caractere';
151
- break;
152
- case lexico_regular_1.default.INTEIRO:
153
- this.codigoFormatado += ': Inteiro';
154
- break;
155
- case 'NUMERO':
156
- case lexico_regular_1.default.REAL:
157
- this.codigoFormatado += ': Real';
158
- break;
159
- case lexico_regular_1.default.LOGICO:
160
- case lexico_regular_1.default.LÓGICO:
161
- this.codigoFormatado += ': Lógico';
162
- break;
205
+ const tipoNormalizado = this.normalizarTipo(declaracao.tipo);
206
+ if (tipoNormalizado) {
207
+ this.codigoFormatado += `: ${tipoNormalizado}`;
163
208
  }
164
209
  }
165
210
  if (declaracao.inicializador) {
@@ -172,9 +217,18 @@ class FormatadorPotigol {
172
217
  this.codigoFormatado += this.quebraLinha;
173
218
  }
174
219
  }
175
- /* istanbul ignore next */
176
220
  visitarDeclaracaoConstMultiplo(declaracao) {
177
- throw new Error('Método não implementado.');
221
+ if (this.deveIndentar) {
222
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}`;
223
+ }
224
+ this.codigoFormatado += declaracao.simbolos.map((simbolo) => simbolo.lexema).join(', ');
225
+ this.codigoFormatado += ' = ';
226
+ this.deveIndentar = false;
227
+ this.formatarDeclaracaoOuConstruto(declaracao.inicializador);
228
+ this.deveIndentar = true;
229
+ if (this.devePularLinha) {
230
+ this.codigoFormatado += this.quebraLinha;
231
+ }
178
232
  }
179
233
  visitarExpressaoDeAtribuicao(expressao) {
180
234
  this.formatarDeclaracaoOuConstruto(expressao.alvo);
@@ -219,7 +273,16 @@ class FormatadorPotigol {
219
273
  this.deveIndentar = false;
220
274
  for (let caminho of declaracao.caminhos) {
221
275
  this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}caso `;
222
- this.formatarDeclaracaoOuConstruto(caminho.condicoes[0]);
276
+ for (let indice = 0; indice < caminho.condicoes.length; indice++) {
277
+ this.formatarDeclaracaoOuConstruto(caminho.condicoes[indice]);
278
+ if (indice < caminho.condicoes.length - 1) {
279
+ this.codigoFormatado += ', ';
280
+ }
281
+ }
282
+ if (caminho.guarda) {
283
+ this.codigoFormatado += ` se `;
284
+ this.formatarDeclaracaoOuConstruto(caminho.guarda);
285
+ }
223
286
  this.codigoFormatado += ` => `;
224
287
  this.devePularLinha = false;
225
288
  this.deveIndentar = false;
@@ -258,11 +321,15 @@ class FormatadorPotigol {
258
321
  }
259
322
  /* istanbul ignore next */
260
323
  visitarDeclaracaoFazer(declaracao) {
261
- throw new Error('Método não implementado.');
324
+ // Laço faça...enquanto (do-while) não existe em Potigol.
325
+ throw new Error('O laço faça...enquanto não é uma construção de Potigol.');
262
326
  }
263
- /* istanbul ignore next */
264
327
  visitarDeclaracaoImportar(declaracao) {
265
- throw new Error('Método não implementado.');
328
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}use `;
329
+ this.formatarDeclaracaoOuConstruto(declaracao.caminho);
330
+ if (this.devePularLinha) {
331
+ this.codigoFormatado += this.quebraLinha;
332
+ }
266
333
  }
267
334
  visitarDeclaracaoPara(declaracao) {
268
335
  this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}para `;
@@ -288,9 +355,37 @@ class FormatadorPotigol {
288
355
  this.formatarBlocoOuVetorDeclaracoes(declaracao.corpo.declaracoes);
289
356
  this.codigoFormatado += `${this.quebraLinha}${' '.repeat(this.indentacaoAtual)}fim${this.quebraLinha}`;
290
357
  }
291
- /* istanbul ignore next */
358
+ visitarDeclaracaoParaGere(declaracao) {
359
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}para ${declaracao.simboloIteracao.lexema} de `;
360
+ this.deveIndentar = false;
361
+ this.devePularLinha = false;
362
+ this.formatarDeclaracaoOuConstruto(declaracao.inicio);
363
+ this.codigoFormatado += ' ate ';
364
+ this.formatarDeclaracaoOuConstruto(declaracao.fim);
365
+ if (declaracao.passo) {
366
+ this.codigoFormatado += ' passo ';
367
+ this.formatarDeclaracaoOuConstruto(declaracao.passo);
368
+ }
369
+ if (declaracao.condicao) {
370
+ this.codigoFormatado += ' se ';
371
+ this.formatarDeclaracaoOuConstruto(declaracao.condicao);
372
+ }
373
+ this.codigoFormatado += ` gere${this.quebraLinha}`;
374
+ this.devePularLinha = true;
375
+ this.formatarBlocoOuVetorDeclaracoes(declaracao.corpo);
376
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}fim${this.quebraLinha}`;
377
+ this.deveIndentar = true;
378
+ }
292
379
  visitarDeclaracaoParaCada(declaracao) {
293
- throw new Error('Método não implementado.');
380
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}para ${declaracao.variavelIteracao.simbolo.lexema} em `;
381
+ this.deveIndentar = false;
382
+ this.devePularLinha = false;
383
+ this.formatarDeclaracaoOuConstruto(declaracao.vetorOuDicionario);
384
+ this.codigoFormatado += ` faca${this.quebraLinha}`;
385
+ this.deveIndentar = true;
386
+ this.devePularLinha = true;
387
+ this.formatarBlocoOuVetorDeclaracoes(declaracao.corpo.declaracoes);
388
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}fim${this.quebraLinha}`;
294
389
  }
295
390
  visitarDeclaracaoSe(declaracao) {
296
391
  this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}se `;
@@ -301,15 +396,28 @@ class FormatadorPotigol {
301
396
  this.formatarDeclaracaoOuConstruto(declaracaoBloco);
302
397
  }
303
398
  this.indentacaoAtual -= this.tamanhoIndentacao;
304
- if (declaracao.caminhoSenao) {
399
+ let caminhoAtual = declaracao.caminhoSenao;
400
+ while (caminhoAtual instanceof declaracoes_1.Se) {
401
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}senao se `;
402
+ this.formatarDeclaracaoOuConstruto(caminhoAtual.condicao);
403
+ this.codigoFormatado += ` entao${this.quebraLinha}`;
404
+ this.indentacaoAtual += this.tamanhoIndentacao;
405
+ for (let d of caminhoAtual.caminhoEntao.declaracoes) {
406
+ this.formatarDeclaracaoOuConstruto(d);
407
+ }
408
+ this.indentacaoAtual -= this.tamanhoIndentacao;
409
+ caminhoAtual = caminhoAtual.caminhoSenao;
410
+ }
411
+ if (caminhoAtual) {
305
412
  this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}senao${this.quebraLinha}`;
306
- this.formatarDeclaracaoOuConstruto(declaracao.caminhoSenao);
413
+ this.formatarDeclaracaoOuConstruto(caminhoAtual);
307
414
  }
308
415
  this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}fim${this.quebraLinha}`;
309
416
  }
310
417
  /* istanbul ignore next */
311
418
  visitarDeclaracaoTente(declaracao) {
312
- throw new Error('Método não implementado.');
419
+ // Tratamento de exceções (tente...senão) não existe em Potigol.
420
+ throw new Error('Tratamento de exceções não é uma construção de Potigol.');
313
421
  }
314
422
  visitarDeclaracaoVar(declaracao) {
315
423
  if (this.deveIndentar) {
@@ -324,34 +432,52 @@ class FormatadorPotigol {
324
432
  this.codigoFormatado += this.quebraLinha;
325
433
  }
326
434
  }
327
- /* istanbul ignore next */
328
435
  visitarDeclaracaoVarMultiplo(declaracao) {
329
- throw new Error('Método não implementado.');
436
+ if (this.deveIndentar) {
437
+ this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}`;
438
+ }
439
+ this.codigoFormatado += `var ${declaracao.simbolos.map((s) => s.lexema).join(', ')} := `;
440
+ this.deveIndentar = false;
441
+ this.formatarDeclaracaoOuConstruto(declaracao.inicializador);
442
+ this.deveIndentar = true;
443
+ if (this.devePularLinha) {
444
+ this.codigoFormatado += this.quebraLinha;
445
+ }
330
446
  }
331
- /* istanbul ignore next */
332
447
  visitarExpressaoAcessoIndiceVariavel(expressao) {
333
- throw new Error('Método não implementado.');
448
+ this.formatarDeclaracaoOuConstruto(expressao.entidadeChamada);
449
+ this.codigoFormatado += '[';
450
+ this.formatarDeclaracaoOuConstruto(expressao.indice);
451
+ this.codigoFormatado += ']';
334
452
  }
335
453
  /* istanbul ignore next */
336
454
  visitarExpressaoAcessoElementoMatriz(expressao) {
337
- throw new Error('Método não implementado.');
455
+ // Acesso a matrizes multidimensionais não é uma construção de Potigol.
456
+ throw new Error('Acesso a elemento de matriz não é uma construção de Potigol.');
338
457
  }
339
- /* istanbul ignore next */
340
458
  visitarExpressaoAcessoMetodo(expressao) {
341
- throw new Error('Método não implementado.');
459
+ this.formatarDeclaracaoOuConstruto(expressao.objeto);
460
+ this.codigoFormatado += `.${expressao.nomeMetodo}`;
342
461
  }
343
462
  visitarExpressaoAgrupamento(expressao) {
344
463
  this.codigoFormatado += '(';
345
464
  this.formatarDeclaracaoOuConstruto(expressao.expressao);
346
465
  this.codigoFormatado += ')';
347
466
  }
348
- /* istanbul ignore next */
349
467
  visitarExpressaoAtribuicaoPorIndice(expressao) {
350
- throw new Error('Método não implementado.');
468
+ this.formatarDeclaracaoOuConstruto(expressao.objeto);
469
+ this.codigoFormatado += '[';
470
+ this.formatarDeclaracaoOuConstruto(expressao.indice);
471
+ this.codigoFormatado += '] := ';
472
+ this.formatarDeclaracaoOuConstruto(expressao.valor);
473
+ if (this.devePularLinha) {
474
+ this.codigoFormatado += this.quebraLinha;
475
+ }
351
476
  }
352
477
  /* istanbul ignore next */
353
478
  visitarExpressaoAtribuicaoPorIndicesMatriz(expressao) {
354
- throw new Error('Método não implementado.');
479
+ // Atribuição por índices de matriz não é uma construção de Potigol.
480
+ throw new Error('Atribuição por índices de matriz não é uma construção de Potigol.');
355
481
  }
356
482
  visitarExpressaoBinaria(expressao) {
357
483
  this.formatarDeclaracaoOuConstruto(expressao.esquerda);
@@ -412,19 +538,32 @@ class FormatadorPotigol {
412
538
  }
413
539
  /* istanbul ignore next */
414
540
  visitarExpressaoContinua(declaracao) {
415
- throw new Error('Método não implementado.');
541
+ // A instrução 'continua' (continue) não existe em Potigol.
542
+ throw new Error("A instrução 'continua' não é uma construção de Potigol.");
416
543
  }
417
- /* istanbul ignore next */
418
544
  visitarExpressaoDeChamada(expressao) {
419
- throw new Error('Método não implementado.');
545
+ this.formatarDeclaracaoOuConstruto(expressao.entidadeChamada);
546
+ this.codigoFormatado += '(';
547
+ for (let indice = 0; indice < expressao.argumentos.length; indice++) {
548
+ this.formatarDeclaracaoOuConstruto(expressao.argumentos[indice]);
549
+ if (indice < expressao.argumentos.length - 1) {
550
+ this.codigoFormatado += ', ';
551
+ }
552
+ }
553
+ this.codigoFormatado += ')';
420
554
  }
421
- /* istanbul ignore next */
422
555
  visitarExpressaoDefinirValor(expressao) {
423
- throw new Error('Método não implementado.');
556
+ this.formatarDeclaracaoOuConstruto(expressao.objeto);
557
+ this.codigoFormatado += `.${expressao.nome.lexema} := `;
558
+ this.formatarDeclaracaoOuConstruto(expressao.valor);
559
+ if (this.devePularLinha) {
560
+ this.codigoFormatado += this.quebraLinha;
561
+ }
424
562
  }
425
563
  /* istanbul ignore next */
426
564
  visitarExpressaoDeleguaFuncao(expressao) {
427
- throw new Error('Método não implementado.');
565
+ // Funções Delegua como construto não existem em Potigol.
566
+ throw new Error('DeleguaFuncao não é uma construção de Potigol.');
428
567
  }
429
568
  visitarExpressaoDeVariavel(expressao) {
430
569
  if (this.deveIndentar) {
@@ -434,11 +573,13 @@ class FormatadorPotigol {
434
573
  }
435
574
  /* istanbul ignore next */
436
575
  visitarExpressaoDicionario(expressao) {
437
- throw new Error('Método não implementado.');
576
+ // Dicionários não existem em Potigol.
577
+ throw new Error('Dicionário não é uma construção de Potigol.');
438
578
  }
439
579
  /* istanbul ignore next */
440
580
  visitarExpressaoExpressaoRegular(expressao) {
441
- throw new Error('Método não implementado.');
581
+ // Expressões regulares como literais não existem em Potigol.
582
+ throw new Error('Expressão regular não é uma construção de Potigol.');
442
583
  }
443
584
  visitarDeclaracaoEscrevaMesmaLinha(declaracao) {
444
585
  this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}imprima `;
@@ -453,7 +594,8 @@ class FormatadorPotigol {
453
594
  }
454
595
  /* istanbul ignore next */
455
596
  visitarExpressaoFalhar(expressao) {
456
- throw new Error('Método não implementado.');
597
+ // A instrução 'falhar' não existe em Potigol.
598
+ throw new Error("A instrução 'falhar' não é uma construção de Potigol.");
457
599
  }
458
600
  visitarExpressaoFimPara(declaracao) {
459
601
  // FimPara representa o incremento em loops 'para'
@@ -464,7 +606,9 @@ class FormatadorPotigol {
464
606
  }
465
607
  /* istanbul ignore next */
466
608
  visitarExpressaoFormatacaoEscrita(declaracao) {
467
- throw new Error('Método não implementado.');
609
+ // FormatacaoEscrita não é produzida pelo avaliador sintático de Potigol.
610
+ // Em Potigol, formatação é feita pelo método .formato() nos valores.
611
+ throw new Error('FormatacaoEscrita não é produzida pelo avaliador sintático de Potigol.');
468
612
  }
469
613
  visitarExpressaoFuncaoConstruto(expressao) {
470
614
  this.indentacaoAtual += this.tamanhoIndentacao;
@@ -472,18 +616,9 @@ class FormatadorPotigol {
472
616
  for (let parametro of expressao.parametros) {
473
617
  if (parametro.tipoDado) {
474
618
  this.codigoFormatado += `${parametro.nome.lexema}: `;
475
- switch (parametro.tipoDado.toUpperCase()) {
476
- case lexico_regular_1.default.TEXTO:
477
- this.codigoFormatado += 'Caractere';
478
- break;
479
- case lexico_regular_1.default.REAL:
480
- this.codigoFormatado += 'Real';
481
- break;
482
- case lexico_regular_1.default.INTEIRO:
483
- this.codigoFormatado += 'Inteiro';
484
- break;
485
- default:
486
- break;
619
+ const tipoNormalizado = this.normalizarTipo(parametro.tipoDado);
620
+ if (tipoNormalizado) {
621
+ this.codigoFormatado += tipoNormalizado;
487
622
  }
488
623
  this.codigoFormatado += `, `;
489
624
  }
@@ -496,7 +631,7 @@ class FormatadorPotigol {
496
631
  }
497
632
  // Se há tipo de retorno definido
498
633
  if (expressao.tipo) {
499
- this.codigoFormatado += `: ${expressao.tipo}`;
634
+ this.codigoFormatado += `: ${this.normalizarTipo(expressao.tipo)}`;
500
635
  }
501
636
  this.codigoFormatado += ` = `;
502
637
  this.deveIndentar = false;
@@ -506,13 +641,13 @@ class FormatadorPotigol {
506
641
  this.deveIndentar = true;
507
642
  this.indentacaoAtual -= this.tamanhoIndentacao;
508
643
  }
509
- /* istanbul ignore next */
510
644
  visitarExpressaoIsto(expressao) {
511
- throw new Error('Método não implementado.');
645
+ this.codigoFormatado += 'isto';
512
646
  }
513
647
  /* istanbul ignore next */
514
648
  visitarExpressaoLeia(expressao) {
515
- throw new Error('Método não implementado.');
649
+ // Potigol não possui 'leia' genérico — use leia_inteiro, leia_real ou leia_texto.
650
+ throw new Error("Potigol não possui 'leia' genérico. Use leia_inteiro, leia_real ou leia_texto.");
516
651
  }
517
652
  visitarExpressaoLiteral(expressao) {
518
653
  if (typeof expressao.valor === 'string') {
@@ -550,15 +685,17 @@ class FormatadorPotigol {
550
685
  }
551
686
  /* istanbul ignore next */
552
687
  visitarExpressaoSuper(expressao) {
553
- throw new Error('Método não implementado.');
688
+ // A instrução 'super' não existe em Potigol — o dialeto não suporta herança.
689
+ throw new Error("A instrução 'super' não é uma construção de Potigol.");
554
690
  }
555
691
  /* istanbul ignore next */
556
692
  visitarExpressaoSustar(declaracao) {
557
- throw new Error('Método não implementado.');
693
+ // A instrução 'sustar' (break) não existe em Potigol.
694
+ throw new Error("A instrução 'sustar' não é uma construção de Potigol.");
558
695
  }
559
- /* istanbul ignore next */
560
696
  visitarExpressaoTipoDe(expressao) {
561
- throw new Error('Método não implementado.');
697
+ this.formatarDeclaracaoOuConstruto(expressao.valor);
698
+ this.codigoFormatado += `.${expressao.simbolo.lexema}`;
562
699
  }
563
700
  visitarExpressaoUnaria(expressao) {
564
701
  let operador;
@@ -587,9 +724,15 @@ class FormatadorPotigol {
587
724
  this.codigoFormatado += this.quebraLinha;
588
725
  }
589
726
  }
590
- /* istanbul ignore next */
591
727
  visitarExpressaoVetor(expressao) {
592
- throw new Error('Método não implementado.');
728
+ this.codigoFormatado += '[';
729
+ for (let indice = 0; indice < expressao.elementos.length; indice++) {
730
+ this.formatarDeclaracaoOuConstruto(expressao.elementos[indice]);
731
+ if (indice < expressao.elementos.length - 1) {
732
+ this.codigoFormatado += ', ';
733
+ }
734
+ }
735
+ this.codigoFormatado += ']';
593
736
  }
594
737
  visitarDeclaracaoConstante(expressao) {
595
738
  if (this.deveIndentar) {
@@ -597,6 +740,12 @@ class FormatadorPotigol {
597
740
  }
598
741
  this.codigoFormatado += `${expressao.simbolo.lexema}`;
599
742
  }
743
+ visitarExpressaoConstanteOuVariavel(expressao) {
744
+ if (this.deveIndentar) {
745
+ this.codigoFormatado += ' '.repeat(this.indentacaoAtual);
746
+ }
747
+ this.codigoFormatado += `${expressao.simbolo.lexema}`;
748
+ }
600
749
  formatarDeclaracaoTuplas(declaracao) {
601
750
  const declaracoes = Object.keys(declaracao);
602
751
  this.codigoFormatado += '(';
@@ -640,8 +789,14 @@ class FormatadorPotigol {
640
789
  this.visitarExpressaoAcessoIndiceVariavel(declaracaoOuConstruto);
641
790
  break;
642
791
  case construtos_1.AcessoMetodoOuPropriedade:
792
+ this.visitarExpressaoAcessoMetodoOuPropriedade(declaracaoOuConstruto);
793
+ break;
794
+ case construtos_1.AcessoMetodo:
643
795
  this.visitarExpressaoAcessoMetodo(declaracaoOuConstruto);
644
796
  break;
797
+ case construtos_1.AcessoPropriedade:
798
+ this.visitarExpressaoAcessoPropriedade(declaracaoOuConstruto);
799
+ break;
645
800
  case construtos_1.Agrupamento:
646
801
  this.visitarExpressaoAgrupamento(declaracaoOuConstruto);
647
802
  break;
@@ -663,6 +818,9 @@ class FormatadorPotigol {
663
818
  case declaracoes_1.Classe:
664
819
  this.visitarDeclaracaoClasse(declaracaoOuConstruto);
665
820
  break;
821
+ case declaracoes_2.AliasTipo:
822
+ this.visitarDeclaracaoAliasTipo(declaracaoOuConstruto);
823
+ break;
666
824
  case declaracoes_1.Comentario:
667
825
  this.visitarDeclaracaoComentario(declaracaoOuConstruto);
668
826
  break;
@@ -702,6 +860,9 @@ class FormatadorPotigol {
702
860
  case construtos_1.Deceto:
703
861
  this.visitarExpressaoDeceto(declaracaoOuConstruto);
704
862
  break;
863
+ case construtos_1.TuplaN:
864
+ this.visitarExpressaoTuplaN(declaracaoOuConstruto);
865
+ break;
705
866
  case declaracoes_1.Escolha:
706
867
  this.visitarDeclaracaoEscolha(declaracaoOuConstruto);
707
868
  break;
@@ -771,6 +932,9 @@ class FormatadorPotigol {
771
932
  case declaracoes_1.Para:
772
933
  this.visitarDeclaracaoPara(declaracaoOuConstruto);
773
934
  break;
935
+ case declaracoes_2.ParaGere:
936
+ this.visitarDeclaracaoParaGere(declaracaoOuConstruto);
937
+ break;
774
938
  case declaracoes_1.ParaCada:
775
939
  this.visitarDeclaracaoParaCada(declaracaoOuConstruto);
776
940
  break;
@@ -801,9 +965,15 @@ class FormatadorPotigol {
801
965
  case declaracoes_1.Const:
802
966
  this.visitarDeclaracaoConst(declaracaoOuConstruto);
803
967
  break;
968
+ case declaracoes_1.ConstMultiplo:
969
+ this.visitarDeclaracaoConstMultiplo(declaracaoOuConstruto);
970
+ break;
804
971
  case declaracoes_1.Var:
805
972
  this.visitarDeclaracaoVar(declaracaoOuConstruto);
806
973
  break;
974
+ case declaracoes_1.VarMultiplo:
975
+ this.visitarDeclaracaoVarMultiplo(declaracaoOuConstruto);
976
+ break;
807
977
  case construtos_1.Variavel:
808
978
  this.visitarExpressaoDeVariavel(declaracaoOuConstruto);
809
979
  break;
@@ -813,6 +983,9 @@ class FormatadorPotigol {
813
983
  case construtos_1.Constante:
814
984
  this.visitarDeclaracaoConstante(declaracaoOuConstruto);
815
985
  break;
986
+ case construtos_2.ConstanteOuVariavel:
987
+ this.visitarExpressaoConstanteOuVariavel(declaracaoOuConstruto);
988
+ break;
816
989
  case declaracoes_1.PropriedadeClasse:
817
990
  this.visitarExpressaoPropriedadeClasse(declaracaoOuConstruto);
818
991
  break;