@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.
Files changed (38) hide show
  1. package/analisador-semantico/dialetos/analisador-semantico-pitugues.d.ts +83 -0
  2. package/analisador-semantico/dialetos/analisador-semantico-pitugues.d.ts.map +1 -0
  3. package/analisador-semantico/dialetos/analisador-semantico-pitugues.js +748 -0
  4. package/analisador-semantico/dialetos/analisador-semantico-pitugues.js.map +1 -0
  5. package/analisador-semantico/dialetos/index.d.ts +2 -0
  6. package/analisador-semantico/dialetos/index.d.ts.map +1 -0
  7. package/analisador-semantico/dialetos/index.js +18 -0
  8. package/analisador-semantico/dialetos/index.js.map +1 -0
  9. package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts +3 -0
  10. package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts.map +1 -1
  11. package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js +155 -50
  12. package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js.map +1 -1
  13. package/bin/package.json +1 -1
  14. package/interpretador/depuracao/avaliador-expressao-depuracao.d.ts +66 -0
  15. package/interpretador/depuracao/avaliador-expressao-depuracao.d.ts.map +1 -0
  16. package/interpretador/depuracao/avaliador-expressao-depuracao.js +145 -0
  17. package/interpretador/depuracao/avaliador-expressao-depuracao.js.map +1 -0
  18. package/interpretador/depuracao/comum.d.ts +11 -1
  19. package/interpretador/depuracao/comum.d.ts.map +1 -1
  20. package/interpretador/depuracao/comum.js +219 -3
  21. package/interpretador/depuracao/comum.js.map +1 -1
  22. package/interpretador/depuracao/index.d.ts +1 -0
  23. package/interpretador/depuracao/index.d.ts.map +1 -1
  24. package/interpretador/depuracao/index.js +1 -0
  25. package/interpretador/depuracao/index.js.map +1 -1
  26. package/interpretador/depuracao/interpretador-base-com-depuracao.d.ts +35 -3
  27. package/interpretador/depuracao/interpretador-base-com-depuracao.d.ts.map +1 -1
  28. package/interpretador/depuracao/interpretador-base-com-depuracao.js +50 -3
  29. package/interpretador/depuracao/interpretador-base-com-depuracao.js.map +1 -1
  30. package/interpretador/depuracao/interpretador-com-depuracao.d.ts +12 -3
  31. package/interpretador/depuracao/interpretador-com-depuracao.d.ts.map +1 -1
  32. package/interpretador/depuracao/interpretador-com-depuracao.js +27 -3
  33. package/interpretador/depuracao/interpretador-com-depuracao.js.map +1 -1
  34. package/interpretador/interpretador-base.d.ts.map +1 -1
  35. package/interpretador/interpretador-base.js +2 -0
  36. package/interpretador/interpretador-base.js.map +1 -1
  37. package/package.json +1 -1
  38. 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 contadorIdentificadores = 0;
3450
+ let identificadores = 0;
3450
3451
  while (pos < this.simbolos.length) {
3451
- if (this.simbolos[pos].tipo === pitugues_2.default.IDENTIFICADOR) {
3452
- contadorIdentificadores++;
3452
+ // Consome opcionalmente o operador de resto (*)
3453
+ if (this.simbolos[pos].tipo === pitugues_2.default.MULTIPLICACAO) {
3453
3454
  pos++;
3454
- if (pos >= this.simbolos.length)
3455
- return false;
3456
- // Se encontrou =, verifica se tinha mais de 1 identificador
3457
- if (this.simbolos[pos].tipo === pitugues_2.default.IGUAL) {
3458
- return contadorIdentificadores > 1;
3459
- }
3460
- // Se não é vírgula, não é padrão múltiplo
3461
- if (this.simbolos[pos].tipo !== pitugues_2.default.VIRGULA) {
3462
- return false;
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
- break;
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 _a;
3474
- if (this.simbolos[this.atual].lexema !== 'var') {
3480
+ if (this.simbolos[this.atual].lexema !== "var") {
3475
3481
  return false;
3476
3482
  }
3477
- // Exemplos permitidos: var = 10 | var, a = 10, 20
3478
- if (((_a = this.simbolos[this.atual + 1]) === null || _a === void 0 ? void 0 : _a.tipo) !== pitugues_2.default.IDENTIFICADOR) {
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
- if (this.simbolos[pos].tipo === pitugues_2.default.IGUAL) {
3484
- return true; // Encontrou padrão var identificador = ...
3485
- }
3486
- // Se encontrou algo que não seja IDENTIFICADOR ou VIRGULA, não é o padrão
3487
- if (this.simbolos[pos].tipo !== pitugues_2.default.IDENTIFICADOR &&
3488
- this.simbolos[pos].tipo !== pitugues_2.default.VIRGULA) {
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
- declaracaoDeVariaveis() {
3503
+ consumirIdentificadores() {
3496
3504
  const identificadores = [];
3497
- let retorno = [];
3498
- let tipo = 'qualquer';
3505
+ let indexResto = -1;
3499
3506
  do {
3500
- identificadores.push(this.consumir(pitugues_2.default.IDENTIFICADOR, 'Esperado nome de variável.'));
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
- this.consumir(pitugues_2.default.IGUAL, 'Esperado o símbolo igual(=) após identificador.');
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
- if (identificadores.length !== inicializadores.length) {
3508
- throw this.erro(this.simboloAtual(), 'Quantidade de identificadores à esquerda do igual é diferente da quantidade de valores à direita.');
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
- for (let [indice, identificador] of identificadores.entries()) {
3511
- const inicializador = inicializadores[indice];
3512
- tipo = this.logicaComumInferenciaTiposVariaveisEConstantes(inicializadores[indice], tipo);
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
- var _a;
4350
- // Detecção de declaração implícita
4351
- if (this.simbolos[this.atual].tipo === pitugues_2.default.IDENTIFICADOR) {
4352
- // Detecta e bloqueia "var x = 10"
4353
- if (this.temPadraoVarComoPalavraChave()) {
4354
- throw this.erro(this.simbolos[this.atual], '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".');
4355
- }
4356
- // Verifica se é múltipla atribuição (a, b, c = 1, 2, 3)
4357
- if (this.temPadraoMultiplaAtribuicao()) {
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
- // Verifica se é atribuição simples (a = 1)
4361
- if (((_a = this.simbolos[this.atual + 1]) === null || _a === void 0 ? void 0 : _a.tipo) === pitugues_2.default.IGUAL) {
4362
- const nomeVariavel = this.simbolos[this.atual].lexema;
4363
- if (!this.variavelJaDeclarada(nomeVariavel)) {
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: