@designliquido/delegua 1.23.3 → 1.23.4

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 (27) hide show
  1. package/analisador-semantico/analisador-semantico.d.ts.map +1 -1
  2. package/analisador-semantico/analisador-semantico.js +1 -3
  3. package/analisador-semantico/analisador-semantico.js.map +1 -1
  4. package/avaliador-sintatico/avaliador-sintatico.d.ts.map +1 -1
  5. package/avaliador-sintatico/avaliador-sintatico.js +38 -14
  6. package/avaliador-sintatico/avaliador-sintatico.js.map +1 -1
  7. package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts +1 -1
  8. package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts.map +1 -1
  9. package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js +54 -16
  10. package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js.map +1 -1
  11. package/bin/package.json +1 -1
  12. package/construtos/binario.d.ts.map +1 -1
  13. package/construtos/binario.js +15 -0
  14. package/construtos/binario.js.map +1 -1
  15. package/interpretador/estruturas/delegua-funcao.d.ts +1 -1
  16. package/interpretador/estruturas/delegua-funcao.d.ts.map +1 -1
  17. package/interpretador/estruturas/delegua-funcao.js +21 -8
  18. package/interpretador/estruturas/delegua-funcao.js.map +1 -1
  19. package/interpretador/interpretador-base.d.ts +5 -0
  20. package/interpretador/interpretador-base.d.ts.map +1 -1
  21. package/interpretador/interpretador-base.js +52 -13
  22. package/interpretador/interpretador-base.js.map +1 -1
  23. package/interpretador/interpretador.d.ts.map +1 -1
  24. package/interpretador/interpretador.js +30 -0
  25. package/interpretador/interpretador.js.map +1 -1
  26. package/package.json +1 -1
  27. package/umd/delegua.js +213 -56
package/umd/delegua.js CHANGED
@@ -712,9 +712,7 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
712
712
  }
713
713
  async visitarExpressaoDeChamada(expressao) {
714
714
  for (const argumento of expressao.argumentos) {
715
- if (argumento instanceof construtos_1.Variavel) {
716
- this.gerenciadorEscopos.marcarComoUsada(argumento.simbolo.lexema);
717
- }
715
+ this.marcarVariaveisUsadasEmExpressao(argumento);
718
716
  }
719
717
  switch (expressao.entidadeChamada.constructor) {
720
718
  case construtos_1.AcessoMetodo:
@@ -2775,7 +2773,7 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
2775
2773
  this.avancarEDevolverAnterior();
2776
2774
  valores = [];
2777
2775
  if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.COLCHETE_DIREITO)) {
2778
- return new construtos_1.Vetor(this.hashArquivo, Number(simboloAtual.linha), [], 'qualquer[]');
2776
+ return new construtos_1.Vetor(this.hashArquivo, simboloAtual.linha, [], 'qualquer[]');
2779
2777
  }
2780
2778
  if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.PARENTESE_ESQUERDO)) {
2781
2779
  return this.construtoTupla();
@@ -2810,21 +2808,34 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
2810
2808
  const valoresSemComentarios = valores.filter((v) => v.constructor !== construtos_1.ComentarioComoConstruto);
2811
2809
  let elementoSeparador = false; // O primeiro elemento não pode ser separador.
2812
2810
  for (const elemento of valoresSemComentarios) {
2811
+ const simboloErro = elemento.simbolo || simboloAtual;
2813
2812
  if (elementoSeparador) {
2814
2813
  if (elemento.constructor !== construtos_1.Separador) {
2815
- throw this.erro(elemento.simbolo, 'Não podem haver duas vírgulas seguidas em uma definição de vetor, ou definição de vetor começando em vírgula.');
2814
+ throw this.erro(simboloErro, 'Os itens dos vetores devem ser separados através de uma vírgula.');
2816
2815
  }
2817
2816
  elementoSeparador = false;
2818
2817
  }
2819
2818
  else {
2820
2819
  if (elemento.constructor === construtos_1.Separador) {
2821
- throw this.erro(elemento.simbolo, 'Não podem haver duas vírgulas seguidas em uma definição de vetor, ou definição de vetor começando em vírgula.');
2820
+ throw this.erro(simboloErro, 'Não podem haver duas vírgulas seguidas em uma definição de vetor, ou definição de vetor começando em vírgula.');
2822
2821
  }
2823
2822
  elementoSeparador = true;
2824
2823
  }
2825
2824
  }
2826
2825
  const valoresSemSeparadores = valoresSemComentarios.filter((v) => v.constructor !== construtos_1.Separador);
2827
- const tipoVetor = (0, inferenciador_1.inferirTipoVariavel)(valoresSemSeparadores);
2826
+ let tipoVetor;
2827
+ if (valoresSemSeparadores.length === 0) {
2828
+ tipoVetor = 'qualquer[]';
2829
+ }
2830
+ else {
2831
+ const primeiroElemento = valoresSemSeparadores[0];
2832
+ if (primeiroElemento instanceof construtos_1.Vetor) {
2833
+ tipoVetor = primeiroElemento.tipo + '[]';
2834
+ }
2835
+ else {
2836
+ tipoVetor = (0, inferenciador_1.inferirTipoVariavel)(valoresSemSeparadores);
2837
+ }
2838
+ }
2828
2839
  return new construtos_1.Vetor(this.hashArquivo, Number(simboloAtual.linha), valores, tipoVetor);
2829
2840
  case delegua_2.default.ENQUANTO:
2830
2841
  this.avancarEDevolverAnterior();
@@ -4241,17 +4252,28 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
4241
4252
  }
4242
4253
  switch (inicializador.constructor) {
4243
4254
  case construtos_1.AcessoIndiceVariavel:
4244
- const entidadeChamadaAcessoIndiceVariavel = inicializador
4245
- .entidadeChamada;
4246
- // Este condicional ocorre com chamadas aninhadas. Por exemplo, `vetor[1][2]`.
4247
- if (entidadeChamadaAcessoIndiceVariavel.constructor === construtos_1.AcessoIndiceVariavel) {
4248
- return this.logicaComumInferenciaTiposVariaveisEConstantes(entidadeChamadaAcessoIndiceVariavel, tipo);
4249
- }
4250
- const tipoEntidadeChamadaAcessoIndiceVariavel = entidadeChamadaAcessoIndiceVariavel.tipo;
4251
- if (tipoEntidadeChamadaAcessoIndiceVariavel.endsWith('[]')) {
4252
- return tipoEntidadeChamadaAcessoIndiceVariavel.slice(0, -2);
4255
+ const acessoAtual = inicializador;
4256
+ let entidade = acessoAtual.entidadeChamada;
4257
+ let numeroIndices = 1;
4258
+ // Percorre a cadeia de acessos aninhados para contar quantos índices existem
4259
+ // Cada índice consome um nível de vetor, então removemos um '[]' por acesso.
4260
+ while (entidade.constructor === construtos_1.AcessoIndiceVariavel) {
4261
+ numeroIndices++;
4262
+ entidade = entidade
4263
+ .entidadeChamada;
4264
+ }
4265
+ const tipoBase = entidade.tipo;
4266
+ if (tipoBase.endsWith('[]')) {
4267
+ let tipoResultante = tipoBase;
4268
+ for (let i = 0; i < numeroIndices; i++) {
4269
+ if (tipoResultante.endsWith('[]')) {
4270
+ tipoResultante = tipoResultante.slice(0, -2);
4271
+ }
4272
+ else
4273
+ break;
4274
+ }
4275
+ return tipoResultante;
4253
4276
  }
4254
- // Normalmente, `entidadeChamadaAcessoIndiceVariavel.tipo` aqui será 'vetor'.
4255
4277
  return 'qualquer';
4256
4278
  case construtos_1.Chamada:
4257
4279
  const entidadeChamadaChamada = inicializador.entidadeChamada;
@@ -6374,14 +6396,27 @@ class AvaliadorSintaticoPitugues {
6374
6396
  return tipoPrevio;
6375
6397
  switch (inicializador.constructor) {
6376
6398
  case construtos_1.AcessoIndiceVariavel:
6377
- const entidadeChamadaAcessoIndiceVariavel = inicializador
6378
- .entidadeChamada;
6379
- // Este condicional ocorre com chamadas aninhadas. Por exemplo, `vetor[1][2]`.
6380
- if (entidadeChamadaAcessoIndiceVariavel.constructor === construtos_1.AcessoIndiceVariavel) {
6381
- return this.logicaComumInferenciaTiposVariaveisEConstantes(entidadeChamadaAcessoIndiceVariavel, tipoPrevio);
6382
- }
6383
- if (entidadeChamadaAcessoIndiceVariavel.tipo.endsWith('[]')) {
6384
- return entidadeChamadaAcessoIndiceVariavel.tipo.slice(0, -2);
6399
+ const acessoAtual = inicializador;
6400
+ let entidade = acessoAtual.entidadeChamada;
6401
+ let numeroIndices = 1;
6402
+ // Percorre acessos aninhados como `vetor[1][2]` contando quantos índices foram aplicados.
6403
+ // Cada índice consome um nível de vetor, então removemos um '[]' por acesso.
6404
+ while (entidade.constructor === construtos_1.AcessoIndiceVariavel) {
6405
+ numeroIndices++;
6406
+ entidade = entidade
6407
+ .entidadeChamada;
6408
+ }
6409
+ const tipoBase = entidade.tipo;
6410
+ if (tipoBase.endsWith('[]')) {
6411
+ let tipoResultante = tipoBase;
6412
+ for (let i = 0; i < numeroIndices; i++) {
6413
+ if (tipoResultante.endsWith('[]')) {
6414
+ tipoResultante = tipoResultante.slice(0, -2);
6415
+ }
6416
+ else
6417
+ break;
6418
+ }
6419
+ return tipoResultante;
6385
6420
  }
6386
6421
  // Normalmente, `entidadeChamadaAcessoIndiceVariavel.tipo` aqui será 'vetor'.
6387
6422
  return 'qualquer';
@@ -6807,6 +6842,9 @@ class AvaliadorSintaticoPitugues {
6807
6842
  if (this.verificarSeSimboloAtualEIgualA(pitugues_2.default.COLCHETE_DIREITO)) {
6808
6843
  return new construtos_1.Vetor(this.hashArquivo, simboloAtual.linha, [], 'qualquer[]');
6809
6844
  }
6845
+ if (this.verificarTipoSimboloAtual(pitugues_2.default.VIRGULA)) {
6846
+ throw this.erro(this.simboloAtual(), 'Não podem haver duas vírgulas seguidas em uma definição de vetor, ou definição de vetor começando em vírgula.');
6847
+ }
6810
6848
  // Ao resolver a expressão aqui, identificadores dentro da expressão de compreensão
6811
6849
  // de lista serão tratados como 'qualquer', para evitar erros de tipo.
6812
6850
  this.intuirTipoQualquerParaIdentificadores = true;
@@ -6817,13 +6855,35 @@ class AvaliadorSintaticoPitugues {
6817
6855
  }
6818
6856
  // Aqui já sabemos que não é uma compreensão de lista.
6819
6857
  const valoresVetor = [retornoExpressaoOuPrimeiroValor];
6858
+ this.ignorarComentarios();
6820
6859
  while (!this.verificarSeSimboloAtualEIgualA(pitugues_2.default.COLCHETE_DIREITO)) {
6821
- this.consumir(pitugues_2.default.VIRGULA, 'Esperado vírgula antes da próxima expressão.');
6822
- this.ignorarComentarios();
6823
- valoresVetor.push(await this.atribuir());
6824
- this.ignorarComentarios();
6860
+ if (this.verificarSeSimboloAtualEIgualA(pitugues_2.default.VIRGULA)) {
6861
+ this.ignorarComentarios();
6862
+ if (this.verificarTipoSimboloAtual(pitugues_2.default.VIRGULA)) {
6863
+ throw this.erro(this.simboloAtual(), 'Não podem haver duas vírgulas seguidas em uma definição de vetor, ou definição de vetor começando em vírgula.');
6864
+ }
6865
+ }
6866
+ else {
6867
+ throw this.erro(this.simboloAtual() || simboloAtual, 'Os itens dos vetores devem ser separados através de uma vírgula.');
6868
+ }
6869
+ if (!this.verificarTipoSimboloAtual(pitugues_2.default.COLCHETE_DIREITO)) {
6870
+ valoresVetor.push(await this.atribuir());
6871
+ this.ignorarComentarios();
6872
+ }
6873
+ }
6874
+ let tipoVetor;
6875
+ if (valoresVetor.length === 0) {
6876
+ tipoVetor = 'qualquer[]';
6877
+ }
6878
+ else {
6879
+ const primeiroElemento = valoresVetor[0];
6880
+ if (primeiroElemento instanceof construtos_1.Vetor) {
6881
+ tipoVetor = primeiroElemento.tipo + '[]';
6882
+ }
6883
+ else {
6884
+ tipoVetor = (0, inferenciador_1.inferirTipoVariavel)(valoresVetor);
6885
+ }
6825
6886
  }
6826
- const tipoVetor = (0, inferenciador_1.inferirTipoVariavel)(valoresVetor);
6827
6887
  return new construtos_1.Vetor(this.hashArquivo, simboloAtual.linha, valoresVetor, tipoVetor);
6828
6888
  case pitugues_2.default.COMENTARIO:
6829
6889
  const simboloComentario = this.avancarEDevolverAnterior();
@@ -7780,10 +7840,10 @@ class AvaliadorSintaticoPitugues {
7780
7840
  this.tiposDefinidosEmCodigo[definicaoClasse.simbolo.lexema] = definicaoClasse;
7781
7841
  return definicaoClasse;
7782
7842
  }
7783
- declaracaoFalhar() {
7843
+ async declaracaoFalhar() {
7784
7844
  const simboloFalha = this.simbolos[this.atual - 1];
7785
- const textoFalha = this.consumir(pitugues_2.default.TEXTO, 'Esperado texto para explicar falha.');
7786
- return new declaracoes_1.Falhar(simboloFalha, textoFalha.literal);
7845
+ const explicacao = await this.atribuir();
7846
+ return new declaracoes_1.Falhar(simboloFalha, explicacao);
7787
7847
  }
7788
7848
  /**
7789
7849
  * Verifica se há pontos e vírgula no final de sentenças.
@@ -7893,7 +7953,7 @@ class AvaliadorSintaticoPitugues {
7893
7953
  return this.declaracaoEscreva(simboloEscrevaOuImprima);
7894
7954
  case pitugues_2.default.FALHAR:
7895
7955
  this.avancarEDevolverAnterior();
7896
- return this.declaracaoFalhar();
7956
+ return await this.declaracaoFalhar();
7897
7957
  case pitugues_2.default.FAZER:
7898
7958
  this.avancarEDevolverAnterior();
7899
7959
  return this.declaracaoFazer();
@@ -14341,8 +14401,12 @@ exports.Atribuir = Atribuir;
14341
14401
 
14342
14402
  },{"./variavel":95}],50:[function(require,module,exports){
14343
14403
  "use strict";
14404
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14405
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14406
+ };
14344
14407
  Object.defineProperty(exports, "__esModule", { value: true });
14345
14408
  exports.Binario = void 0;
14409
+ const delegua_1 = __importDefault(require("../tipos-de-simbolos/delegua"));
14346
14410
  /**
14347
14411
  * Binário é uma estrutura com um operador e dois operandos: esquerda e direita.
14348
14412
  * Implementa as seguintes operações para Delégua e todos os dialetos:
@@ -14380,6 +14444,17 @@ class Binario {
14380
14444
  * @returns O tipo deduzido.
14381
14445
  */
14382
14446
  deduzirTipo() {
14447
+ if ([
14448
+ delegua_1.default.MAIOR,
14449
+ delegua_1.default.MAIOR_IGUAL,
14450
+ delegua_1.default.MENOR,
14451
+ delegua_1.default.MENOR_IGUAL,
14452
+ delegua_1.default.IGUAL,
14453
+ delegua_1.default.IGUAL_IGUAL,
14454
+ delegua_1.default.DIFERENTE,
14455
+ ].includes(this.operador.tipo)) {
14456
+ return 'lógico';
14457
+ }
14383
14458
  if (['logico', 'lógico'].includes(this.esquerda.tipo) ||
14384
14459
  ['logico', 'lógico'].includes(this.direita.tipo)) {
14385
14460
  return 'lógico';
@@ -14411,7 +14486,7 @@ class Binario {
14411
14486
  }
14412
14487
  exports.Binario = Binario;
14413
14488
 
14414
- },{}],51:[function(require,module,exports){
14489
+ },{"../tipos-de-simbolos/delegua":253}],51:[function(require,module,exports){
14415
14490
  "use strict";
14416
14491
  Object.defineProperty(exports, "__esModule", { value: true });
14417
14492
  exports.Bote = void 0;
@@ -20509,7 +20584,7 @@ class DeleguaFuncao extends chamavel_1.Chamavel {
20509
20584
  }
20510
20585
  return argumentosResolvidos;
20511
20586
  }
20512
- resolverAmbiente(argumentos) {
20587
+ async resolverAmbiente(visitante, argumentos) {
20513
20588
  const ambiente = new espaco_memoria_1.EspacoMemoria();
20514
20589
  const parametros = this.declaracao.parametros || [];
20515
20590
  for (let i = 0; i < parametros.length; i++) {
@@ -20525,15 +20600,28 @@ class DeleguaFuncao extends chamavel_1.Chamavel {
20525
20600
  };
20526
20601
  }
20527
20602
  else {
20528
- let argumento = argumentos[i];
20529
- if (argumento.valor === null) {
20530
- argumentos[i].valor = parametro.valorPadrao ? parametro.valorPadrao : null;
20603
+ let valorFinal;
20604
+ const argumento = argumentos[i];
20605
+ const valorExtraido = (argumento && argumento.hasOwnProperty('valor'))
20606
+ ? argumento.valor
20607
+ : argumento;
20608
+ if (i < argumentos.length &&
20609
+ valorExtraido !== undefined &&
20610
+ valorExtraido !== null) {
20611
+ valorFinal = valorExtraido;
20612
+ }
20613
+ else if (parametro.valorPadrao) {
20614
+ valorFinal = await visitante.avaliar(parametro.valorPadrao);
20615
+ }
20616
+ else {
20617
+ valorFinal = null;
20531
20618
  }
20532
- ambiente.valores[nome] =
20533
- argumento && argumento.hasOwnProperty('valor') ? argumento.valor : argumento;
20619
+ ambiente.valores[nome] = valorFinal;
20534
20620
  // Se o argumento é `DeleguaFuncao`, para habilitar o recurso de _currying_,
20535
20621
  // copiamos seu valor para o escopo atual. Nem sempre podemos contar com a tipagem explícita aqui.
20536
- if (argumento.valor && ['funcao', 'função'].includes(argumento.valor.tipo)) {
20622
+ if (valorFinal &&
20623
+ typeof valorFinal === 'object' &&
20624
+ ['funcao', 'função'].includes(valorFinal.tipo)) {
20537
20625
  parametro.referencia = true;
20538
20626
  }
20539
20627
  }
@@ -20541,7 +20629,7 @@ class DeleguaFuncao extends chamavel_1.Chamavel {
20541
20629
  return ambiente;
20542
20630
  }
20543
20631
  async chamar(visitante, argumentos) {
20544
- const ambiente = this.resolverAmbiente(argumentos);
20632
+ const ambiente = await this.resolverAmbiente(visitante, argumentos);
20545
20633
  if (this.instancia !== undefined) {
20546
20634
  ambiente.valores['isto'] = {
20547
20635
  valor: this.instancia,
@@ -21924,7 +22012,28 @@ class InterpretadorBase {
21924
22012
  throw new Error('Método não implementado.');
21925
22013
  }
21926
22014
  async visitarExpressaoFalhar(expressao) {
21927
- const textoFalha = expressao.explicacao.valor ?? (await this.avaliar(expressao.explicacao)).valor;
22015
+ let valorAvaliado = expressao.explicacao;
22016
+ // Se for um construto (ex.: Variavel), avalia para obter seu valor real
22017
+ if (expressao.explicacao &&
22018
+ typeof expressao.explicacao.aceitar === 'function') {
22019
+ valorAvaliado = await this.avaliar(expressao.explicacao);
22020
+ }
22021
+ let textoFalha;
22022
+ if (valorAvaliado === null || valorAvaliado === undefined) {
22023
+ textoFalha = 'nulo';
22024
+ }
22025
+ else if (typeof valorAvaliado === 'string') {
22026
+ textoFalha = valorAvaliado;
22027
+ }
22028
+ else if (typeof valorAvaliado === 'object' &&
22029
+ 'valor' in valorAvaliado) {
22030
+ // Objetos tipados como { valor: 'mensagem', tipo: 'texto' }
22031
+ textoFalha = String(valorAvaliado.valor);
22032
+ }
22033
+ else {
22034
+ // Caso incomum: usa a representação textual padrão
22035
+ textoFalha = this.paraTexto(valorAvaliado);
22036
+ }
21928
22037
  throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simbolo, textoFalha, expressao.linha);
21929
22038
  }
21930
22039
  async visitarExpressaoFimPara(_) {
@@ -22929,36 +23038,47 @@ class InterpretadorBase {
22929
23038
  } while (!(retornoExecucao && retornoExecucao.valorRetornado instanceof quebras_1.Quebra) &&
22930
23039
  this.eVerdadeiro(await this.avaliar(declaracao.condicaoEnquanto)));
22931
23040
  }
23041
+ /**
23042
+ * Unifica a execução do bloco 'pegue', tratando tanto o caso de
23043
+ * declarações simples quanto o caso de função com parâmetro de erro.
23044
+ */
23045
+ async executarBlocoPegue(pegue, erro) {
23046
+ if (Array.isArray(pegue)) {
23047
+ return await this.executarBloco(pegue);
23048
+ }
23049
+ // Caso seja FuncaoConstruto (pegue com parâmetro de erro)
23050
+ const literalErro = new construtos_1.Literal(pegue.hashArquivo, pegue.linha, erro.mensagem || erro.message || erro);
23051
+ const chamadaPegue = new construtos_1.Chamada(pegue.hashArquivo, pegue, [literalErro]);
23052
+ return await chamadaPegue.aceitar(this);
23053
+ }
22932
23054
  /**
22933
23055
  * Interpretação de uma declaração `tente`.
22934
23056
  * @param declaracao O objeto da declaração.
22935
23057
  */
22936
23058
  async visitarDeclaracaoTente(declaracao) {
22937
23059
  let valorRetorno;
23060
+ let sucessoNoTente = false;
22938
23061
  try {
22939
23062
  this.emDeclaracaoTente = true;
22940
23063
  try {
22941
23064
  valorRetorno = await this.executarBloco(declaracao.caminhoTente);
23065
+ sucessoNoTente = true;
22942
23066
  }
22943
23067
  catch (erro) {
22944
23068
  if (declaracao.caminhoPegue !== null) {
22945
- // `caminhoPegue` aqui pode ser um construto de função (se `pegue` tem parâmetros)
22946
- // ou um vetor de `Declaracao` (`pegue` sem parâmetros).
22947
- // As execuções, portanto, são diferentes.
22948
- if (Array.isArray(declaracao.caminhoPegue)) {
22949
- valorRetorno = await this.executarBloco(declaracao.caminhoPegue);
22950
- }
22951
- else {
22952
- const literalErro = new construtos_1.Literal(declaracao.hashArquivo, Number(declaracao.linha), erro.mensagem);
22953
- const chamadaPegue = new construtos_1.Chamada(declaracao.caminhoPegue.hashArquivo, declaracao.caminhoPegue, [literalErro]);
22954
- valorRetorno = await chamadaPegue.aceitar(this);
22955
- }
23069
+ valorRetorno = await this.executarBlocoPegue(declaracao.caminhoPegue, erro);
22956
23070
  }
23071
+ else
23072
+ throw erro;
23073
+ }
23074
+ if (sucessoNoTente && declaracao.caminhoSenao) {
23075
+ valorRetorno = await this.executarBloco(declaracao.caminhoSenao);
22957
23076
  }
22958
23077
  }
22959
23078
  finally {
22960
- if (declaracao.caminhoFinalmente)
23079
+ if (declaracao.caminhoFinalmente) {
22961
23080
  valorRetorno = await this.executarBloco(declaracao.caminhoFinalmente);
23081
+ }
22962
23082
  this.emDeclaracaoTente = false;
22963
23083
  }
22964
23084
  return valorRetorno;
@@ -23417,6 +23537,13 @@ class InterpretadorBase {
23417
23537
  if (tipoObjeto === null || tipoObjeto === undefined) {
23418
23538
  tipoObjeto = (0, inferenciador_1.inferirTipoVariavel)(variavelObjeto);
23419
23539
  }
23540
+ // Trata qualquer tipo terminado em '[]' como vetor
23541
+ if (tipoObjeto && tipoObjeto.endsWith('[]')) {
23542
+ if (expressao.simbolo.lexema in primitivas_vetor_1.default) {
23543
+ const metodo = primitivas_vetor_1.default[expressao.simbolo.lexema].implementacao;
23544
+ return new metodo_primitiva_1.MetodoPrimitiva(nomeObjeto, objeto, metodo, expressao.simbolo.lexema, tipoObjeto);
23545
+ }
23546
+ }
23420
23547
  // Caso 3: Vetor simples do JavaScript.
23421
23548
  if (Array.isArray(objeto)) {
23422
23549
  if (expressao.simbolo.lexema in primitivas_vetor_1.default) {
@@ -24684,6 +24811,23 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
24684
24811
  if (tipoObjeto === null || tipoObjeto === undefined) {
24685
24812
  tipoObjeto = (0, inferenciador_1.inferirTipoVariavel)(objeto);
24686
24813
  }
24814
+ // Trata qualquer tipo terminado em '[]' como vetor
24815
+ if (tipoObjeto && tipoObjeto.endsWith('[]')) {
24816
+ if (expressao.nomeMetodo in primitivas_vetor_1.default) {
24817
+ const metodo = primitivas_vetor_1.default[expressao.nomeMetodo].implementacao;
24818
+ return new estruturas_1.MetodoPrimitiva(nomeObjeto, objeto, metodo, expressao.nomeMetodo, tipoObjeto);
24819
+ }
24820
+ else {
24821
+ const funcaoExt = this.encontrarMetodoExtensao(['vetor', 'objeto'], expressao.nomeMetodo, this.hashArquivoDeclaracaoAtual);
24822
+ if (funcaoExt)
24823
+ return funcaoExt.funcaoPorExtensao(objeto);
24824
+ throw new excecoes_1.ErroEmTempoDeExecucao({
24825
+ hashArquivo: this.hashArquivoDeclaracaoAtual,
24826
+ linha: this.linhaDeclaracaoAtual,
24827
+ lexema: expressao.nomeMetodo
24828
+ }, `Método de primitiva '${expressao.nomeMetodo}' não existe para o tipo ${tipoObjeto}.`, expressao.linha);
24829
+ }
24830
+ }
24687
24831
  // Como internamente um dicionário de Delégua é simplesmente um objeto de
24688
24832
  // JavaScript, as primitivas de dicionário, especificamente, são tratadas
24689
24833
  // mais acima.
@@ -24859,6 +25003,19 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
24859
25003
  if (tipoObjeto === null || tipoObjeto === undefined) {
24860
25004
  tipoObjeto = (0, inferenciador_1.inferirTipoVariavel)(objeto);
24861
25005
  }
25006
+ // Trata qualquer tipo terminado em '[]' como vetor
25007
+ if (tipoObjeto && tipoObjeto.endsWith('[]')) {
25008
+ if (expressao.simbolo.lexema in primitivas_vetor_1.default) {
25009
+ const metodo = primitivas_vetor_1.default[expressao.simbolo.lexema].implementacao;
25010
+ return new estruturas_1.MetodoPrimitiva(nomeObjeto, objeto, metodo, expressao.simbolo.lexema, tipoObjeto);
25011
+ }
25012
+ else {
25013
+ const funcaoExt = this.encontrarMetodoExtensao(['vetor', 'objeto'], expressao.simbolo.lexema, this.hashArquivoDeclaracaoAtual);
25014
+ if (funcaoExt)
25015
+ return funcaoExt.funcaoPorExtensao(objeto);
25016
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simbolo, `Método de primitiva '${expressao.simbolo.lexema}' não existe para o tipo ${tipoObjeto}.`, expressao.linha);
25017
+ }
25018
+ }
24862
25019
  // Como internamente um dicionário de Delégua é simplesmente um objeto de
24863
25020
  // JavaScript, as primitivas de dicionário, especificamente, são tratadas
24864
25021
  // mais acima.