@designliquido/delegua 1.23.2 → 1.23.3
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/avaliador-sintatico/avaliador-sintatico.d.ts.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.js +49 -47
- package/avaliador-sintatico/avaliador-sintatico.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js +36 -19
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js.map +1 -1
- package/bin/package.json +1 -1
- package/package.json +1 -1
- package/umd/delegua.js +84 -65
package/umd/delegua.js
CHANGED
|
@@ -2408,6 +2408,28 @@ const primitivas_dicionario_1 = __importDefault(require("../bibliotecas/primitiv
|
|
|
2408
2408
|
const primitivas_numero_1 = __importDefault(require("../bibliotecas/primitivas-numero"));
|
|
2409
2409
|
const primitivas_texto_1 = __importDefault(require("../bibliotecas/primitivas-texto"));
|
|
2410
2410
|
const primitivas_vetor_1 = __importDefault(require("../bibliotecas/primitivas-vetor"));
|
|
2411
|
+
// Constante usada em "declaracaoRetorna()"
|
|
2412
|
+
const simbolosInicioExpressao = new Set([
|
|
2413
|
+
delegua_2.default.CHAVE_ESQUERDA,
|
|
2414
|
+
delegua_2.default.COLCHETE_ESQUERDO,
|
|
2415
|
+
delegua_2.default.FALSO,
|
|
2416
|
+
delegua_2.default.FUNCAO,
|
|
2417
|
+
delegua_2.default.FUNÇÃO,
|
|
2418
|
+
delegua_2.default.IDENTIFICADOR,
|
|
2419
|
+
delegua_2.default.ISTO,
|
|
2420
|
+
delegua_2.default.NAO,
|
|
2421
|
+
delegua_2.default.NEGACAO,
|
|
2422
|
+
delegua_2.default.NUMERO,
|
|
2423
|
+
delegua_2.default.NULO,
|
|
2424
|
+
delegua_2.default.PARENTESE_ESQUERDO,
|
|
2425
|
+
delegua_2.default.SUPER,
|
|
2426
|
+
delegua_2.default.TEXTO,
|
|
2427
|
+
delegua_2.default.VERDADEIRO,
|
|
2428
|
+
delegua_2.default.ADICAO,
|
|
2429
|
+
delegua_2.default.SUBTRACAO,
|
|
2430
|
+
delegua_2.default.INCREMENTAR,
|
|
2431
|
+
delegua_2.default.DECREMENTAR
|
|
2432
|
+
]);
|
|
2411
2433
|
/**
|
|
2412
2434
|
* O avaliador sintático (_Parser_) é responsável por transformar os símbolos do Lexador em estruturas de alto nível.
|
|
2413
2435
|
* Essas estruturas de alto nível são as partes que executam lógica de programação de fato.
|
|
@@ -4017,24 +4039,9 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4017
4039
|
}
|
|
4018
4040
|
async declaracaoRetorna() {
|
|
4019
4041
|
const simboloChave = this.simbolos[this.atual - 1];
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
delegua_2.default.COLCHETE_ESQUERDO,
|
|
4024
|
-
delegua_2.default.FALSO,
|
|
4025
|
-
delegua_2.default.FUNCAO,
|
|
4026
|
-
delegua_2.default.FUNÇÃO,
|
|
4027
|
-
delegua_2.default.IDENTIFICADOR,
|
|
4028
|
-
delegua_2.default.ISTO,
|
|
4029
|
-
delegua_2.default.NAO,
|
|
4030
|
-
delegua_2.default.NEGACAO,
|
|
4031
|
-
delegua_2.default.NUMERO,
|
|
4032
|
-
delegua_2.default.NULO,
|
|
4033
|
-
delegua_2.default.PARENTESE_ESQUERDO,
|
|
4034
|
-
delegua_2.default.SUPER,
|
|
4035
|
-
delegua_2.default.TEXTO,
|
|
4036
|
-
delegua_2.default.VERDADEIRO,
|
|
4037
|
-
].includes(this.simbolos[this.atual].tipo)) {
|
|
4042
|
+
const simboloAtual = this.simbolos[this.atual];
|
|
4043
|
+
let valor;
|
|
4044
|
+
if (simboloAtual && simbolosInicioExpressao.has(simboloAtual.tipo)) {
|
|
4038
4045
|
valor = await this.expressao();
|
|
4039
4046
|
}
|
|
4040
4047
|
// Ponto-e-vírgula é opcional aqui.
|
|
@@ -4326,51 +4333,46 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4326
4333
|
*/
|
|
4327
4334
|
async declaracaoDeVariaveis() {
|
|
4328
4335
|
const simboloVariavel = this.simboloAnterior();
|
|
4329
|
-
const identificadores = [];
|
|
4330
|
-
const retorno = [];
|
|
4331
|
-
let tipo = 'qualquer';
|
|
4332
4336
|
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.CHAVE_ESQUERDA)) {
|
|
4333
4337
|
return await this.declaracaoDesestruturacaoVariavel();
|
|
4334
4338
|
}
|
|
4339
|
+
const identificadores = [];
|
|
4335
4340
|
do {
|
|
4336
4341
|
identificadores.push(this.consumir(delegua_2.default.IDENTIFICADOR, 'Esperado nome da variável.'));
|
|
4337
4342
|
} while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.VIRGULA));
|
|
4343
|
+
let tipo = 'qualquer';
|
|
4338
4344
|
let tipoExplicito = false;
|
|
4339
4345
|
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.DOIS_PONTOS)) {
|
|
4340
4346
|
tipo = this.verificarDefinicaoTipoAtual();
|
|
4341
4347
|
tipoExplicito = true;
|
|
4342
4348
|
this.avancarEDevolverAnterior();
|
|
4343
4349
|
}
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4350
|
+
const retorno = [];
|
|
4351
|
+
const decoradores = Array.from(this.pilhaDecoradores);
|
|
4352
|
+
const temAtribuicao = this.verificarSeSimboloAtualEIgualA(delegua_2.default.IGUAL, delegua_2.default.SETA_ESQUERDA);
|
|
4353
|
+
if (!temAtribuicao) {
|
|
4354
|
+
for (const identificador of identificadores) {
|
|
4347
4355
|
this.pilhaEscopos.definirInformacoesVariavel(identificador.lexema, new informacao_elemento_sintatico_1.InformacaoElementoSintatico(identificador.lexema, tipo));
|
|
4348
|
-
retorno.push(new declaracoes_1.Var(identificador, undefined, tipo, tipoExplicito,
|
|
4356
|
+
retorno.push(new declaracoes_1.Var(identificador, undefined, tipo, tipoExplicito, decoradores));
|
|
4349
4357
|
}
|
|
4350
|
-
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
4351
|
-
this.pilhaDecoradores = [];
|
|
4352
|
-
return retorno;
|
|
4353
4358
|
}
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
for (let [indice, identificador] of identificadores.entries()) {
|
|
4362
|
-
const tipoOriginal = tipo; // Preserva o tipo antes da inferência
|
|
4363
|
-
tipo =
|
|
4364
|
-
this.logicaComumInferenciaTiposVariaveisEConstantes(inicializadores[indice], tipo) ?? tipo;
|
|
4365
|
-
if (tipo !== 'dicionário') {
|
|
4366
|
-
this.pilhaEscopos.definirInformacoesVariavel(identificador.lexema, new informacao_elemento_sintatico_1.InformacaoElementoSintatico(identificador.lexema, tipo));
|
|
4359
|
+
else {
|
|
4360
|
+
const inicializadores = [];
|
|
4361
|
+
do {
|
|
4362
|
+
inicializadores.push(await this.expressao());
|
|
4363
|
+
} while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.VIRGULA));
|
|
4364
|
+
if (identificadores.length !== inicializadores.length) {
|
|
4365
|
+
throw this.erro(simboloVariavel, 'Quantidade de identificadores à esquerda do igual é diferente da quantidade de valores à direita.');
|
|
4367
4366
|
}
|
|
4368
|
-
|
|
4369
|
-
const
|
|
4370
|
-
this.
|
|
4367
|
+
for (let [indice, identificador] of identificadores.entries()) {
|
|
4368
|
+
const inicializador = inicializadores[indice];
|
|
4369
|
+
const tipoInferido = this.logicaComumInferenciaTiposVariaveisEConstantes(inicializador, tipo) ?? tipo;
|
|
4370
|
+
const informacaoSintatica = tipo === 'dicionário'
|
|
4371
|
+
? this.resolverInformacaoElementoSintaticoDeDicionario(inicializador)
|
|
4372
|
+
: new informacao_elemento_sintatico_1.InformacaoElementoSintatico(identificador.lexema, tipoInferido);
|
|
4373
|
+
this.pilhaEscopos.definirInformacoesVariavel(identificador.lexema, informacaoSintatica);
|
|
4374
|
+
retorno.push(new declaracoes_1.Var(identificador, inicializador, tipoInferido, tipoExplicito, decoradores, tipo));
|
|
4371
4375
|
}
|
|
4372
|
-
retorno.push(new declaracoes_1.Var(identificador, inicializadores[indice], tipo, tipoExplicito, Array.from(this.pilhaDecoradores), tipoOriginal // Passa o tipo original para o construtor
|
|
4373
|
-
));
|
|
4374
4376
|
}
|
|
4375
4377
|
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
4376
4378
|
this.pilhaDecoradores = [];
|
|
@@ -6368,9 +6370,8 @@ class AvaliadorSintaticoPitugues {
|
|
|
6368
6370
|
throw new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(entidadeChamada.simbolo, `Primitiva '${entidadeChamada.simbolo.lexema}' não existe.`);
|
|
6369
6371
|
}
|
|
6370
6372
|
logicaComumInferenciaTiposVariaveisEConstantes(inicializador, tipoPrevio) {
|
|
6371
|
-
if (tipoPrevio !== 'qualquer')
|
|
6373
|
+
if (tipoPrevio !== 'qualquer')
|
|
6372
6374
|
return tipoPrevio;
|
|
6373
|
-
}
|
|
6374
6375
|
switch (inicializador.constructor) {
|
|
6375
6376
|
case construtos_1.AcessoIndiceVariavel:
|
|
6376
6377
|
const entidadeChamadaAcessoIndiceVariavel = inicializador
|
|
@@ -6403,7 +6404,16 @@ class AvaliadorSintaticoPitugues {
|
|
|
6403
6404
|
return entidadeChamadaReferenciaFuncao.tipo;
|
|
6404
6405
|
case construtos_1.Variavel:
|
|
6405
6406
|
const entidadeChamadaVariavel = entidadeChamadaChamada;
|
|
6406
|
-
|
|
6407
|
+
const tipoBruto = entidadeChamadaVariavel.tipo;
|
|
6408
|
+
if (tipoBruto &&
|
|
6409
|
+
tipoBruto.startsWith('função<') &&
|
|
6410
|
+
tipoBruto.endsWith('>')) {
|
|
6411
|
+
return tipoBruto.substring(7, tipoBruto.length - 1);
|
|
6412
|
+
}
|
|
6413
|
+
else if (tipoBruto === 'função') {
|
|
6414
|
+
return 'qualquer';
|
|
6415
|
+
}
|
|
6416
|
+
return tipoBruto;
|
|
6407
6417
|
}
|
|
6408
6418
|
break;
|
|
6409
6419
|
case construtos_1.FuncaoConstruto:
|
|
@@ -6583,15 +6593,13 @@ class AvaliadorSintaticoPitugues {
|
|
|
6583
6593
|
const qtdIdentificadores = identificadores.length;
|
|
6584
6594
|
const qtdValores = inicializadores.length;
|
|
6585
6595
|
const ehDesempacotamento = qtdIdentificadores > 1 && qtdValores === 1;
|
|
6586
|
-
if (indexResto > -1) {
|
|
6587
|
-
if (
|
|
6588
|
-
|
|
6589
|
-
|
|
6590
|
-
throw this.erro(this.simboloAnterior(), 'Quantidade insuficiente de valores para desempacotamento com operador de resto.');
|
|
6591
|
-
}
|
|
6596
|
+
if (indexResto > -1 && qtdValores < qtdIdentificadores - 1) {
|
|
6597
|
+
if (!ehDesempacotamento ||
|
|
6598
|
+
(ehDesempacotamento && inicializadores[0] instanceof construtos_1.Literal)) {
|
|
6599
|
+
throw this.erro(this.simboloAnterior(), 'Quantidade insuficiente de valores para desempacotamento com operador de resto.');
|
|
6592
6600
|
}
|
|
6593
6601
|
}
|
|
6594
|
-
else {
|
|
6602
|
+
else if (indexResto === -1) {
|
|
6595
6603
|
if (!ehDesempacotamento && qtdIdentificadores !== qtdValores) {
|
|
6596
6604
|
throw this.erro(this.simboloAnterior(), 'Quantidade de inicializadores à esquerda do igual é diferente da quantidade de identificadores à direita.');
|
|
6597
6605
|
}
|
|
@@ -6604,41 +6612,52 @@ class AvaliadorSintaticoPitugues {
|
|
|
6604
6612
|
}
|
|
6605
6613
|
const retorno = [];
|
|
6606
6614
|
let origemParaAtribuicao = inicializadores[0];
|
|
6607
|
-
// Injeção de
|
|
6615
|
+
// Injeção de código para variáveis temporárias
|
|
6608
6616
|
if (ehDesempacotamento && !(inicializadores[0] instanceof construtos_1.Vetor)) {
|
|
6609
6617
|
const linha = identificadores[0].linha;
|
|
6610
|
-
// Cria variável temporária para evitar reavaliar a expressão original múltiplas vezes
|
|
6611
6618
|
const nomeVarTemp = `__temp_desempacotamento_${new Date().getTime()}_${Math.floor(Math.random() * 1000)}`;
|
|
6612
6619
|
const simboloVarTemp = new lexador_1.Simbolo(pitugues_2.default.IDENTIFICADOR, nomeVarTemp, null, linha, -1);
|
|
6613
6620
|
retorno.push(new declaracoes_1.Var(simboloVarTemp, inicializadores[0], 'qualquer[]'));
|
|
6614
6621
|
origemParaAtribuicao = new construtos_1.Variavel(this.hashArquivo, simboloVarTemp);
|
|
6615
|
-
// Injeta validação de tamanho se não houver operador de resto
|
|
6616
6622
|
if (indexResto === -1) {
|
|
6617
6623
|
retorno.push(this.construirValidacaoDesempacotamento(identificadores[0], origemParaAtribuicao, qtdIdentificadores));
|
|
6618
6624
|
}
|
|
6619
6625
|
}
|
|
6620
|
-
let cursorValores = 0;
|
|
6621
6626
|
const qtdParaResto = qtdValores - (qtdIdentificadores - 1);
|
|
6622
|
-
|
|
6627
|
+
const elementosAposResto = qtdIdentificadores - 1 - indexResto;
|
|
6628
|
+
let cursorValores = 0;
|
|
6629
|
+
let cursorDesempacotamento = 0;
|
|
6630
|
+
for (let i = 0; i < qtdIdentificadores; i++) {
|
|
6623
6631
|
const identificador = identificadores[i];
|
|
6624
6632
|
let inicializador;
|
|
6625
6633
|
let tipo = 'qualquer';
|
|
6626
6634
|
if (i === indexResto) {
|
|
6627
|
-
|
|
6635
|
+
let valoresResto;
|
|
6636
|
+
if (ehDesempacotamento && inicializadores[0] instanceof construtos_1.Vetor) {
|
|
6637
|
+
const vetorLiteral = inicializadores[0];
|
|
6638
|
+
valoresResto = vetorLiteral.valores.slice(cursorDesempacotamento, vetorLiteral.valores.length - elementosAposResto);
|
|
6639
|
+
cursorDesempacotamento += valoresResto.length;
|
|
6640
|
+
}
|
|
6641
|
+
else {
|
|
6642
|
+
valoresResto = inicializadores.slice(cursorValores, cursorValores + qtdParaResto);
|
|
6643
|
+
cursorValores += qtdParaResto;
|
|
6644
|
+
}
|
|
6628
6645
|
let tipoInferido = (0, inferenciador_1.inferirTipoVariavel)(valoresResto);
|
|
6629
|
-
if (!tipoInferido.endsWith('[]'))
|
|
6646
|
+
if (!tipoInferido.endsWith('[]')) {
|
|
6630
6647
|
tipoInferido = `${tipoInferido}[]`;
|
|
6648
|
+
}
|
|
6631
6649
|
inicializador = new construtos_1.Vetor(identificador.hashArquivo, identificador.linha, valoresResto, tipoInferido);
|
|
6632
6650
|
tipo = tipoInferido;
|
|
6633
|
-
cursorValores += qtdParaResto;
|
|
6634
6651
|
}
|
|
6635
6652
|
else if (ehDesempacotamento) {
|
|
6636
6653
|
if (inicializadores[0] instanceof construtos_1.Vetor) {
|
|
6637
|
-
|
|
6654
|
+
const vetorLiteral = inicializadores[0];
|
|
6655
|
+
inicializador = vetorLiteral.valores[cursorDesempacotamento];
|
|
6638
6656
|
}
|
|
6639
6657
|
else {
|
|
6640
6658
|
inicializador = new construtos_1.AcessoIndiceVariavel(this.hashArquivo, origemParaAtribuicao, new construtos_1.Literal(this.hashArquivo, identificador.linha, i, 'número'), new lexador_1.Simbolo(pitugues_2.default.COLCHETE_DIREITO, ']', null, identificador.linha, -1));
|
|
6641
6659
|
}
|
|
6660
|
+
cursorDesempacotamento++;
|
|
6642
6661
|
}
|
|
6643
6662
|
else {
|
|
6644
6663
|
inicializador = inicializadores[cursorValores];
|