@designliquido/delegua 1.15.4 → 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 +10 -4
- package/analisador-semantico/analisador-semantico.d.ts.map +1 -1
- package/analisador-semantico/analisador-semantico.js +142 -22
- package/analisador-semantico/analisador-semantico.js.map +1 -1
- package/analisador-semantico/dialetos/analisador-semantico-pitugues.d.ts.map +1 -1
- package/analisador-semantico/dialetos/analisador-semantico-pitugues.js +1 -0
- package/analisador-semantico/dialetos/analisador-semantico-pitugues.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/avaliador-sintatico/avaliador-sintatico.d.ts.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.js +4 -1
- package/avaliador-sintatico/avaliador-sintatico.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-prisma.js +1 -1
- package/bibliotecas/dialetos/prisma/biblioteca-global.d.ts +1 -1
- package/bibliotecas/dialetos/prisma/biblioteca-global.js +1 -1
- package/bin/package.json +1 -1
- package/construtos/literal.d.ts +2 -1
- package/construtos/literal.d.ts.map +1 -1
- package/construtos/literal.js +2 -1
- package/construtos/literal.js.map +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/estilizador/estilizador-delegua.d.ts +7 -6
- package/estilizador/estilizador-delegua.d.ts.map +1 -1
- package/estilizador/estilizador-delegua.js +9 -0
- package/estilizador/estilizador-delegua.js.map +1 -1
- package/estilizador/regras/convencao-nomenclatura.d.ts +2 -2
- package/estilizador/regras/convencao-nomenclatura.d.ts.map +1 -1
- package/estilizador/regras/fortalecer-tipos.d.ts +2 -2
- package/estilizador/regras/fortalecer-tipos.d.ts.map +1 -1
- package/estilizador/regras/fortalecer-tipos.js.map +1 -1
- package/estilizador/regras/paradigma-consistente.d.ts +3 -16
- package/estilizador/regras/paradigma-consistente.d.ts.map +1 -1
- package/estilizador/regras/paradigma-consistente.js.map +1 -1
- package/formatadores/formatador-delegua.d.ts +20 -5
- package/formatadores/formatador-delegua.d.ts.map +1 -1
- package/formatadores/formatador-delegua.js +177 -8
- 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/estilizador/estilizador-interface.d.ts +49 -0
- package/interfaces/estilizador/estilizador-interface.d.ts.map +1 -0
- package/interfaces/{estilizador-comum-interface.js → estilizador/estilizador-interface.js} +1 -1
- package/interfaces/estilizador/estilizador-interface.js.map +1 -0
- package/interfaces/estilizador/index.d.ts +5 -0
- package/interfaces/estilizador/index.d.ts.map +1 -0
- package/interfaces/estilizador/index.js +21 -0
- package/interfaces/estilizador/index.js.map +1 -0
- package/interfaces/estilizador/opcoes-paradigma-consistente-interface.d.ts +14 -0
- package/interfaces/estilizador/opcoes-paradigma-consistente-interface.d.ts.map +1 -0
- package/interfaces/estilizador/opcoes-paradigma-consistente-interface.js +3 -0
- package/interfaces/estilizador/opcoes-paradigma-consistente-interface.js.map +1 -0
- package/interfaces/estilizador/regra-estilizacao-interface.d.ts +28 -0
- package/interfaces/estilizador/regra-estilizacao-interface.d.ts.map +1 -0
- package/interfaces/estilizador/regra-estilizacao-interface.js +3 -0
- package/interfaces/estilizador/regra-estilizacao-interface.js.map +1 -0
- package/interfaces/estilizador/violacao-estilo-interface.d.ts +26 -0
- package/interfaces/estilizador/violacao-estilo-interface.d.ts.map +1 -0
- package/interfaces/estilizador/violacao-estilo-interface.js +3 -0
- package/interfaces/estilizador/violacao-estilo-interface.js.map +1 -0
- 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/interfaces/index.d.ts +1 -1
- package/interfaces/index.d.ts.map +1 -1
- package/interfaces/index.js +1 -1
- package/interfaces/index.js.map +1 -1
- package/interfaces/simbolo-interface.d.ts +2 -1
- package/interfaces/simbolo-interface.d.ts.map +1 -1
- package/interpretador/dialetos/prisma/interpretador-prisma.d.ts +1 -1
- package/interpretador/dialetos/prisma/interpretador-prisma.js +1 -1
- package/lexador/filtro-paradigma.d.ts +1 -1
- package/lexador/filtro-paradigma.d.ts.map +1 -1
- package/lexador/filtro-paradigma.js.map +1 -1
- package/lexador/lexador.d.ts.map +1 -1
- package/lexador/lexador.js +2 -0
- package/lexador/lexador.js.map +1 -1
- package/lexador/mapeamento-paradigmas.d.ts +1 -7
- package/lexador/mapeamento-paradigmas.d.ts.map +1 -1
- package/lexador/mapeamento-paradigmas.js +3 -3
- package/lexador/mapeamento-paradigmas.js.map +1 -1
- package/lexador/simbolo.d.ts +2 -1
- package/lexador/simbolo.d.ts.map +1 -1
- package/lexador/simbolo.js +2 -1
- package/lexador/simbolo.js.map +1 -1
- package/package.json +1 -1
- package/tipos.d.ts +15 -0
- package/tipos.d.ts.map +1 -0
- package/tipos.js +3 -0
- package/tipos.js.map +1 -0
- package/tradutores/tradutor-assemblyscript.js +1 -1
- package/tradutores/tradutor-assemblyscript.js.map +1 -1
- package/tradutores/tradutor-elixir.d.ts +1 -1
- package/tradutores/tradutor-elixir.js +3 -3
- package/tradutores/tradutor-elixir.js.map +1 -1
- package/umd/delegua.js +362 -45
- package/interfaces/estilizador-comum-interface.d.ts +0 -85
- package/interfaces/estilizador-comum-interface.d.ts.map +0 -1
- package/interfaces/estilizador-comum-interface.js.map +0 -1
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)) {
|
|
@@ -503,6 +507,10 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
503
507
|
}
|
|
504
508
|
}
|
|
505
509
|
}
|
|
510
|
+
else if (declaracao.inicializador instanceof construtos_1.Chamada) {
|
|
511
|
+
// Chamadas de método/função podem retornar vetores.
|
|
512
|
+
// A validação detalhada é feita em tempo de execução.
|
|
513
|
+
}
|
|
506
514
|
else {
|
|
507
515
|
this.erro(declaracao.simbolo, `Atribuição inválida para '${declaracao.simbolo.lexema}': é esperado um vetor de elementos.`);
|
|
508
516
|
}
|
|
@@ -664,6 +672,8 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
664
672
|
}
|
|
665
673
|
// Marca como inicializada após atribuição
|
|
666
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);
|
|
667
677
|
// Atualiza tipo se a variável não foi tipada explicitamente
|
|
668
678
|
if (variavel.tipo === 'qualquer') {
|
|
669
679
|
const tipoInferido = this.obterTipoExpressao(expressao.valor);
|
|
@@ -738,10 +748,34 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
738
748
|
this.variaveis[simboloAlvo.lexema].valor = expressao.valor;
|
|
739
749
|
}
|
|
740
750
|
} */
|
|
751
|
+
return Promise.resolve();
|
|
741
752
|
}
|
|
742
753
|
async visitarDeclaracaoDeExpressao(declaracao) {
|
|
743
754
|
return await declaracao.expressao.aceitar(this);
|
|
744
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
|
+
}
|
|
745
779
|
visitarDeclaracaoAjuda(declaracao) {
|
|
746
780
|
if (declaracao.elemento) {
|
|
747
781
|
this.marcarVariaveisUsadasEmExpressao(declaracao.elemento);
|
|
@@ -756,7 +790,7 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
756
790
|
}
|
|
757
791
|
visitarDeclaracaoEscolha(declaracao) {
|
|
758
792
|
const identificadorOuLiteral = declaracao.identificadorOuLiteral;
|
|
759
|
-
const tipo = identificadorOuLiteral.tipo;
|
|
793
|
+
const tipo = identificadorOuLiteral.tipo || 'qualquer';
|
|
760
794
|
for (let caminho of declaracao.caminhos) {
|
|
761
795
|
for (let condicao of caminho.condicoes) {
|
|
762
796
|
switch (condicao.constructor) {
|
|
@@ -787,8 +821,16 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
787
821
|
}
|
|
788
822
|
return Promise.resolve();
|
|
789
823
|
}
|
|
790
|
-
visitarDeclaracaoEnquanto(declaracao) {
|
|
791
|
-
|
|
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();
|
|
792
834
|
}
|
|
793
835
|
visitarDeclaracaoFazer(declaracao) {
|
|
794
836
|
// Marca variáveis usadas na condição
|
|
@@ -796,16 +838,59 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
796
838
|
// Verifica a condição
|
|
797
839
|
return this.verificarCondicao(declaracao.condicaoEnquanto);
|
|
798
840
|
}
|
|
841
|
+
async visitarDeclaracaoPara(declaracao) {
|
|
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);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
finally {
|
|
866
|
+
this.gerenciadorEscopos.desempilharEscopo();
|
|
867
|
+
}
|
|
868
|
+
return Promise.resolve();
|
|
869
|
+
}
|
|
799
870
|
visitarDeclaracaoParaCada(declaracao) {
|
|
800
871
|
// Marca o vetor/dicionário como usado
|
|
801
872
|
this.marcarVariaveisUsadasEmExpressao(declaracao.vetorOuDicionario);
|
|
802
873
|
return Promise.resolve();
|
|
803
874
|
}
|
|
804
|
-
visitarDeclaracaoSe(declaracao) {
|
|
875
|
+
async visitarDeclaracaoSe(declaracao) {
|
|
805
876
|
// Marca variáveis usadas na condição
|
|
806
877
|
this.marcarVariaveisUsadasEmExpressao(declaracao.condicao);
|
|
807
878
|
// Verifica a condição (incluindo validação de tipos para operadores lógicos)
|
|
808
|
-
|
|
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();
|
|
809
894
|
}
|
|
810
895
|
/**
|
|
811
896
|
* Verifica uma expressão recursivamente, incluindo operações binárias
|
|
@@ -952,6 +1037,9 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
952
1037
|
const tipoEsquerda = this.obterTipoExpressao(binario.esquerda);
|
|
953
1038
|
const tipoDireita = this.obterTipoExpressao(binario.direita);
|
|
954
1039
|
const tiposNumericos = ['inteiro', 'número', 'real'];
|
|
1040
|
+
if (!tipoEsquerda || !tipoDireita) {
|
|
1041
|
+
return;
|
|
1042
|
+
}
|
|
955
1043
|
if ((tipoEsquerda === 'texto' && tiposNumericos.includes(tipoDireita)) ||
|
|
956
1044
|
(tiposNumericos.includes(tipoEsquerda) && tipoDireita === 'texto')) {
|
|
957
1045
|
this.aviso(binario.operador, `Esta comparação ocorre entre tipos ${tipoEsquerda} e ${tipoDireita}, e o resultado pode não ser o desejado.`);
|
|
@@ -1058,10 +1146,11 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1058
1146
|
case construtos_1.Variavel:
|
|
1059
1147
|
let entidadeChamadaVariavel = chamada.entidadeChamada;
|
|
1060
1148
|
const nomeFuncao = entidadeChamadaVariavel.simbolo.lexema;
|
|
1061
|
-
// Lista de funções
|
|
1062
|
-
const
|
|
1149
|
+
// Lista de funções embutidas que não precisam ser declaradas
|
|
1150
|
+
const funcoesEmbutidas = [
|
|
1063
1151
|
'inteiro',
|
|
1064
1152
|
'real',
|
|
1153
|
+
'numero',
|
|
1065
1154
|
'número',
|
|
1066
1155
|
'texto',
|
|
1067
1156
|
'leia',
|
|
@@ -1070,8 +1159,8 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1070
1159
|
];
|
|
1071
1160
|
// Classes/construtores geralmente começam com letra maiúscula
|
|
1072
1161
|
const pareceSerClasse = nomeFuncao[0] === nomeFuncao[0].toUpperCase();
|
|
1073
|
-
// Só verifica se a função existe se não for
|
|
1074
|
-
if (!
|
|
1162
|
+
// Só verifica se a função existe se não for embutidas e não parecer ser classe
|
|
1163
|
+
if (!funcoesEmbutidas.includes(nomeFuncao) &&
|
|
1075
1164
|
!pareceSerClasse &&
|
|
1076
1165
|
!this.funcoes[nomeFuncao] &&
|
|
1077
1166
|
!this.gerenciadorEscopos.buscar(nomeFuncao)) {
|
|
@@ -1253,7 +1342,10 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1253
1342
|
// Inferir tipo do inicializador se não foi especificado explicitamente
|
|
1254
1343
|
let tipoInferido = declaracao.tipo;
|
|
1255
1344
|
if (!tipoInferido && declaracao.inicializador) {
|
|
1256
|
-
|
|
1345
|
+
const tipoInicializador = this.obterTipoExpressao(declaracao.inicializador);
|
|
1346
|
+
if (tipoInicializador) {
|
|
1347
|
+
tipoInferido = tipoInicializador;
|
|
1348
|
+
}
|
|
1257
1349
|
}
|
|
1258
1350
|
// Sugestão de tipo melhor quando 'qualquer' é usado explicitamente
|
|
1259
1351
|
if (declaracao.tipoExplicito &&
|
|
@@ -1267,8 +1359,8 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1267
1359
|
textoOriginal: 'qualquer',
|
|
1268
1360
|
textoSubstituto: tipoMelhor,
|
|
1269
1361
|
linha: declaracao.simbolo.linha,
|
|
1270
|
-
colunaInicio: declaracao.simbolo.colunaInicio,
|
|
1271
|
-
colunaFim: declaracao.simbolo.colunaFim,
|
|
1362
|
+
colunaInicio: declaracao.simbolo.colunaInicio || 0,
|
|
1363
|
+
colunaFim: declaracao.simbolo.colunaFim || 0,
|
|
1272
1364
|
},
|
|
1273
1365
|
]);
|
|
1274
1366
|
}
|
|
@@ -1303,7 +1395,7 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1303
1395
|
return Promise.resolve();
|
|
1304
1396
|
}
|
|
1305
1397
|
visitarExpressaoRetornar(declaracao) {
|
|
1306
|
-
return Promise.resolve(
|
|
1398
|
+
return Promise.resolve(undefined);
|
|
1307
1399
|
}
|
|
1308
1400
|
visitarExpressaoDeVariavel(expressao) {
|
|
1309
1401
|
if (expressao instanceof construtos_1.Variavel) {
|
|
@@ -1387,11 +1479,11 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1387
1479
|
if (nomeSuperclasse === declaracao.simbolo.lexema) {
|
|
1388
1480
|
this.erro(superClasseVariavel.simbolo, `A classe '${declaracao.simbolo.lexema}' não pode herdar de si mesma.`);
|
|
1389
1481
|
}
|
|
1390
|
-
else if (!this.
|
|
1482
|
+
else if (!this.classesDeclaradas.has(nomeSuperclasse) && !this.classesExternasConhecidas.has(nomeSuperclasse)) {
|
|
1391
1483
|
this.erro(superClasseVariavel.simbolo, `Superclasse '${nomeSuperclasse}' não foi declarada.`);
|
|
1392
1484
|
}
|
|
1393
1485
|
}
|
|
1394
|
-
this.
|
|
1486
|
+
this.classesDeclaradas.add(declaracao.simbolo.lexema);
|
|
1395
1487
|
this.classesRegistradas.set(declaracao.simbolo.lexema, declaracao);
|
|
1396
1488
|
// Visita corpos dos métodos com contexto de classe ativo
|
|
1397
1489
|
const classeAnterior = this.classeAtualEmAnalise;
|
|
@@ -1403,7 +1495,7 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1403
1495
|
}
|
|
1404
1496
|
this.classeAtualEmAnalise = classeAnterior;
|
|
1405
1497
|
}
|
|
1406
|
-
visitarDeclaracaoDefinicaoFuncao(declaracao) {
|
|
1498
|
+
async visitarDeclaracaoDefinicaoFuncao(declaracao) {
|
|
1407
1499
|
var _a;
|
|
1408
1500
|
if (declaracao.funcao.tipo === undefined) {
|
|
1409
1501
|
this.erro(declaracao.simbolo, `Declaração de retorno da função é inválido.`);
|
|
@@ -1419,7 +1511,10 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1419
1511
|
this.erro(declaracao.simbolo, `Função '${declaracao.simbolo.lexema}' deve retornar '${tipoRetornoFuncao}' em todos os caminhos de execução.`);
|
|
1420
1512
|
}
|
|
1421
1513
|
}
|
|
1422
|
-
|
|
1514
|
+
let retornos = [];
|
|
1515
|
+
for (const declaracaoCorpo of declaracao.funcao.corpo) {
|
|
1516
|
+
retornos = retornos.concat((0, comum_1.buscarRetornos)(declaracaoCorpo));
|
|
1517
|
+
}
|
|
1423
1518
|
// Filtra retornos com tipo 'qualquer' (não determinado em tempo de análise sintática)
|
|
1424
1519
|
const retornosComTipoIndeterminado = retornos.filter((retorno) => retorno.valor !== null &&
|
|
1425
1520
|
retorno.valor !== undefined &&
|
|
@@ -1430,7 +1525,8 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1430
1525
|
declaracao.funcao.tipoExplicito &&
|
|
1431
1526
|
retornosComTipoIndeterminado.length > 0) {
|
|
1432
1527
|
const retornoComValor = retornosComTipoIndeterminado[0];
|
|
1433
|
-
const
|
|
1528
|
+
const valorRetorno = retornoComValor.valor;
|
|
1529
|
+
const tipoInferido = this.obterTipoExpressao(valorRetorno);
|
|
1434
1530
|
if (tipoInferido && tipoInferido !== 'qualquer') {
|
|
1435
1531
|
this.erro(declaracao.simbolo, `A função não pode ter nenhum tipo de retorno. Tipo inferido do retorno: '${tipoInferido}'.`);
|
|
1436
1532
|
}
|
|
@@ -1458,14 +1554,38 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1458
1554
|
this.funcoes[declaracao.simbolo.lexema] = {
|
|
1459
1555
|
valor: declaracao.funcao,
|
|
1460
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
|
+
}
|
|
1461
1578
|
return Promise.resolve();
|
|
1462
1579
|
}
|
|
1463
1580
|
verificarVariaveisNaoUsadas() {
|
|
1464
1581
|
const naoUsadas = this.gerenciadorEscopos.obterVariaveisNaoUsadas();
|
|
1465
1582
|
for (let variavel of naoUsadas) {
|
|
1466
1583
|
// Verifica se já existe um erro associado à variável.
|
|
1467
|
-
const temErro = this.diagnosticos.some((d) =>
|
|
1468
|
-
|
|
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
|
+
});
|
|
1469
1589
|
// Se a variável já tem um erro associado, não emitir aviso de não usada.
|
|
1470
1590
|
if (temErro) {
|
|
1471
1591
|
continue;
|
|
@@ -1480,7 +1600,7 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1480
1600
|
}
|
|
1481
1601
|
async analisar(declaracoes) {
|
|
1482
1602
|
this.gerenciadorEscopos = new gerenciador_escopos_1.GerenciadorEscopos();
|
|
1483
|
-
this.
|
|
1603
|
+
this.classesDeclaradas = new Set();
|
|
1484
1604
|
this.classesRegistradas = new Map();
|
|
1485
1605
|
this.classeAtualEmAnalise = null;
|
|
1486
1606
|
this.atual = 0;
|
|
@@ -1662,6 +1782,13 @@ const comum_1 = __importDefault(require("../tipos-de-simbolos/comum"));
|
|
|
1662
1782
|
* de tipos de símbolos comuns entre todos os dialetos.
|
|
1663
1783
|
*/
|
|
1664
1784
|
class AvaliadorSintaticoBase {
|
|
1785
|
+
constructor() {
|
|
1786
|
+
this.simbolos = [];
|
|
1787
|
+
this.erros = [];
|
|
1788
|
+
this.hashArquivo = -1;
|
|
1789
|
+
this.atual = 0;
|
|
1790
|
+
this.blocos = 0;
|
|
1791
|
+
}
|
|
1665
1792
|
erro(simbolo, mensagemDeErro) {
|
|
1666
1793
|
const excecao = new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(simbolo, mensagemDeErro);
|
|
1667
1794
|
return excecao;
|
|
@@ -1693,6 +1820,8 @@ class AvaliadorSintaticoBase {
|
|
|
1693
1820
|
return this.simbolos[this.atual].tipo === tipo;
|
|
1694
1821
|
}
|
|
1695
1822
|
verificarTipoProximoSimbolo(tipo) {
|
|
1823
|
+
if (this.atual + 1 >= this.simbolos.length)
|
|
1824
|
+
return false;
|
|
1696
1825
|
return this.simbolos[this.atual + 1].tipo === tipo;
|
|
1697
1826
|
}
|
|
1698
1827
|
estaNoFinal() {
|
|
@@ -1852,7 +1981,7 @@ class AvaliadorSintaticoBase {
|
|
|
1852
1981
|
}
|
|
1853
1982
|
const parametro = {};
|
|
1854
1983
|
if (this.simbolos[this.atual].tipo === comum_1.default.MULTIPLICACAO) {
|
|
1855
|
-
this.
|
|
1984
|
+
this.avancarEDevolverAnterior();
|
|
1856
1985
|
parametro.abrangencia = 'multiplo';
|
|
1857
1986
|
}
|
|
1858
1987
|
else {
|
|
@@ -2318,7 +2447,10 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
2318
2447
|
case delegua_2.default.TEXTO:
|
|
2319
2448
|
const simboloNumeroTexto = this.avancarEDevolverAnterior();
|
|
2320
2449
|
const tipoInferido = (0, inferenciador_1.inferirTipoVariavel)(simboloNumeroTexto.literal);
|
|
2321
|
-
|
|
2450
|
+
const delimitadorTexto = simboloNumeroTexto.tipo === delegua_2.default.TEXTO
|
|
2451
|
+
? simboloNumeroTexto.delimitadorTexto
|
|
2452
|
+
: undefined;
|
|
2453
|
+
return new construtos_1.Literal(this.hashArquivo, Number(simboloNumeroTexto.linha), simboloNumeroTexto.literal, tipoInferido, delimitadorTexto);
|
|
2322
2454
|
case delegua_2.default.PARA:
|
|
2323
2455
|
const simboloPara = this.avancarEDevolverAnterior();
|
|
2324
2456
|
return await this.paraComoConstruto(simboloPara);
|
|
@@ -8316,7 +8448,7 @@ class AvaliadorSintaticoPrisma extends avaliador_sintatico_base_1.AvaliadorSinta
|
|
|
8316
8448
|
inicializarPilhaEscopos() {
|
|
8317
8449
|
this.pilhaEscopos = new pilha_escopos_1.PilhaEscopos();
|
|
8318
8450
|
this.pilhaEscopos.empilhar(new informacao_escopo_1.InformacaoEscopo());
|
|
8319
|
-
// Registrar funções nativas (
|
|
8451
|
+
// Registrar funções nativas (embutidos) do Prisma no escopo do parser
|
|
8320
8452
|
// para evitar erros de variável não definida durante análise semântica
|
|
8321
8453
|
this.pilhaEscopos.definirInformacoesVariavel('tipo', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('tipo', 'função', true, [
|
|
8322
8454
|
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('valor', 'qualquer'),
|
|
@@ -13369,11 +13501,12 @@ exports.ListaCompreensao = ListaCompreensao;
|
|
|
13369
13501
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13370
13502
|
exports.Literal = void 0;
|
|
13371
13503
|
class Literal {
|
|
13372
|
-
constructor(hashArquivo, linha, valor, tipo = 'qualquer') {
|
|
13504
|
+
constructor(hashArquivo, linha, valor, tipo = 'qualquer', delimitadorTexto) {
|
|
13373
13505
|
this.linha = linha;
|
|
13374
13506
|
this.hashArquivo = hashArquivo;
|
|
13375
13507
|
this.valor = valor;
|
|
13376
13508
|
this.tipo = tipo;
|
|
13509
|
+
this.delimitadorTexto = delimitadorTexto;
|
|
13377
13510
|
}
|
|
13378
13511
|
async aceitar(visitante) {
|
|
13379
13512
|
return await visitante.visitarExpressaoLiteral(this);
|
|
@@ -14467,6 +14600,9 @@ exports.Expressao = Expressao;
|
|
|
14467
14600
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14468
14601
|
exports.Extensao = void 0;
|
|
14469
14602
|
const declaracao_1 = require("./declaracao");
|
|
14603
|
+
/**
|
|
14604
|
+
* Declaração de Extensão de Classe.
|
|
14605
|
+
*/
|
|
14470
14606
|
class Extensao extends declaracao_1.Declaracao {
|
|
14471
14607
|
constructor(simboloTipo, metodos, ehGlobal, hashArquivo) {
|
|
14472
14608
|
super(Number(simboloTipo.linha), hashArquivo);
|
|
@@ -14999,6 +15135,7 @@ exports.Var = Var;
|
|
|
14999
15135
|
"use strict";
|
|
15000
15136
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15001
15137
|
exports.EstilizadorDelegua = void 0;
|
|
15138
|
+
const formatadores_1 = require("../formatadores");
|
|
15002
15139
|
/**
|
|
15003
15140
|
* Estilizador de código para Delégua.
|
|
15004
15141
|
* Aplica transformações no AST para enforcar convenções e melhorar qualidade do código.
|
|
@@ -15225,10 +15362,18 @@ class EstilizadorDelegua {
|
|
|
15225
15362
|
this.modoValidacao = false;
|
|
15226
15363
|
return violacoesEncontradas;
|
|
15227
15364
|
}
|
|
15365
|
+
estilizarEFormatar(declaracoes, opcoesFormatacao = {}) {
|
|
15366
|
+
var _a;
|
|
15367
|
+
const declaracoesEstilizadas = this.estilizar(declaracoes);
|
|
15368
|
+
const formatador = new formatadores_1.FormatadorDelegua(opcoesFormatacao.quebraLinha || '\n', (_a = opcoesFormatacao.tamanhoIndentacao) !== null && _a !== void 0 ? _a : 4, {
|
|
15369
|
+
delimitadorTexto: opcoesFormatacao.delimitadorTexto,
|
|
15370
|
+
});
|
|
15371
|
+
return formatador.formatar(declaracoesEstilizadas);
|
|
15372
|
+
}
|
|
15228
15373
|
}
|
|
15229
15374
|
exports.EstilizadorDelegua = EstilizadorDelegua;
|
|
15230
15375
|
|
|
15231
|
-
},{}],125:[function(require,module,exports){
|
|
15376
|
+
},{"../formatadores":134}],125:[function(require,module,exports){
|
|
15232
15377
|
"use strict";
|
|
15233
15378
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15234
15379
|
if (k2 === undefined) k2 = k;
|
|
@@ -15642,13 +15787,152 @@ const delegua_1 = __importDefault(require("../tipos-de-simbolos/delegua"));
|
|
|
15642
15787
|
* Normalmente usado por IDEs, mas pode ser usado por linha de comando ou programaticamente.
|
|
15643
15788
|
*/
|
|
15644
15789
|
class FormatadorDelegua {
|
|
15645
|
-
constructor(quebraLinha, tamanhoIndentacao = 4) {
|
|
15790
|
+
constructor(quebraLinha, tamanhoIndentacao = 4, opcoes = {}) {
|
|
15646
15791
|
this.quebraLinha = quebraLinha;
|
|
15647
15792
|
this.tamanhoIndentacao = tamanhoIndentacao;
|
|
15648
15793
|
this.indentacaoAtual = 0;
|
|
15649
15794
|
this.codigoFormatado = '';
|
|
15650
15795
|
this.devePularLinha = true;
|
|
15651
15796
|
this.deveIndentar = true;
|
|
15797
|
+
this.delimitadorTexto = opcoes.delimitadorTexto || 'aspas-simples';
|
|
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
|
+
}
|
|
15928
|
+
obterDelimitadorTexto(expressao) {
|
|
15929
|
+
if (this.delimitadorTexto === 'aspas-duplas') {
|
|
15930
|
+
return '"';
|
|
15931
|
+
}
|
|
15932
|
+
if (this.delimitadorTexto === 'preservar' && expressao.delimitadorTexto) {
|
|
15933
|
+
return expressao.delimitadorTexto;
|
|
15934
|
+
}
|
|
15935
|
+
return "'";
|
|
15652
15936
|
}
|
|
15653
15937
|
/* istanbul ignore next */
|
|
15654
15938
|
visitarExpressaoTuplaN(expressao) {
|
|
@@ -15688,7 +15972,7 @@ class FormatadorDelegua {
|
|
|
15688
15972
|
}
|
|
15689
15973
|
visitarDeclaracaoComentario(declaracao) {
|
|
15690
15974
|
if (declaracao.multilinha) {
|
|
15691
|
-
this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}
|
|
15975
|
+
this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}/*${this.quebraLinha}`;
|
|
15692
15976
|
for (let linhaConteudo of declaracao.conteudo) {
|
|
15693
15977
|
this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)} ${linhaConteudo.replace(/\s+/g, ' ')}${this.quebraLinha}`;
|
|
15694
15978
|
}
|
|
@@ -15771,6 +16055,9 @@ class FormatadorDelegua {
|
|
|
15771
16055
|
visitarDeclaracaoDeExpressao(declaracao) {
|
|
15772
16056
|
this.codigoFormatado += ' '.repeat(this.indentacaoAtual);
|
|
15773
16057
|
this.formatarDeclaracaoOuConstruto(declaracao.expressao);
|
|
16058
|
+
if (!this.codigoFormatado.endsWith(this.quebraLinha)) {
|
|
16059
|
+
this.codigoFormatado += this.quebraLinha;
|
|
16060
|
+
}
|
|
15774
16061
|
}
|
|
15775
16062
|
visitarDeclaracaoDefinicaoFuncao(declaracao) {
|
|
15776
16063
|
this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}função `;
|
|
@@ -15782,7 +16069,13 @@ class FormatadorDelegua {
|
|
|
15782
16069
|
visitarDeclaracaoEnquanto(declaracao) {
|
|
15783
16070
|
this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}enquanto `;
|
|
15784
16071
|
this.formatarDeclaracaoOuConstruto(declaracao.condicao);
|
|
15785
|
-
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}`;
|
|
15786
16079
|
}
|
|
15787
16080
|
visitarDeclaracaoEscolha(declaracao) {
|
|
15788
16081
|
this.codigoFormatado += `${' '.repeat(this.indentacaoAtual)}escolha `;
|
|
@@ -16147,13 +16440,19 @@ class FormatadorDelegua {
|
|
|
16147
16440
|
}
|
|
16148
16441
|
visitarExpressaoLiteral(expressao) {
|
|
16149
16442
|
if (typeof expressao.valor === 'string') {
|
|
16150
|
-
const
|
|
16443
|
+
const delimitador = this.obterDelimitadorTexto(expressao);
|
|
16444
|
+
let valorTexto = expressao.valor
|
|
16151
16445
|
.replace(/\\/g, '\\\\')
|
|
16152
16446
|
.replace(/\r/g, '\\r')
|
|
16153
16447
|
.replace(/\n/g, '\\n')
|
|
16154
|
-
.replace(/\t/g, '\\t')
|
|
16155
|
-
|
|
16156
|
-
|
|
16448
|
+
.replace(/\t/g, '\\t');
|
|
16449
|
+
if (delimitador === "'") {
|
|
16450
|
+
valorTexto = valorTexto.replace(/'/g, "\\'");
|
|
16451
|
+
}
|
|
16452
|
+
else {
|
|
16453
|
+
valorTexto = valorTexto.replace(/"/g, '\\"');
|
|
16454
|
+
}
|
|
16455
|
+
this.codigoFormatado += `${delimitador}${valorTexto}${delimitador}`;
|
|
16157
16456
|
return;
|
|
16158
16457
|
}
|
|
16159
16458
|
if (['logico', 'lógico'].includes(expressao.tipo)) {
|
|
@@ -16199,7 +16498,7 @@ class FormatadorDelegua {
|
|
|
16199
16498
|
this.formatarDeclaracaoOuConstruto(expressao.valor);
|
|
16200
16499
|
}
|
|
16201
16500
|
visitarExpressaoUnaria(expressao) {
|
|
16202
|
-
let operador;
|
|
16501
|
+
let operador = '';
|
|
16203
16502
|
switch (expressao.operador.tipo) {
|
|
16204
16503
|
case delegua_1.default.INCREMENTAR:
|
|
16205
16504
|
operador = `++`;
|
|
@@ -16244,6 +16543,12 @@ class FormatadorDelegua {
|
|
|
16244
16543
|
case construtos_1.AcessoIndiceVariavel:
|
|
16245
16544
|
this.visitarExpressaoAcessoIndiceVariavel(declaracaoOuConstruto);
|
|
16246
16545
|
break;
|
|
16546
|
+
case construtos_1.AcessoMetodo:
|
|
16547
|
+
this.visitarExpressaoAcessoMetodo(declaracaoOuConstruto);
|
|
16548
|
+
break;
|
|
16549
|
+
case construtos_1.AcessoPropriedade:
|
|
16550
|
+
this.visitarExpressaoAcessoPropriedade(declaracaoOuConstruto);
|
|
16551
|
+
break;
|
|
16247
16552
|
case construtos_1.AcessoMetodoOuPropriedade:
|
|
16248
16553
|
this.visitarExpressaoAcessoMetodoOuPropriedade(declaracaoOuConstruto);
|
|
16249
16554
|
break;
|
|
@@ -16271,6 +16576,9 @@ class FormatadorDelegua {
|
|
|
16271
16576
|
case declaracoes_1.Classe:
|
|
16272
16577
|
this.visitarDeclaracaoClasse(declaracaoOuConstruto);
|
|
16273
16578
|
break;
|
|
16579
|
+
case declaracoes_1.Comentario:
|
|
16580
|
+
this.visitarDeclaracaoComentario(declaracaoOuConstruto);
|
|
16581
|
+
break;
|
|
16274
16582
|
case declaracoes_1.Continua:
|
|
16275
16583
|
this.visitarExpressaoContinua(declaracaoOuConstruto);
|
|
16276
16584
|
break;
|
|
@@ -16286,6 +16594,9 @@ class FormatadorDelegua {
|
|
|
16286
16594
|
case declaracoes_1.Enquanto:
|
|
16287
16595
|
this.visitarDeclaracaoEnquanto(declaracaoOuConstruto);
|
|
16288
16596
|
break;
|
|
16597
|
+
case declaracoes_1.Extensao:
|
|
16598
|
+
this.visitarDeclaracaoExtensao(declaracaoOuConstruto);
|
|
16599
|
+
break;
|
|
16289
16600
|
case declaracoes_1.Escreva:
|
|
16290
16601
|
this.visitarDeclaracaoEscreva(declaracaoOuConstruto);
|
|
16291
16602
|
break;
|
|
@@ -16310,6 +16621,9 @@ class FormatadorDelegua {
|
|
|
16310
16621
|
case declaracoes_1.Importar:
|
|
16311
16622
|
this.visitarDeclaracaoImportar(declaracaoOuConstruto);
|
|
16312
16623
|
break;
|
|
16624
|
+
case declaracoes_1.InterfaceDeclaracao:
|
|
16625
|
+
this.visitarDeclaracaoInterface(declaracaoOuConstruto);
|
|
16626
|
+
break;
|
|
16313
16627
|
case construtos_1.ImportarComoConstruto:
|
|
16314
16628
|
this.visitarExpressaoImportar(declaracaoOuConstruto);
|
|
16315
16629
|
break;
|
|
@@ -17173,7 +17487,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17173
17487
|
__exportStar(require("./avaliador-sintatico-interface"), exports);
|
|
17174
17488
|
__exportStar(require("./componente-modulo-classe-interface"), exports);
|
|
17175
17489
|
__exportStar(require("./componente-modulo-funcao-interface"), exports);
|
|
17176
|
-
__exportStar(require("./estilizador-
|
|
17490
|
+
__exportStar(require("./estilizador/estilizador-interface"), exports);
|
|
17177
17491
|
__exportStar(require("./formatador-comum-interface"), exports);
|
|
17178
17492
|
__exportStar(require("./interpretador-com-depuracao-interface"), exports);
|
|
17179
17493
|
__exportStar(require("./interpretador-interface"), exports);
|
|
@@ -17194,7 +17508,7 @@ __exportStar(require("./construtos"), exports);
|
|
|
17194
17508
|
__exportStar(require("./erros"), exports);
|
|
17195
17509
|
__exportStar(require("./retornos"), exports);
|
|
17196
17510
|
|
|
17197
|
-
},{"./avaliador-sintatico-interface":139,"./componente-modulo-classe-interface":140,"./componente-modulo-funcao-interface":141,"./construtos":142,"./erros":146,"./estilizador-
|
|
17511
|
+
},{"./avaliador-sintatico-interface":139,"./componente-modulo-classe-interface":140,"./componente-modulo-funcao-interface":141,"./construtos":142,"./erros":146,"./estilizador/estilizador-interface":147,"./formatador-comum-interface":148,"./interpretador-com-depuracao-interface":150,"./interpretador-interface":151,"./lexador-interface":152,"./modulo-interface":153,"./parametro-interface":154,"./pilha-interface":155,"./primitiva-interface":156,"./resolvedor-interface":157,"./resultado-parcial-interpretador-interface":158,"./retornos":159,"./retornos/retorno-execucao-interface":162,"./simbolo-interface":165,"./tradutor-interface":166,"./variavel-interface":167,"./visitante-comum-interface":168,"./visitante-delegua-interface":169}],150:[function(require,module,exports){
|
|
17198
17512
|
"use strict";
|
|
17199
17513
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17200
17514
|
|
|
@@ -26131,6 +26445,8 @@ class Lexador {
|
|
|
26131
26445
|
if (caractere === delimitador) {
|
|
26132
26446
|
this.avancar();
|
|
26133
26447
|
this.adicionarSimbolo(delegua_1.default.TEXTO, valor);
|
|
26448
|
+
const ultimoSimbolo = this.simbolos[this.simbolos.length - 1];
|
|
26449
|
+
ultimoSimbolo.delimitadorTexto = delimitador;
|
|
26134
26450
|
return;
|
|
26135
26451
|
}
|
|
26136
26452
|
if (caractere === '\0' && this.eUltimaLinha()) {
|
|
@@ -26739,11 +27055,11 @@ function obterMapaLexemaParaParadigma() {
|
|
|
26739
27055
|
*/
|
|
26740
27056
|
function obterFormaAlternativa(lexema, paradigmaAlvo) {
|
|
26741
27057
|
var _a, _b;
|
|
26742
|
-
const
|
|
27058
|
+
const lexemaMinusculo = lexema.toLowerCase();
|
|
26743
27059
|
// Encontra o grupo que contém este lexema
|
|
26744
27060
|
for (const grupo of exports.gruposPalavrasParadigma) {
|
|
26745
|
-
const temImperativo = (_a = grupo.imperativo) === null || _a === void 0 ? void 0 : _a.some((p) => p ===
|
|
26746
|
-
const temInfinitivo = (_b = grupo.infinitivo) === null || _b === void 0 ? void 0 : _b.some((p) => p ===
|
|
27061
|
+
const temImperativo = (_a = grupo.imperativo) === null || _a === void 0 ? void 0 : _a.some((p) => p === lexemaMinusculo);
|
|
27062
|
+
const temInfinitivo = (_b = grupo.infinitivo) === null || _b === void 0 ? void 0 : _b.some((p) => p === lexemaMinusculo);
|
|
26747
27063
|
if (temImperativo || temInfinitivo) {
|
|
26748
27064
|
// Retorna a primeira forma do paradigma alvo
|
|
26749
27065
|
if (paradigmaAlvo === 'imperativo' && grupo.imperativo && grupo.imperativo.length > 0) {
|
|
@@ -27337,7 +27653,7 @@ exports.palavrasReservadasMicroGramatica = {
|
|
|
27337
27653
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27338
27654
|
exports.Simbolo = void 0;
|
|
27339
27655
|
class Simbolo {
|
|
27340
|
-
constructor(tipo, lexema, literal, linha, hashArquivo, colunaInicio = 0, colunaFim = 0) {
|
|
27656
|
+
constructor(tipo, lexema, literal, linha, hashArquivo, colunaInicio = 0, colunaFim = 0, delimitadorTexto) {
|
|
27341
27657
|
this.tipo = tipo;
|
|
27342
27658
|
this.lexema = lexema;
|
|
27343
27659
|
this.literal = literal;
|
|
@@ -27345,6 +27661,7 @@ class Simbolo {
|
|
|
27345
27661
|
this.hashArquivo = hashArquivo;
|
|
27346
27662
|
this.colunaInicio = colunaInicio;
|
|
27347
27663
|
this.colunaFim = colunaFim;
|
|
27664
|
+
this.delimitadorTexto = delimitadorTexto;
|
|
27348
27665
|
}
|
|
27349
27666
|
paraTexto() {
|
|
27350
27667
|
return this.tipo + ' ' + this.lexema + ' ' + this.literal;
|
|
@@ -43475,7 +43792,7 @@ class TradutorAssemblyScript {
|
|
|
43475
43792
|
}
|
|
43476
43793
|
traduzirDeclaracaoTendoComo(declaracaoTendoComo) {
|
|
43477
43794
|
// TendoComo is a resource management pattern (like try-with-resources in Java)
|
|
43478
|
-
// AssemblyScript doesn't have
|
|
43795
|
+
// AssemblyScript doesn't have embutidos support, so we'll just treat it as a scope
|
|
43479
43796
|
let resultado = `// tendo ${declaracaoTendoComo.simboloVariavel.lexema} como recurso\n`;
|
|
43480
43797
|
resultado += ' '.repeat(this.indentacao);
|
|
43481
43798
|
resultado += `let ${declaracaoTendoComo.simboloVariavel.lexema} = `;
|
|
@@ -44824,7 +45141,7 @@ class TradutorElixir {
|
|
|
44824
45141
|
return Promise.resolve(`${objeto}.${metodo}`);
|
|
44825
45142
|
}
|
|
44826
45143
|
/**
|
|
44827
|
-
* Mapeia métodos
|
|
45144
|
+
* Mapeia métodos embutidos de Delégua para Elixir
|
|
44828
45145
|
*/
|
|
44829
45146
|
mapearMetodoBuiltIn(metodo, objeto, argumentos) {
|
|
44830
45147
|
switch (metodo) {
|
|
@@ -44956,7 +45273,7 @@ class TradutorElixir {
|
|
|
44956
45273
|
const acessoMetodo = expressao.entidadeChamada;
|
|
44957
45274
|
const objeto = await acessoMetodo.objeto.aceitar(this);
|
|
44958
45275
|
const metodo = this.converterIdentificador(acessoMetodo.nomeMetodo);
|
|
44959
|
-
// Mapear métodos
|
|
45276
|
+
// Mapear métodos embutidos
|
|
44960
45277
|
const metodoMapeado = this.mapearMetodoBuiltIn(metodo, objeto, argumentos);
|
|
44961
45278
|
if (metodoMapeado) {
|
|
44962
45279
|
return Promise.resolve(metodoMapeado);
|
|
@@ -44968,7 +45285,7 @@ class TradutorElixir {
|
|
|
44968
45285
|
const acesso = expressao.entidadeChamada;
|
|
44969
45286
|
const objeto = await acesso.objeto.aceitar(this);
|
|
44970
45287
|
const simbolo = this.converterIdentificador(acesso.simbolo.lexema);
|
|
44971
|
-
// Mapear métodos
|
|
45288
|
+
// Mapear métodos embutidos
|
|
44972
45289
|
const metodoMapeado = this.mapearMetodoBuiltIn(simbolo, objeto, argumentos);
|
|
44973
45290
|
if (metodoMapeado) {
|
|
44974
45291
|
return Promise.resolve(metodoMapeado);
|