@designliquido/delegua 0.64.1 → 0.66.0
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/dialetos/analisador-semantico-pitugues.d.ts +83 -0
- package/analisador-semantico/dialetos/analisador-semantico-pitugues.d.ts.map +1 -0
- package/analisador-semantico/dialetos/analisador-semantico-pitugues.js +748 -0
- package/analisador-semantico/dialetos/analisador-semantico-pitugues.js.map +1 -0
- package/analisador-semantico/dialetos/index.d.ts +2 -0
- package/analisador-semantico/dialetos/index.d.ts.map +1 -0
- package/analisador-semantico/dialetos/index.js +18 -0
- package/analisador-semantico/dialetos/index.js.map +1 -0
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts +3 -0
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js +155 -50
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js.map +1 -1
- package/bin/package.json +1 -1
- package/interpretador/depuracao/avaliador-expressao-depuracao.d.ts +66 -0
- package/interpretador/depuracao/avaliador-expressao-depuracao.d.ts.map +1 -0
- package/interpretador/depuracao/avaliador-expressao-depuracao.js +145 -0
- package/interpretador/depuracao/avaliador-expressao-depuracao.js.map +1 -0
- package/interpretador/depuracao/comum.d.ts +11 -1
- package/interpretador/depuracao/comum.d.ts.map +1 -1
- package/interpretador/depuracao/comum.js +219 -3
- package/interpretador/depuracao/comum.js.map +1 -1
- package/interpretador/depuracao/index.d.ts +1 -0
- package/interpretador/depuracao/index.d.ts.map +1 -1
- package/interpretador/depuracao/index.js +1 -0
- package/interpretador/depuracao/index.js.map +1 -1
- package/interpretador/depuracao/interpretador-base-com-depuracao.d.ts +35 -3
- package/interpretador/depuracao/interpretador-base-com-depuracao.d.ts.map +1 -1
- package/interpretador/depuracao/interpretador-base-com-depuracao.js +50 -3
- package/interpretador/depuracao/interpretador-base-com-depuracao.js.map +1 -1
- package/interpretador/depuracao/interpretador-com-depuracao.d.ts +12 -3
- package/interpretador/depuracao/interpretador-com-depuracao.d.ts.map +1 -1
- package/interpretador/depuracao/interpretador-com-depuracao.js +27 -3
- package/interpretador/depuracao/interpretador-com-depuracao.js.map +1 -1
- package/interpretador/interpretador-base.d.ts.map +1 -1
- package/interpretador/interpretador-base.js +2 -0
- package/interpretador/interpretador-base.js.map +1 -1
- package/package.json +1 -1
- package/umd/delegua.js +157 -50
package/umd/delegua.js
CHANGED
|
@@ -3445,71 +3445,173 @@ class AvaliadorSintaticoPitugues {
|
|
|
3445
3445
|
}
|
|
3446
3446
|
temPadraoMultiplaAtribuicao() {
|
|
3447
3447
|
// Verifica padrão: IDENTIFICADOR, VIRGULA, IDENTIFICADOR, ..., IGUAL
|
|
3448
|
+
// Também aceita * antes de identificador
|
|
3448
3449
|
let pos = this.atual;
|
|
3449
|
-
let
|
|
3450
|
+
let identificadores = 0;
|
|
3450
3451
|
while (pos < this.simbolos.length) {
|
|
3451
|
-
|
|
3452
|
-
|
|
3452
|
+
// Consome opcionalmente o operador de resto (*)
|
|
3453
|
+
if (this.simbolos[pos].tipo === pitugues_2.default.MULTIPLICACAO) {
|
|
3453
3454
|
pos++;
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3455
|
+
}
|
|
3456
|
+
// Verifica se há um identificador obrigatório
|
|
3457
|
+
if (pos >= this.simbolos.length || this.simbolos[pos].tipo !== pitugues_2.default.IDENTIFICADOR) {
|
|
3458
|
+
return false;
|
|
3459
|
+
}
|
|
3460
|
+
pos++;
|
|
3461
|
+
identificadores++;
|
|
3462
|
+
// Verifica o próximo símbolo (deve ser ',' ou '=')
|
|
3463
|
+
if (pos >= this.simbolos.length)
|
|
3464
|
+
return false;
|
|
3465
|
+
const proximoTipo = this.simbolos[pos].tipo;
|
|
3466
|
+
if (proximoTipo === pitugues_2.default.IGUAL) {
|
|
3467
|
+
return identificadores >= 2;
|
|
3468
|
+
}
|
|
3469
|
+
if (proximoTipo === pitugues_2.default.VIRGULA) {
|
|
3464
3470
|
pos++;
|
|
3465
3471
|
continue;
|
|
3466
3472
|
}
|
|
3467
|
-
|
|
3473
|
+
// Se chegou aqui, não é vírgula nem igual, então o padrão quebrou
|
|
3474
|
+
return false;
|
|
3468
3475
|
}
|
|
3469
3476
|
return false;
|
|
3470
3477
|
}
|
|
3471
3478
|
temPadraoVarComoPalavraChave() {
|
|
3472
3479
|
// Verifica padrão: var identificador = ...
|
|
3473
|
-
var
|
|
3474
|
-
if (this.simbolos[this.atual].lexema !== 'var') {
|
|
3480
|
+
if (this.simbolos[this.atual].lexema !== "var") {
|
|
3475
3481
|
return false;
|
|
3476
3482
|
}
|
|
3477
|
-
|
|
3478
|
-
if (
|
|
3483
|
+
const proximo = this.simbolos[this.atual + 1];
|
|
3484
|
+
if (!proximo)
|
|
3485
|
+
return false;
|
|
3486
|
+
if (proximo.tipo === pitugues_2.default.MULTIPLICACAO) {
|
|
3479
3487
|
return false;
|
|
3480
3488
|
}
|
|
3489
|
+
// Busca pelo sinal de igualdade, permitido apenas IDENTIFICADORES e VÍRGULAS no caminho
|
|
3481
3490
|
let pos = this.atual + 1;
|
|
3482
3491
|
while (pos < this.simbolos.length) {
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3492
|
+
const tipo = this.simbolos[pos].tipo;
|
|
3493
|
+
// Encontrou padrão var a, b = ...
|
|
3494
|
+
if (tipo === pitugues_2.default.IGUAL)
|
|
3495
|
+
return true;
|
|
3496
|
+
// Encontrou algo como 'var a + b'
|
|
3497
|
+
if (tipo !== pitugues_2.default.IDENTIFICADOR && tipo !== pitugues_2.default.VIRGULA)
|
|
3489
3498
|
return false;
|
|
3490
|
-
}
|
|
3491
3499
|
pos++;
|
|
3492
3500
|
}
|
|
3493
3501
|
return false;
|
|
3494
3502
|
}
|
|
3495
|
-
|
|
3503
|
+
consumirIdentificadores() {
|
|
3496
3504
|
const identificadores = [];
|
|
3497
|
-
let
|
|
3498
|
-
let tipo = 'qualquer';
|
|
3505
|
+
let indexResto = -1;
|
|
3499
3506
|
do {
|
|
3500
|
-
|
|
3507
|
+
let ehRestoAtual = false;
|
|
3508
|
+
// Verifica * como token separado
|
|
3509
|
+
if (this.verificarTipoSimboloAtual(pitugues_2.default.MULTIPLICACAO)) {
|
|
3510
|
+
this.consumir(pitugues_2.default.MULTIPLICACAO, '');
|
|
3511
|
+
ehRestoAtual = true;
|
|
3512
|
+
}
|
|
3513
|
+
const identificador = this.consumir(pitugues_2.default.IDENTIFICADOR, ehRestoAtual ? 'Esperado nome de variável após operador *.' : 'Esperado nome de variável.');
|
|
3514
|
+
// Verifica * no nome da variável
|
|
3515
|
+
if (identificador.lexema.startsWith('*')) {
|
|
3516
|
+
ehRestoAtual = true;
|
|
3517
|
+
identificador.lexema = identificador.lexema.slice(1);
|
|
3518
|
+
}
|
|
3519
|
+
if (ehRestoAtual) {
|
|
3520
|
+
if (indexResto > -1) {
|
|
3521
|
+
throw this.erro(this.simboloAtual(), 'Sintaxe inválida: apenas um operador de resto é permitido.');
|
|
3522
|
+
}
|
|
3523
|
+
indexResto = identificadores.length;
|
|
3524
|
+
}
|
|
3525
|
+
identificadores.push(identificador);
|
|
3501
3526
|
} while (this.verificarSeSimboloAtualEIgualA(pitugues_2.default.VIRGULA));
|
|
3502
|
-
|
|
3527
|
+
return { simbolos: identificadores, indexResto };
|
|
3528
|
+
}
|
|
3529
|
+
consumirInicializadores() {
|
|
3503
3530
|
const inicializadores = [];
|
|
3504
3531
|
do {
|
|
3532
|
+
if (this.estaNoFinal()) {
|
|
3533
|
+
throw this.erro(this.simboloAtual(), 'Esperado inicializador após vírgula.');
|
|
3534
|
+
}
|
|
3505
3535
|
inicializadores.push(this.expressao());
|
|
3506
3536
|
} while (this.verificarSeSimboloAtualEIgualA(pitugues_2.default.VIRGULA));
|
|
3507
|
-
|
|
3508
|
-
|
|
3537
|
+
return inicializadores;
|
|
3538
|
+
}
|
|
3539
|
+
construirValidacaoDesempacotamento(identificador, origem, qtdEsperada) {
|
|
3540
|
+
const linha = identificador.linha;
|
|
3541
|
+
const chamadaTamanho = new construtos_1.Chamada(this.hashArquivo, new construtos_1.Variavel(this.hashArquivo, new lexador_1.Simbolo(pitugues_2.default.IDENTIFICADOR, "tamanho", null, linha, -1)), [origem]);
|
|
3542
|
+
const condicaoErro = new construtos_1.Binario(this.hashArquivo, chamadaTamanho, new lexador_1.Simbolo(pitugues_2.default.DIFERENTE, "!=", null, linha, -1), new construtos_1.Literal(this.hashArquivo, linha, qtdEsperada, 'número'));
|
|
3543
|
+
const mensagem = `Erro de execução: Você tentou desempacotar em ${qtdEsperada} variáveis, mas o vetor possui tamanho diferente.`;
|
|
3544
|
+
const falha = new declaracoes_1.Falhar(new lexador_1.Simbolo(pitugues_2.default.FALHAR, "falhar", null, linha, -1), new construtos_1.Literal(this.hashArquivo, linha, mensagem, 'texto'));
|
|
3545
|
+
return new declaracoes_1.Se(condicaoErro, new declaracoes_1.Bloco(this.hashArquivo, linha, [falha]), [], null);
|
|
3546
|
+
}
|
|
3547
|
+
declaracaoDeVariaveis() {
|
|
3548
|
+
const { simbolos: identificadores, indexResto } = this.consumirIdentificadores();
|
|
3549
|
+
this.consumir(pitugues_2.default.IGUAL, 'Esperado o símbolo igual(=) após identificador.');
|
|
3550
|
+
const inicializadores = this.consumirInicializadores();
|
|
3551
|
+
const qtdIdentificadores = identificadores.length;
|
|
3552
|
+
const qtdValores = inicializadores.length;
|
|
3553
|
+
const ehDesempacotamento = qtdIdentificadores > 1 && qtdValores === 1;
|
|
3554
|
+
if (indexResto > -1) {
|
|
3555
|
+
if (qtdValores < qtdIdentificadores - 1) {
|
|
3556
|
+
if (!ehDesempacotamento || (ehDesempacotamento && inicializadores[0] instanceof construtos_1.Literal)) {
|
|
3557
|
+
throw this.erro(this.simboloAnterior(), 'Quantidade insuficiente de valores para desempacotamento com operador de resto.');
|
|
3558
|
+
}
|
|
3559
|
+
}
|
|
3509
3560
|
}
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3561
|
+
else {
|
|
3562
|
+
if (!ehDesempacotamento && qtdIdentificadores !== qtdValores) {
|
|
3563
|
+
throw this.erro(this.simboloAnterior(), 'Quantidade de inicializadores à esquerda do igual é diferente da quantidade de identificadores à direita.');
|
|
3564
|
+
}
|
|
3565
|
+
if (ehDesempacotamento && inicializadores[0] instanceof construtos_1.Vetor) {
|
|
3566
|
+
const vetor = inicializadores[0];
|
|
3567
|
+
if (vetor.tamanho !== qtdIdentificadores) {
|
|
3568
|
+
throw this.erro(this.simboloAnterior(), `O vetor possui ${vetor.tamanho} elementos, mas você tentou desempacotar em ${qtdIdentificadores} variáveis.`);
|
|
3569
|
+
}
|
|
3570
|
+
}
|
|
3571
|
+
}
|
|
3572
|
+
const retorno = [];
|
|
3573
|
+
let origemParaAtribuicao = inicializadores[0];
|
|
3574
|
+
// Injeção de Código (Runtime Check)
|
|
3575
|
+
if (ehDesempacotamento && !(inicializadores[0] instanceof construtos_1.Vetor)) {
|
|
3576
|
+
const linha = identificadores[0].linha;
|
|
3577
|
+
// Cria variável temporária para evitar reavaliar a expressão original múltiplas vezes
|
|
3578
|
+
const nomeVarTemp = `__temp_desempacotamento_${new Date().getTime()}_${Math.floor(Math.random() * 1000)}`;
|
|
3579
|
+
const simboloVarTemp = new lexador_1.Simbolo(pitugues_2.default.IDENTIFICADOR, nomeVarTemp, null, linha, -1);
|
|
3580
|
+
retorno.push(new declaracoes_1.Var(simboloVarTemp, inicializadores[0], 'qualquer[]'));
|
|
3581
|
+
origemParaAtribuicao = new construtos_1.Variavel(this.hashArquivo, simboloVarTemp);
|
|
3582
|
+
// Injeta validação de tamanho se não houver operador de resto
|
|
3583
|
+
if (indexResto === -1) {
|
|
3584
|
+
retorno.push(this.construirValidacaoDesempacotamento(identificadores[0], origemParaAtribuicao, qtdIdentificadores));
|
|
3585
|
+
}
|
|
3586
|
+
}
|
|
3587
|
+
let cursorValores = 0;
|
|
3588
|
+
const qtdParaResto = qtdValores - (qtdIdentificadores - 1);
|
|
3589
|
+
for (let i = 0; i < identificadores.length; i++) {
|
|
3590
|
+
const identificador = identificadores[i];
|
|
3591
|
+
let inicializador;
|
|
3592
|
+
let tipo = "qualquer";
|
|
3593
|
+
if (i === indexResto) {
|
|
3594
|
+
const valoresResto = inicializadores.slice(cursorValores, cursorValores + qtdParaResto);
|
|
3595
|
+
let tipoInferido = (0, inferenciador_1.inferirTipoVariavel)(valoresResto);
|
|
3596
|
+
if (!tipoInferido.endsWith('[]'))
|
|
3597
|
+
tipoInferido = `${tipoInferido}[]`;
|
|
3598
|
+
inicializador = new construtos_1.Vetor(identificador.hashArquivo, identificador.linha, valoresResto, valoresResto.length, tipoInferido);
|
|
3599
|
+
tipo = tipoInferido;
|
|
3600
|
+
cursorValores += qtdParaResto;
|
|
3601
|
+
}
|
|
3602
|
+
else if (ehDesempacotamento) {
|
|
3603
|
+
if (inicializadores[0] instanceof construtos_1.Vetor) {
|
|
3604
|
+
inicializador = inicializadores[0].valores[i];
|
|
3605
|
+
}
|
|
3606
|
+
else {
|
|
3607
|
+
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));
|
|
3608
|
+
}
|
|
3609
|
+
}
|
|
3610
|
+
else {
|
|
3611
|
+
inicializador = inicializadores[cursorValores];
|
|
3612
|
+
cursorValores++;
|
|
3613
|
+
tipo = this.logicaComumInferenciaTiposVariaveisEConstantes(inicializador, tipo);
|
|
3614
|
+
}
|
|
3513
3615
|
this.pilhaEscopos.definirInformacoesVariavel(identificador.lexema, new informacao_elemento_sintatico_1.InformacaoElementoSintatico(identificador.lexema, tipo));
|
|
3514
3616
|
retorno.push(new declaracoes_1.Var(identificador, inicializador, tipo));
|
|
3515
3617
|
}
|
|
@@ -4346,23 +4448,26 @@ class AvaliadorSintaticoPitugues {
|
|
|
4346
4448
|
}
|
|
4347
4449
|
}
|
|
4348
4450
|
resolverDeclaracao() {
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4451
|
+
// Detecção de declaração implícita ou múltipla atribuição (pode começar com * ou identificador)
|
|
4452
|
+
const simboloAtual = this.simbolos[this.atual];
|
|
4453
|
+
// Bloqueio explícito do uso de "var"
|
|
4454
|
+
if (this.temPadraoVarComoPalavraChave()) {
|
|
4455
|
+
throw this.erro(simboloAtual, 'Palavra "var" não pode ser usada como palavra-chave para declaração. Use declarações implícitas: "x = 10" em vez de "var x = 10".');
|
|
4456
|
+
}
|
|
4457
|
+
// Se caso começar com o operador resto (*), ex: *a, b = ...
|
|
4458
|
+
if (simboloAtual.tipo === pitugues_2.default.MULTIPLICACAO) {
|
|
4459
|
+
return this.declaracaoDeVariaveis();
|
|
4460
|
+
}
|
|
4461
|
+
// Se caso começar com um identificador
|
|
4462
|
+
if (simboloAtual.tipo === pitugues_2.default.IDENTIFICADOR) {
|
|
4463
|
+
if (simboloAtual.lexema.startsWith('*'))
|
|
4358
4464
|
return this.declaracaoDeVariaveis();
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
if (!this.variavelJaDeclarada(
|
|
4465
|
+
if (this.temPadraoMultiplaAtribuicao())
|
|
4466
|
+
return this.declaracaoDeVariaveis();
|
|
4467
|
+
const proximoSimbolo = this.simbolos[this.atual + 1];
|
|
4468
|
+
if (proximoSimbolo && proximoSimbolo.tipo === pitugues_2.default.IGUAL) {
|
|
4469
|
+
if (!this.variavelJaDeclarada(simboloAtual.lexema))
|
|
4364
4470
|
return this.declaracaoImplicita();
|
|
4365
|
-
}
|
|
4366
4471
|
}
|
|
4367
4472
|
}
|
|
4368
4473
|
switch (this.simbolos[this.atual].tipo) {
|
|
@@ -13430,6 +13535,8 @@ class InterpretadorBase {
|
|
|
13430
13535
|
return (objetoAcessado as AcessoMetodoOuPropriedade).simbolo.lexema;
|
|
13431
13536
|
case AcessoIndiceVariavel:
|
|
13432
13537
|
return this.resolverNomeObjectoAcessado((objetoAcessado as AcessoIndiceVariavel).entidadeChamada); */
|
|
13538
|
+
case construtos_1.Chamada:
|
|
13539
|
+
return this.resolverNomeObjectoAcessado(objetoAcessado.entidadeChamada);
|
|
13433
13540
|
case construtos_1.Constante:
|
|
13434
13541
|
return objetoAcessado.simbolo.lexema;
|
|
13435
13542
|
case construtos_1.AcessoMetodoOuPropriedade:
|