@designliquido/delegua 1.15.5 → 1.15.6
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.
- package/analisador-semantico/analisador-semantico.d.ts +9 -4
- package/analisador-semantico/analisador-semantico.d.ts.map +1 -1
- package/analisador-semantico/analisador-semantico.js +127 -35
- package/analisador-semantico/analisador-semantico.js.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico-base.d.ts.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico-base.js +10 -1
- package/avaliador-sintatico/avaliador-sintatico-base.js.map +1 -1
- package/bin/package.json +1 -1
- package/declaracoes/extensao.d.ts +3 -0
- package/declaracoes/extensao.d.ts.map +1 -1
- package/declaracoes/extensao.js +3 -0
- package/declaracoes/extensao.js.map +1 -1
- package/formatadores/formatador-delegua.d.ts +18 -9
- package/formatadores/formatador-delegua.d.ts.map +1 -1
- package/formatadores/formatador-delegua.js +152 -2
- package/formatadores/formatador-delegua.js.map +1 -1
- package/interfaces/analisador-semantico-interface.d.ts +1 -0
- package/interfaces/analisador-semantico-interface.d.ts.map +1 -1
- package/interfaces/formatador/index.d.ts +2 -0
- package/interfaces/formatador/index.d.ts.map +1 -0
- package/interfaces/formatador/index.js +18 -0
- package/interfaces/formatador/index.js.map +1 -0
- package/interfaces/formatador/opcoes-formatador-delegua-interface.d.ts +5 -0
- package/interfaces/formatador/opcoes-formatador-delegua-interface.d.ts.map +1 -0
- package/interfaces/formatador/opcoes-formatador-delegua-interface.js +3 -0
- package/interfaces/formatador/opcoes-formatador-delegua-interface.js.map +1 -0
- package/package.json +1 -1
- package/tipos.d.ts +7 -0
- package/tipos.d.ts.map +1 -1
- package/umd/delegua.js +292 -38
package/umd/delegua.js
CHANGED
|
@@ -478,12 +478,16 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
478
478
|
this.pilhaVariaveis = new pilha_variaveis_1.PilhaVariaveis();
|
|
479
479
|
this.gerenciadorEscopos = new gerenciador_escopos_1.GerenciadorEscopos();
|
|
480
480
|
this.funcoes = {};
|
|
481
|
-
this.
|
|
481
|
+
this.classesDeclaradas = new Set();
|
|
482
482
|
this.classesRegistradas = new Map();
|
|
483
|
+
this.classesExternasConhecidas = new Set();
|
|
483
484
|
this.classeAtualEmAnalise = null;
|
|
484
485
|
this.atual = 0;
|
|
485
486
|
this.diagnosticos = [];
|
|
486
487
|
}
|
|
488
|
+
definirClassesExternasConhecidas(classesExternasConhecidas) {
|
|
489
|
+
this.classesExternasConhecidas = new Set(classesExternasConhecidas);
|
|
490
|
+
}
|
|
487
491
|
verificarTipoAtribuido(declaracao) {
|
|
488
492
|
if (declaracao.tipo) {
|
|
489
493
|
if (['vetor', 'qualquer[]', 'inteiro[]', 'texto[]'].includes(declaracao.tipo)) {
|
|
@@ -668,6 +672,8 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
668
672
|
}
|
|
669
673
|
// Marca como inicializada após atribuição
|
|
670
674
|
this.gerenciadorEscopos.marcarComoInicializada(simboloAlvo.lexema, expressao.valor);
|
|
675
|
+
// Marca variáveis usadas no valor atribuído (ex: idade = ano - inteiro(leia(...))).
|
|
676
|
+
this.marcarVariaveisUsadasEmExpressao(expressao.valor);
|
|
671
677
|
// Atualiza tipo se a variável não foi tipada explicitamente
|
|
672
678
|
if (variavel.tipo === 'qualquer') {
|
|
673
679
|
const tipoInferido = this.obterTipoExpressao(expressao.valor);
|
|
@@ -742,10 +748,34 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
742
748
|
this.variaveis[simboloAlvo.lexema].valor = expressao.valor;
|
|
743
749
|
}
|
|
744
750
|
} */
|
|
751
|
+
return Promise.resolve();
|
|
745
752
|
}
|
|
746
753
|
async visitarDeclaracaoDeExpressao(declaracao) {
|
|
747
754
|
return await declaracao.expressao.aceitar(this);
|
|
748
755
|
}
|
|
756
|
+
async visitarExpressaoBloco(declaracao) {
|
|
757
|
+
this.gerenciadorEscopos.empilharEscopo();
|
|
758
|
+
try {
|
|
759
|
+
for (const declaracaoBloco of declaracao.declaracoes) {
|
|
760
|
+
await declaracaoBloco.aceitar(this);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
finally {
|
|
764
|
+
this.gerenciadorEscopos.desempilharEscopo();
|
|
765
|
+
}
|
|
766
|
+
return Promise.resolve();
|
|
767
|
+
}
|
|
768
|
+
visitarExpressaoAcessoIndiceVariavel(expressao) {
|
|
769
|
+
this.marcarVariaveisUsadasEmExpressao(expressao.entidadeChamada);
|
|
770
|
+
this.marcarVariaveisUsadasEmExpressao(expressao.indice);
|
|
771
|
+
return Promise.resolve();
|
|
772
|
+
}
|
|
773
|
+
visitarExpressaoAtribuicaoPorIndice(expressao) {
|
|
774
|
+
this.marcarVariaveisUsadasEmExpressao(expressao.objeto);
|
|
775
|
+
this.marcarVariaveisUsadasEmExpressao(expressao.indice);
|
|
776
|
+
this.marcarVariaveisUsadasEmExpressao(expressao.valor);
|
|
777
|
+
return Promise.resolve();
|
|
778
|
+
}
|
|
749
779
|
visitarDeclaracaoAjuda(declaracao) {
|
|
750
780
|
if (declaracao.elemento) {
|
|
751
781
|
this.marcarVariaveisUsadasEmExpressao(declaracao.elemento);
|
|
@@ -760,7 +790,7 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
760
790
|
}
|
|
761
791
|
visitarDeclaracaoEscolha(declaracao) {
|
|
762
792
|
const identificadorOuLiteral = declaracao.identificadorOuLiteral;
|
|
763
|
-
const tipo = identificadorOuLiteral.tipo;
|
|
793
|
+
const tipo = identificadorOuLiteral.tipo || 'qualquer';
|
|
764
794
|
for (let caminho of declaracao.caminhos) {
|
|
765
795
|
for (let condicao of caminho.condicoes) {
|
|
766
796
|
switch (condicao.constructor) {
|
|
@@ -791,8 +821,16 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
791
821
|
}
|
|
792
822
|
return Promise.resolve();
|
|
793
823
|
}
|
|
794
|
-
visitarDeclaracaoEnquanto(declaracao) {
|
|
795
|
-
|
|
824
|
+
async visitarDeclaracaoEnquanto(declaracao) {
|
|
825
|
+
// Marca variáveis usadas na condição.
|
|
826
|
+
this.marcarVariaveisUsadasEmExpressao(declaracao.condicao);
|
|
827
|
+
// Verifica a condição (incluindo validações de tipo para operadores lógicos).
|
|
828
|
+
await this.verificarCondicao(declaracao.condicao);
|
|
829
|
+
// Visita corpo para que usos/atribuições dentro do laço sejam analisados.
|
|
830
|
+
for (const declaracaoCorpo of declaracao.corpo.declaracoes) {
|
|
831
|
+
await declaracaoCorpo.aceitar(this);
|
|
832
|
+
}
|
|
833
|
+
return Promise.resolve();
|
|
796
834
|
}
|
|
797
835
|
visitarDeclaracaoFazer(declaracao) {
|
|
798
836
|
// Marca variáveis usadas na condição
|
|
@@ -801,25 +839,31 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
801
839
|
return this.verificarCondicao(declaracao.condicaoEnquanto);
|
|
802
840
|
}
|
|
803
841
|
async visitarDeclaracaoPara(declaracao) {
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
842
|
+
this.gerenciadorEscopos.empilharEscopo();
|
|
843
|
+
try {
|
|
844
|
+
if (Array.isArray(declaracao.inicializador)) {
|
|
845
|
+
for (const inicializador of declaracao.inicializador) {
|
|
846
|
+
await inicializador.aceitar(this);
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
else if (declaracao.inicializador) {
|
|
850
|
+
await declaracao.inicializador.aceitar(this);
|
|
851
|
+
}
|
|
852
|
+
// O laço precisa visitar condição/incremento/corpo para registrar usos de variáveis.
|
|
853
|
+
if (declaracao.condicao) {
|
|
854
|
+
this.marcarVariaveisUsadasEmExpressao(declaracao.condicao);
|
|
855
|
+
await this.verificarCondicao(declaracao.condicao);
|
|
856
|
+
}
|
|
857
|
+
if (declaracao.incrementar) {
|
|
858
|
+
this.marcarVariaveisUsadasEmExpressao(declaracao.incrementar);
|
|
859
|
+
this.verificarExpressao(declaracao.incrementar);
|
|
860
|
+
}
|
|
861
|
+
for (const declaracaoCorpo of declaracao.corpo.declaracoes) {
|
|
862
|
+
await declaracaoCorpo.aceitar(this);
|
|
807
863
|
}
|
|
808
864
|
}
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
}
|
|
812
|
-
// O laço precisa visitar condição/incremento/corpo para registrar usos de variáveis.
|
|
813
|
-
if (declaracao.condicao) {
|
|
814
|
-
this.marcarVariaveisUsadasEmExpressao(declaracao.condicao);
|
|
815
|
-
await this.verificarCondicao(declaracao.condicao);
|
|
816
|
-
}
|
|
817
|
-
if (declaracao.incrementar) {
|
|
818
|
-
this.marcarVariaveisUsadasEmExpressao(declaracao.incrementar);
|
|
819
|
-
this.verificarExpressao(declaracao.incrementar);
|
|
820
|
-
}
|
|
821
|
-
for (const declaracaoCorpo of declaracao.corpo.declaracoes) {
|
|
822
|
-
await declaracaoCorpo.aceitar(this);
|
|
865
|
+
finally {
|
|
866
|
+
this.gerenciadorEscopos.desempilharEscopo();
|
|
823
867
|
}
|
|
824
868
|
return Promise.resolve();
|
|
825
869
|
}
|
|
@@ -828,11 +872,25 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
828
872
|
this.marcarVariaveisUsadasEmExpressao(declaracao.vetorOuDicionario);
|
|
829
873
|
return Promise.resolve();
|
|
830
874
|
}
|
|
831
|
-
visitarDeclaracaoSe(declaracao) {
|
|
875
|
+
async visitarDeclaracaoSe(declaracao) {
|
|
832
876
|
// Marca variáveis usadas na condição
|
|
833
877
|
this.marcarVariaveisUsadasEmExpressao(declaracao.condicao);
|
|
834
878
|
// Verifica a condição (incluindo validação de tipos para operadores lógicos)
|
|
835
|
-
|
|
879
|
+
await this.verificarCondicao(declaracao.condicao);
|
|
880
|
+
if (declaracao.caminhoEntao) {
|
|
881
|
+
await declaracao.caminhoEntao.aceitar(this);
|
|
882
|
+
}
|
|
883
|
+
if (declaracao.caminhosSeSenao && declaracao.caminhosSeSenao.length > 0) {
|
|
884
|
+
for (const caminhoSeSenao of declaracao.caminhosSeSenao) {
|
|
885
|
+
this.marcarVariaveisUsadasEmExpressao(caminhoSeSenao.condicao);
|
|
886
|
+
await this.verificarCondicao(caminhoSeSenao.condicao);
|
|
887
|
+
await caminhoSeSenao.caminho.aceitar(this);
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
if (declaracao.caminhoSenao) {
|
|
891
|
+
await declaracao.caminhoSenao.aceitar(this);
|
|
892
|
+
}
|
|
893
|
+
return Promise.resolve();
|
|
836
894
|
}
|
|
837
895
|
/**
|
|
838
896
|
* Verifica uma expressão recursivamente, incluindo operações binárias
|
|
@@ -979,6 +1037,9 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
979
1037
|
const tipoEsquerda = this.obterTipoExpressao(binario.esquerda);
|
|
980
1038
|
const tipoDireita = this.obterTipoExpressao(binario.direita);
|
|
981
1039
|
const tiposNumericos = ['inteiro', 'número', 'real'];
|
|
1040
|
+
if (!tipoEsquerda || !tipoDireita) {
|
|
1041
|
+
return;
|
|
1042
|
+
}
|
|
982
1043
|
if ((tipoEsquerda === 'texto' && tiposNumericos.includes(tipoDireita)) ||
|
|
983
1044
|
(tiposNumericos.includes(tipoEsquerda) && tipoDireita === 'texto')) {
|
|
984
1045
|
this.aviso(binario.operador, `Esta comparação ocorre entre tipos ${tipoEsquerda} e ${tipoDireita}, e o resultado pode não ser o desejado.`);
|
|
@@ -1281,7 +1342,10 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1281
1342
|
// Inferir tipo do inicializador se não foi especificado explicitamente
|
|
1282
1343
|
let tipoInferido = declaracao.tipo;
|
|
1283
1344
|
if (!tipoInferido && declaracao.inicializador) {
|
|
1284
|
-
|
|
1345
|
+
const tipoInicializador = this.obterTipoExpressao(declaracao.inicializador);
|
|
1346
|
+
if (tipoInicializador) {
|
|
1347
|
+
tipoInferido = tipoInicializador;
|
|
1348
|
+
}
|
|
1285
1349
|
}
|
|
1286
1350
|
// Sugestão de tipo melhor quando 'qualquer' é usado explicitamente
|
|
1287
1351
|
if (declaracao.tipoExplicito &&
|
|
@@ -1295,8 +1359,8 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1295
1359
|
textoOriginal: 'qualquer',
|
|
1296
1360
|
textoSubstituto: tipoMelhor,
|
|
1297
1361
|
linha: declaracao.simbolo.linha,
|
|
1298
|
-
colunaInicio: declaracao.simbolo.colunaInicio,
|
|
1299
|
-
colunaFim: declaracao.simbolo.colunaFim,
|
|
1362
|
+
colunaInicio: declaracao.simbolo.colunaInicio || 0,
|
|
1363
|
+
colunaFim: declaracao.simbolo.colunaFim || 0,
|
|
1300
1364
|
},
|
|
1301
1365
|
]);
|
|
1302
1366
|
}
|
|
@@ -1331,7 +1395,7 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1331
1395
|
return Promise.resolve();
|
|
1332
1396
|
}
|
|
1333
1397
|
visitarExpressaoRetornar(declaracao) {
|
|
1334
|
-
return Promise.resolve(
|
|
1398
|
+
return Promise.resolve(undefined);
|
|
1335
1399
|
}
|
|
1336
1400
|
visitarExpressaoDeVariavel(expressao) {
|
|
1337
1401
|
if (expressao instanceof construtos_1.Variavel) {
|
|
@@ -1415,11 +1479,11 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1415
1479
|
if (nomeSuperclasse === declaracao.simbolo.lexema) {
|
|
1416
1480
|
this.erro(superClasseVariavel.simbolo, `A classe '${declaracao.simbolo.lexema}' não pode herdar de si mesma.`);
|
|
1417
1481
|
}
|
|
1418
|
-
else if (!this.
|
|
1482
|
+
else if (!this.classesDeclaradas.has(nomeSuperclasse) && !this.classesExternasConhecidas.has(nomeSuperclasse)) {
|
|
1419
1483
|
this.erro(superClasseVariavel.simbolo, `Superclasse '${nomeSuperclasse}' não foi declarada.`);
|
|
1420
1484
|
}
|
|
1421
1485
|
}
|
|
1422
|
-
this.
|
|
1486
|
+
this.classesDeclaradas.add(declaracao.simbolo.lexema);
|
|
1423
1487
|
this.classesRegistradas.set(declaracao.simbolo.lexema, declaracao);
|
|
1424
1488
|
// Visita corpos dos métodos com contexto de classe ativo
|
|
1425
1489
|
const classeAnterior = this.classeAtualEmAnalise;
|
|
@@ -1431,7 +1495,7 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1431
1495
|
}
|
|
1432
1496
|
this.classeAtualEmAnalise = classeAnterior;
|
|
1433
1497
|
}
|
|
1434
|
-
visitarDeclaracaoDefinicaoFuncao(declaracao) {
|
|
1498
|
+
async visitarDeclaracaoDefinicaoFuncao(declaracao) {
|
|
1435
1499
|
var _a;
|
|
1436
1500
|
if (declaracao.funcao.tipo === undefined) {
|
|
1437
1501
|
this.erro(declaracao.simbolo, `Declaração de retorno da função é inválido.`);
|
|
@@ -1447,7 +1511,10 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1447
1511
|
this.erro(declaracao.simbolo, `Função '${declaracao.simbolo.lexema}' deve retornar '${tipoRetornoFuncao}' em todos os caminhos de execução.`);
|
|
1448
1512
|
}
|
|
1449
1513
|
}
|
|
1450
|
-
|
|
1514
|
+
let retornos = [];
|
|
1515
|
+
for (const declaracaoCorpo of declaracao.funcao.corpo) {
|
|
1516
|
+
retornos = retornos.concat((0, comum_1.buscarRetornos)(declaracaoCorpo));
|
|
1517
|
+
}
|
|
1451
1518
|
// Filtra retornos com tipo 'qualquer' (não determinado em tempo de análise sintática)
|
|
1452
1519
|
const retornosComTipoIndeterminado = retornos.filter((retorno) => retorno.valor !== null &&
|
|
1453
1520
|
retorno.valor !== undefined &&
|
|
@@ -1458,7 +1525,8 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1458
1525
|
declaracao.funcao.tipoExplicito &&
|
|
1459
1526
|
retornosComTipoIndeterminado.length > 0) {
|
|
1460
1527
|
const retornoComValor = retornosComTipoIndeterminado[0];
|
|
1461
|
-
const
|
|
1528
|
+
const valorRetorno = retornoComValor.valor;
|
|
1529
|
+
const tipoInferido = this.obterTipoExpressao(valorRetorno);
|
|
1462
1530
|
if (tipoInferido && tipoInferido !== 'qualquer') {
|
|
1463
1531
|
this.erro(declaracao.simbolo, `A função não pode ter nenhum tipo de retorno. Tipo inferido do retorno: '${tipoInferido}'.`);
|
|
1464
1532
|
}
|
|
@@ -1486,14 +1554,38 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1486
1554
|
this.funcoes[declaracao.simbolo.lexema] = {
|
|
1487
1555
|
valor: declaracao.funcao,
|
|
1488
1556
|
};
|
|
1557
|
+
this.gerenciadorEscopos.empilharEscopo();
|
|
1558
|
+
try {
|
|
1559
|
+
for (const parametro of declaracao.funcao.parametros) {
|
|
1560
|
+
this.gerenciadorEscopos.declarar(parametro.nome.lexema, {
|
|
1561
|
+
nome: parametro.nome.lexema,
|
|
1562
|
+
tipo: parametro.tipoDado || 'qualquer',
|
|
1563
|
+
imutavel: false,
|
|
1564
|
+
valor: undefined,
|
|
1565
|
+
inicializada: true,
|
|
1566
|
+
usada: false,
|
|
1567
|
+
hashArquivo: parametro.nome.hashArquivo,
|
|
1568
|
+
linha: parametro.nome.linha,
|
|
1569
|
+
});
|
|
1570
|
+
}
|
|
1571
|
+
for (const declaracaoCorpo of declaracao.funcao.corpo) {
|
|
1572
|
+
await declaracaoCorpo.aceitar(this);
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
finally {
|
|
1576
|
+
this.gerenciadorEscopos.desempilharEscopo();
|
|
1577
|
+
}
|
|
1489
1578
|
return Promise.resolve();
|
|
1490
1579
|
}
|
|
1491
1580
|
verificarVariaveisNaoUsadas() {
|
|
1492
1581
|
const naoUsadas = this.gerenciadorEscopos.obterVariaveisNaoUsadas();
|
|
1493
1582
|
for (let variavel of naoUsadas) {
|
|
1494
1583
|
// Verifica se já existe um erro associado à variável.
|
|
1495
|
-
const temErro = this.diagnosticos.some((d) =>
|
|
1496
|
-
|
|
1584
|
+
const temErro = this.diagnosticos.some((d) => {
|
|
1585
|
+
var _a;
|
|
1586
|
+
return d.severidade === erros_1.DiagnosticoSeveridade.ERRO &&
|
|
1587
|
+
((_a = d.simbolo) === null || _a === void 0 ? void 0 : _a.lexema) === variavel.nome;
|
|
1588
|
+
});
|
|
1497
1589
|
// Se a variável já tem um erro associado, não emitir aviso de não usada.
|
|
1498
1590
|
if (temErro) {
|
|
1499
1591
|
continue;
|
|
@@ -1508,7 +1600,7 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1508
1600
|
}
|
|
1509
1601
|
async analisar(declaracoes) {
|
|
1510
1602
|
this.gerenciadorEscopos = new gerenciador_escopos_1.GerenciadorEscopos();
|
|
1511
|
-
this.
|
|
1603
|
+
this.classesDeclaradas = new Set();
|
|
1512
1604
|
this.classesRegistradas = new Map();
|
|
1513
1605
|
this.classeAtualEmAnalise = null;
|
|
1514
1606
|
this.atual = 0;
|
|
@@ -1690,6 +1782,13 @@ const comum_1 = __importDefault(require("../tipos-de-simbolos/comum"));
|
|
|
1690
1782
|
* de tipos de símbolos comuns entre todos os dialetos.
|
|
1691
1783
|
*/
|
|
1692
1784
|
class AvaliadorSintaticoBase {
|
|
1785
|
+
constructor() {
|
|
1786
|
+
this.simbolos = [];
|
|
1787
|
+
this.erros = [];
|
|
1788
|
+
this.hashArquivo = -1;
|
|
1789
|
+
this.atual = 0;
|
|
1790
|
+
this.blocos = 0;
|
|
1791
|
+
}
|
|
1693
1792
|
erro(simbolo, mensagemDeErro) {
|
|
1694
1793
|
const excecao = new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(simbolo, mensagemDeErro);
|
|
1695
1794
|
return excecao;
|
|
@@ -1721,6 +1820,8 @@ class AvaliadorSintaticoBase {
|
|
|
1721
1820
|
return this.simbolos[this.atual].tipo === tipo;
|
|
1722
1821
|
}
|
|
1723
1822
|
verificarTipoProximoSimbolo(tipo) {
|
|
1823
|
+
if (this.atual + 1 >= this.simbolos.length)
|
|
1824
|
+
return false;
|
|
1724
1825
|
return this.simbolos[this.atual + 1].tipo === tipo;
|
|
1725
1826
|
}
|
|
1726
1827
|
estaNoFinal() {
|
|
@@ -1880,7 +1981,7 @@ class AvaliadorSintaticoBase {
|
|
|
1880
1981
|
}
|
|
1881
1982
|
const parametro = {};
|
|
1882
1983
|
if (this.simbolos[this.atual].tipo === comum_1.default.MULTIPLICACAO) {
|
|
1883
|
-
this.
|
|
1984
|
+
this.avancarEDevolverAnterior();
|
|
1884
1985
|
parametro.abrangencia = 'multiplo';
|
|
1885
1986
|
}
|
|
1886
1987
|
else {
|
|
@@ -14499,6 +14600,9 @@ exports.Expressao = Expressao;
|
|
|
14499
14600
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14500
14601
|
exports.Extensao = void 0;
|
|
14501
14602
|
const declaracao_1 = require("./declaracao");
|
|
14603
|
+
/**
|
|
14604
|
+
* Declaração de Extensão de Classe.
|
|
14605
|
+
*/
|
|
14502
14606
|
class Extensao extends declaracao_1.Declaracao {
|
|
14503
14607
|
constructor(simboloTipo, metodos, ehGlobal, hashArquivo) {
|
|
14504
14608
|
super(Number(simboloTipo.linha), hashArquivo);
|
|
@@ -15692,6 +15796,135 @@ class FormatadorDelegua {
|
|
|
15692
15796
|
this.deveIndentar = true;
|
|
15693
15797
|
this.delimitadorTexto = opcoes.delimitadorTexto || 'aspas-simples';
|
|
15694
15798
|
}
|
|
15799
|
+
visitarDeclaracaoAjuda(declaracao) {
|
|
15800
|
+
this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}ajuda(`;
|
|
15801
|
+
if (declaracao.elemento) {
|
|
15802
|
+
this.formatarDeclaracaoOuConstruto(declaracao.elemento);
|
|
15803
|
+
}
|
|
15804
|
+
this.codigoFormatado += `)${this.quebraLinha}`;
|
|
15805
|
+
}
|
|
15806
|
+
visitarDeclaracaoExtensao(declaracao) {
|
|
15807
|
+
const global = declaracao.ehGlobal ? 'global ' : '';
|
|
15808
|
+
this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}extensão ${global}de ${declaracao.simboloTipo.lexema} {${this.quebraLinha}`;
|
|
15809
|
+
this.indentacaoAtual += this.tamanhoIndentacao;
|
|
15810
|
+
for (let metodo of declaracao.metodos) {
|
|
15811
|
+
this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}${metodo.simbolo.lexema}`;
|
|
15812
|
+
this.visitarExpressaoFuncaoConstruto(metodo.funcao);
|
|
15813
|
+
}
|
|
15814
|
+
this.indentacaoAtual -= this.tamanhoIndentacao;
|
|
15815
|
+
this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}}${this.quebraLinha}`;
|
|
15816
|
+
}
|
|
15817
|
+
visitarDeclaracaoInterface(declaracao) {
|
|
15818
|
+
this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}interface ${declaracao.simbolo.lexema} {${this.quebraLinha}`;
|
|
15819
|
+
this.indentacaoAtual += this.tamanhoIndentacao;
|
|
15820
|
+
for (let propriedade of declaracao.propriedades) {
|
|
15821
|
+
this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}${propriedade.nome.lexema}: ${propriedade.tipo || 'qualquer'}${this.quebraLinha}`;
|
|
15822
|
+
}
|
|
15823
|
+
for (let metodo of declaracao.metodos) {
|
|
15824
|
+
this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}${metodo.nome.lexema}(`;
|
|
15825
|
+
for (let parametro of metodo.parametros) {
|
|
15826
|
+
this.codigoFormatado += `${parametro.nome.lexema}: ${parametro.tipoDado || 'qualquer'}, `;
|
|
15827
|
+
}
|
|
15828
|
+
if (metodo.parametros.length > 0) {
|
|
15829
|
+
this.codigoFormatado = this.codigoFormatado.slice(0, -2);
|
|
15830
|
+
}
|
|
15831
|
+
this.codigoFormatado += `)`;
|
|
15832
|
+
if (metodo.tipoRetorno) {
|
|
15833
|
+
this.codigoFormatado += `: ${metodo.tipoRetorno}`;
|
|
15834
|
+
}
|
|
15835
|
+
this.codigoFormatado += this.quebraLinha;
|
|
15836
|
+
}
|
|
15837
|
+
this.indentacaoAtual -= this.tamanhoIndentacao;
|
|
15838
|
+
this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}}${this.quebraLinha}`;
|
|
15839
|
+
}
|
|
15840
|
+
visitarExpressaoAjuda(expressao) {
|
|
15841
|
+
this.codigoFormatado += `ajuda(`;
|
|
15842
|
+
if (expressao.valor) {
|
|
15843
|
+
this.formatarDeclaracaoOuConstruto(expressao.valor);
|
|
15844
|
+
}
|
|
15845
|
+
this.codigoFormatado += `)`;
|
|
15846
|
+
}
|
|
15847
|
+
visitarExpressaoEnquanto(expressao) {
|
|
15848
|
+
this.codigoFormatado += `enquanto `;
|
|
15849
|
+
this.formatarDeclaracaoOuConstruto(expressao.condicao);
|
|
15850
|
+
this.codigoFormatado += ` {${this.quebraLinha}`;
|
|
15851
|
+
this.indentacaoAtual += this.tamanhoIndentacao;
|
|
15852
|
+
for (let declaracao of expressao.corpo.declaracoes) {
|
|
15853
|
+
this.formatarDeclaracaoOuConstruto(declaracao);
|
|
15854
|
+
}
|
|
15855
|
+
this.indentacaoAtual -= this.tamanhoIndentacao;
|
|
15856
|
+
this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}}`;
|
|
15857
|
+
}
|
|
15858
|
+
visitarExpressaoElvis(expressao) {
|
|
15859
|
+
this.formatarDeclaracaoOuConstruto(expressao.esquerda);
|
|
15860
|
+
this.codigoFormatado += ` ?? `;
|
|
15861
|
+
this.formatarDeclaracaoOuConstruto(expressao.direita);
|
|
15862
|
+
}
|
|
15863
|
+
visitarExpressaoFazer(expressao) {
|
|
15864
|
+
this.codigoFormatado += `fazer {${this.quebraLinha}`;
|
|
15865
|
+
this.indentacaoAtual += this.tamanhoIndentacao;
|
|
15866
|
+
for (let declaracao of expressao.caminhoFazer.declaracoes) {
|
|
15867
|
+
this.formatarDeclaracaoOuConstruto(declaracao);
|
|
15868
|
+
}
|
|
15869
|
+
this.indentacaoAtual -= this.tamanhoIndentacao;
|
|
15870
|
+
this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}} enquanto `;
|
|
15871
|
+
this.formatarDeclaracaoOuConstruto(expressao.condicaoEnquanto);
|
|
15872
|
+
}
|
|
15873
|
+
visitarExpressaoListaCompreensao(listaCompreensao) {
|
|
15874
|
+
this.codigoFormatado += `[`;
|
|
15875
|
+
this.formatarDeclaracaoOuConstruto(listaCompreensao.expressaoRetorno);
|
|
15876
|
+
this.codigoFormatado += ` para cada `;
|
|
15877
|
+
this.formatarDeclaracaoOuConstruto(listaCompreensao.referenciaVariavelIteracao);
|
|
15878
|
+
this.codigoFormatado += ` de `;
|
|
15879
|
+
this.formatarDeclaracaoOuConstruto(listaCompreensao.paraCada.vetorOuDicionario);
|
|
15880
|
+
this.codigoFormatado += `]`;
|
|
15881
|
+
}
|
|
15882
|
+
visitarExpressaoPara(expressao) {
|
|
15883
|
+
this.codigoFormatado += `para `;
|
|
15884
|
+
this.devePularLinha = false;
|
|
15885
|
+
if (expressao.inicializador) {
|
|
15886
|
+
if (Array.isArray(expressao.inicializador)) {
|
|
15887
|
+
this.deveIndentar = false;
|
|
15888
|
+
for (let declaracaoInicializador of expressao.inicializador) {
|
|
15889
|
+
this.formatarDeclaracaoOuConstruto(declaracaoInicializador);
|
|
15890
|
+
}
|
|
15891
|
+
this.deveIndentar = true;
|
|
15892
|
+
}
|
|
15893
|
+
else {
|
|
15894
|
+
this.formatarDeclaracaoOuConstruto(expressao.inicializador);
|
|
15895
|
+
}
|
|
15896
|
+
}
|
|
15897
|
+
this.codigoFormatado += `; `;
|
|
15898
|
+
this.formatarDeclaracaoOuConstruto(expressao.condicao);
|
|
15899
|
+
this.codigoFormatado += `; `;
|
|
15900
|
+
this.formatarDeclaracaoOuConstruto(expressao.incrementar);
|
|
15901
|
+
this.devePularLinha = true;
|
|
15902
|
+
this.codigoFormatado += ` {${this.quebraLinha}`;
|
|
15903
|
+
this.indentacaoAtual += this.tamanhoIndentacao;
|
|
15904
|
+
for (let declaracao of expressao.corpo.declaracoes) {
|
|
15905
|
+
this.formatarDeclaracaoOuConstruto(declaracao);
|
|
15906
|
+
}
|
|
15907
|
+
this.indentacaoAtual -= this.tamanhoIndentacao;
|
|
15908
|
+
this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}}`;
|
|
15909
|
+
}
|
|
15910
|
+
visitarExpressaoParaCada(expressao) {
|
|
15911
|
+
this.codigoFormatado += `para cada ${expressao.variavelIteracao} de `;
|
|
15912
|
+
this.formatarDeclaracaoOuConstruto(expressao.vetorOuDicionario);
|
|
15913
|
+
this.codigoFormatado += ` {${this.quebraLinha}`;
|
|
15914
|
+
this.indentacaoAtual += this.tamanhoIndentacao;
|
|
15915
|
+
for (let declaracao of expressao.corpo.declaracoes) {
|
|
15916
|
+
this.formatarDeclaracaoOuConstruto(declaracao);
|
|
15917
|
+
}
|
|
15918
|
+
this.indentacaoAtual -= this.tamanhoIndentacao;
|
|
15919
|
+
this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}}`;
|
|
15920
|
+
}
|
|
15921
|
+
visitarExpressaoSeTernario(expressao) {
|
|
15922
|
+
this.formatarDeclaracaoOuConstruto(expressao.condicao);
|
|
15923
|
+
this.codigoFormatado += ` ? `;
|
|
15924
|
+
this.formatarDeclaracaoOuConstruto(expressao.expressaoSe);
|
|
15925
|
+
this.codigoFormatado += ` : `;
|
|
15926
|
+
this.formatarDeclaracaoOuConstruto(expressao.expressaoSenao);
|
|
15927
|
+
}
|
|
15695
15928
|
obterDelimitadorTexto(expressao) {
|
|
15696
15929
|
if (this.delimitadorTexto === 'aspas-duplas') {
|
|
15697
15930
|
return '"';
|
|
@@ -15822,6 +16055,9 @@ class FormatadorDelegua {
|
|
|
15822
16055
|
visitarDeclaracaoDeExpressao(declaracao) {
|
|
15823
16056
|
this.codigoFormatado += ' '.repeat(this.indentacaoAtual);
|
|
15824
16057
|
this.formatarDeclaracaoOuConstruto(declaracao.expressao);
|
|
16058
|
+
if (!this.codigoFormatado.endsWith(this.quebraLinha)) {
|
|
16059
|
+
this.codigoFormatado += this.quebraLinha;
|
|
16060
|
+
}
|
|
15825
16061
|
}
|
|
15826
16062
|
visitarDeclaracaoDefinicaoFuncao(declaracao) {
|
|
15827
16063
|
this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}função `;
|
|
@@ -15833,7 +16069,13 @@ class FormatadorDelegua {
|
|
|
15833
16069
|
visitarDeclaracaoEnquanto(declaracao) {
|
|
15834
16070
|
this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}enquanto `;
|
|
15835
16071
|
this.formatarDeclaracaoOuConstruto(declaracao.condicao);
|
|
15836
|
-
this.
|
|
16072
|
+
this.codigoFormatado += ` {${this.quebraLinha}`;
|
|
16073
|
+
this.indentacaoAtual += this.tamanhoIndentacao;
|
|
16074
|
+
for (let declaracaoBloco of declaracao.corpo.declaracoes) {
|
|
16075
|
+
this.formatarDeclaracaoOuConstruto(declaracaoBloco);
|
|
16076
|
+
}
|
|
16077
|
+
this.indentacaoAtual -= this.tamanhoIndentacao;
|
|
16078
|
+
this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}}${this.quebraLinha}`;
|
|
15837
16079
|
}
|
|
15838
16080
|
visitarDeclaracaoEscolha(declaracao) {
|
|
15839
16081
|
this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}escolha `;
|
|
@@ -16256,7 +16498,7 @@ class FormatadorDelegua {
|
|
|
16256
16498
|
this.formatarDeclaracaoOuConstruto(expressao.valor);
|
|
16257
16499
|
}
|
|
16258
16500
|
visitarExpressaoUnaria(expressao) {
|
|
16259
|
-
let operador;
|
|
16501
|
+
let operador = '';
|
|
16260
16502
|
switch (expressao.operador.tipo) {
|
|
16261
16503
|
case delegua_1.default.INCREMENTAR:
|
|
16262
16504
|
operador = `++`;
|
|
@@ -16301,6 +16543,12 @@ class FormatadorDelegua {
|
|
|
16301
16543
|
case construtos_1.AcessoIndiceVariavel:
|
|
16302
16544
|
this.visitarExpressaoAcessoIndiceVariavel(declaracaoOuConstruto);
|
|
16303
16545
|
break;
|
|
16546
|
+
case construtos_1.AcessoMetodo:
|
|
16547
|
+
this.visitarExpressaoAcessoMetodo(declaracaoOuConstruto);
|
|
16548
|
+
break;
|
|
16549
|
+
case construtos_1.AcessoPropriedade:
|
|
16550
|
+
this.visitarExpressaoAcessoPropriedade(declaracaoOuConstruto);
|
|
16551
|
+
break;
|
|
16304
16552
|
case construtos_1.AcessoMetodoOuPropriedade:
|
|
16305
16553
|
this.visitarExpressaoAcessoMetodoOuPropriedade(declaracaoOuConstruto);
|
|
16306
16554
|
break;
|
|
@@ -16346,6 +16594,9 @@ class FormatadorDelegua {
|
|
|
16346
16594
|
case declaracoes_1.Enquanto:
|
|
16347
16595
|
this.visitarDeclaracaoEnquanto(declaracaoOuConstruto);
|
|
16348
16596
|
break;
|
|
16597
|
+
case declaracoes_1.Extensao:
|
|
16598
|
+
this.visitarDeclaracaoExtensao(declaracaoOuConstruto);
|
|
16599
|
+
break;
|
|
16349
16600
|
case declaracoes_1.Escreva:
|
|
16350
16601
|
this.visitarDeclaracaoEscreva(declaracaoOuConstruto);
|
|
16351
16602
|
break;
|
|
@@ -16370,6 +16621,9 @@ class FormatadorDelegua {
|
|
|
16370
16621
|
case declaracoes_1.Importar:
|
|
16371
16622
|
this.visitarDeclaracaoImportar(declaracaoOuConstruto);
|
|
16372
16623
|
break;
|
|
16624
|
+
case declaracoes_1.InterfaceDeclaracao:
|
|
16625
|
+
this.visitarDeclaracaoInterface(declaracaoOuConstruto);
|
|
16626
|
+
break;
|
|
16373
16627
|
case construtos_1.ImportarComoConstruto:
|
|
16374
16628
|
this.visitarExpressaoImportar(declaracaoOuConstruto);
|
|
16375
16629
|
break;
|