@designliquido/delegua 0.64.0 → 0.65.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 (42) hide show
  1. package/analisador-semantico/analisador-semantico-base.d.ts +18 -1
  2. package/analisador-semantico/analisador-semantico-base.d.ts.map +1 -1
  3. package/analisador-semantico/analisador-semantico-base.js +129 -0
  4. package/analisador-semantico/analisador-semantico-base.js.map +1 -1
  5. package/analisador-semantico/analisador-semantico.d.ts +38 -19
  6. package/analisador-semantico/analisador-semantico.d.ts.map +1 -1
  7. package/analisador-semantico/analisador-semantico.js +353 -112
  8. package/analisador-semantico/analisador-semantico.js.map +1 -1
  9. package/analisador-semantico/escopo-variavel.d.ts +11 -0
  10. package/analisador-semantico/escopo-variavel.d.ts.map +1 -0
  11. package/analisador-semantico/escopo-variavel.js +3 -0
  12. package/analisador-semantico/escopo-variavel.js.map +1 -0
  13. package/analisador-semantico/funcao-hipotetica-interface.d.ts +5 -0
  14. package/analisador-semantico/funcao-hipotetica-interface.d.ts.map +1 -0
  15. package/analisador-semantico/funcao-hipotetica-interface.js +3 -0
  16. package/analisador-semantico/funcao-hipotetica-interface.js.map +1 -0
  17. package/analisador-semantico/gerenciador-escopos.d.ts +15 -0
  18. package/analisador-semantico/gerenciador-escopos.d.ts.map +1 -0
  19. package/analisador-semantico/gerenciador-escopos.js +77 -0
  20. package/analisador-semantico/gerenciador-escopos.js.map +1 -0
  21. package/analisador-semantico/index.d.ts +4 -0
  22. package/analisador-semantico/index.d.ts.map +1 -1
  23. package/analisador-semantico/index.js +4 -0
  24. package/analisador-semantico/index.js.map +1 -1
  25. package/analisador-semantico/variavel-hipotetica-interface.d.ts +7 -0
  26. package/analisador-semantico/variavel-hipotetica-interface.d.ts.map +1 -0
  27. package/analisador-semantico/variavel-hipotetica-interface.js +3 -0
  28. package/analisador-semantico/variavel-hipotetica-interface.js.map +1 -0
  29. package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts.map +1 -1
  30. package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js +111 -48
  31. package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js.map +1 -1
  32. package/bin/package.json +1 -1
  33. package/interpretador/depuracao/avaliador-expressao-depuracao.d.ts +66 -0
  34. package/interpretador/depuracao/avaliador-expressao-depuracao.d.ts.map +1 -0
  35. package/interpretador/depuracao/avaliador-expressao-depuracao.js +151 -0
  36. package/interpretador/depuracao/avaliador-expressao-depuracao.js.map +1 -0
  37. package/interpretador/depuracao/index.d.ts +1 -0
  38. package/interpretador/depuracao/index.d.ts.map +1 -1
  39. package/interpretador/depuracao/index.js +1 -0
  40. package/interpretador/depuracao/index.js.map +1 -1
  41. package/package.json +1 -1
  42. package/umd/delegua.js +111 -48
package/umd/delegua.js CHANGED
@@ -3445,71 +3445,131 @@ 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
3503
  declaracaoDeVariaveis() {
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 se o * veio 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 se o * veio como parte do 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
  this.consumir(pitugues_2.default.IGUAL, 'Esperado o símbolo igual(=) após identificador.');
3503
3528
  const inicializadores = [];
3504
3529
  do {
3530
+ if (this.estaNoFinal()) {
3531
+ throw this.erro(this.simboloAtual(), 'Esperado inicializador após vírgula.');
3532
+ }
3505
3533
  inicializadores.push(this.expressao());
3506
3534
  } 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.');
3535
+ const qtdIdentificadores = identificadores.length;
3536
+ const qtdValores = inicializadores.length;
3537
+ if (indexResto > -1) {
3538
+ // Com resto: precisa de valores suficientes para cobrir as variáveis obrigatórias.
3539
+ if (qtdValores < qtdIdentificadores - 1) {
3540
+ throw this.erro(this.simboloAnterior(), 'Quantidade insuficiente de valores para desempacotamento com operador de resto.');
3541
+ }
3509
3542
  }
3510
- for (let [indice, identificador] of identificadores.entries()) {
3511
- const inicializador = inicializadores[indice];
3512
- tipo = this.logicaComumInferenciaTiposVariaveisEConstantes(inicializadores[indice], tipo);
3543
+ else {
3544
+ // Sem resto: a quantidade deve ser exata.
3545
+ if (qtdIdentificadores !== qtdValores) {
3546
+ throw this.erro(this.simboloAnterior(), 'Quantidade de inicializadores à esquerda do igual é diferente da quantidade de identificadores à direita.');
3547
+ }
3548
+ }
3549
+ const retorno = [];
3550
+ let cursorValores = 0;
3551
+ const qtdParaResto = qtdValores - (qtdIdentificadores - 1);
3552
+ for (let i = 0; i < identificadores.length; i++) {
3553
+ const identificador = identificadores[i];
3554
+ let inicializador;
3555
+ let tipo = "qualquer";
3556
+ if (i === indexResto) {
3557
+ // Caso Resto (*): absorve N valores em um Vetor e força tipagem de array.
3558
+ const valoresResto = inicializadores.slice(cursorValores, cursorValores + qtdParaResto);
3559
+ let tipoInferido = (0, inferenciador_1.inferirTipoVariavel)(valoresResto);
3560
+ if (!tipoInferido.endsWith('[]')) {
3561
+ tipoInferido = `${tipoInferido}[]`;
3562
+ }
3563
+ inicializador = new construtos_1.Vetor(identificador.hashArquivo, identificador.linha, valoresResto, valoresResto.length, tipoInferido);
3564
+ tipo = tipoInferido;
3565
+ cursorValores += qtdParaResto;
3566
+ }
3567
+ else {
3568
+ // Caso comum: consome 1 valor
3569
+ inicializador = inicializadores[cursorValores];
3570
+ cursorValores++;
3571
+ tipo = this.logicaComumInferenciaTiposVariaveisEConstantes(inicializador, tipo);
3572
+ }
3513
3573
  this.pilhaEscopos.definirInformacoesVariavel(identificador.lexema, new informacao_elemento_sintatico_1.InformacaoElementoSintatico(identificador.lexema, tipo));
3514
3574
  retorno.push(new declaracoes_1.Var(identificador, inicializador, tipo));
3515
3575
  }
@@ -4346,23 +4406,26 @@ class AvaliadorSintaticoPitugues {
4346
4406
  }
4347
4407
  }
4348
4408
  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()) {
4409
+ // Detecção de declaração implícita ou múltipla atribuição (pode começar com * ou identificador)
4410
+ const simboloAtual = this.simbolos[this.atual];
4411
+ // Bloqueio explícito do uso de "var"
4412
+ if (this.temPadraoVarComoPalavraChave()) {
4413
+ 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".');
4414
+ }
4415
+ // Se caso começar com o operador resto (*), ex: *a, b = ...
4416
+ if (simboloAtual.tipo === pitugues_2.default.MULTIPLICACAO) {
4417
+ return this.declaracaoDeVariaveis();
4418
+ }
4419
+ // Se caso começar com um identificador
4420
+ if (simboloAtual.tipo === pitugues_2.default.IDENTIFICADOR) {
4421
+ if (simboloAtual.lexema.startsWith('*'))
4358
4422
  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)) {
4423
+ if (this.temPadraoMultiplaAtribuicao())
4424
+ return this.declaracaoDeVariaveis();
4425
+ const proximoSimbolo = this.simbolos[this.atual + 1];
4426
+ if (proximoSimbolo && proximoSimbolo.tipo === pitugues_2.default.IGUAL) {
4427
+ if (!this.variavelJaDeclarada(simboloAtual.lexema))
4364
4428
  return this.declaracaoImplicita();
4365
- }
4366
4429
  }
4367
4430
  }
4368
4431
  switch (this.simbolos[this.atual].tipo) {