@designliquido/delegua 1.0.0 → 1.1.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 (66) hide show
  1. package/avaliador-sintatico/avaliador-sintatico-base.d.ts +5 -0
  2. package/avaliador-sintatico/avaliador-sintatico-base.d.ts.map +1 -1
  3. package/avaliador-sintatico/avaliador-sintatico-base.js +20 -0
  4. package/avaliador-sintatico/avaliador-sintatico-base.js.map +1 -1
  5. package/avaliador-sintatico/avaliador-sintatico.d.ts +11 -1
  6. package/avaliador-sintatico/avaliador-sintatico.d.ts.map +1 -1
  7. package/avaliador-sintatico/avaliador-sintatico.js +38 -6
  8. package/avaliador-sintatico/avaliador-sintatico.js.map +1 -1
  9. package/avaliador-sintatico/comum.d.ts.map +1 -1
  10. package/avaliador-sintatico/comum.js.map +1 -1
  11. package/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.d.ts +1 -1
  12. package/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.d.ts.map +1 -1
  13. package/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.js +2 -2
  14. package/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.js.map +1 -1
  15. package/avaliador-sintatico/traducao/avaliador-sintatico-javascript.d.ts +0 -47
  16. package/avaliador-sintatico/traducao/avaliador-sintatico-javascript.d.ts.map +1 -1
  17. package/avaliador-sintatico/traducao/avaliador-sintatico-javascript.js +0 -135
  18. package/avaliador-sintatico/traducao/avaliador-sintatico-javascript.js.map +1 -1
  19. package/bibliotecas/dialetos/pitugues/primitivas-dicionario.d.ts.map +1 -1
  20. package/bibliotecas/dialetos/pitugues/primitivas-dicionario.js +5 -5
  21. package/bibliotecas/dialetos/pitugues/primitivas-dicionario.js.map +1 -1
  22. package/bibliotecas/dialetos/pitugues/primitivas-numero.d.ts.map +1 -1
  23. package/bibliotecas/dialetos/pitugues/primitivas-numero.js +4 -4
  24. package/bibliotecas/dialetos/pitugues/primitivas-numero.js.map +1 -1
  25. package/bibliotecas/dialetos/pitugues/primitivas-texto.d.ts.map +1 -1
  26. package/bibliotecas/dialetos/pitugues/primitivas-texto.js +18 -18
  27. package/bibliotecas/dialetos/pitugues/primitivas-texto.js.map +1 -1
  28. package/bibliotecas/dialetos/pitugues/primitivas-tupla.d.ts.map +1 -1
  29. package/bibliotecas/dialetos/pitugues/primitivas-tupla.js +2 -2
  30. package/bibliotecas/dialetos/pitugues/primitivas-tupla.js.map +1 -1
  31. package/bibliotecas/dialetos/pitugues/primitivas-vetor.d.ts.map +1 -1
  32. package/bibliotecas/dialetos/pitugues/primitivas-vetor.js +18 -38
  33. package/bibliotecas/dialetos/pitugues/primitivas-vetor.js.map +1 -1
  34. package/bibliotecas/primitivas-dicionario.d.ts.map +1 -1
  35. package/bibliotecas/primitivas-dicionario.js +5 -5
  36. package/bibliotecas/primitivas-dicionario.js.map +1 -1
  37. package/bibliotecas/primitivas-numero.d.ts.map +1 -1
  38. package/bibliotecas/primitivas-numero.js +4 -4
  39. package/bibliotecas/primitivas-numero.js.map +1 -1
  40. package/bibliotecas/primitivas-texto.d.ts +1 -1
  41. package/bibliotecas/primitivas-texto.d.ts.map +1 -1
  42. package/bibliotecas/primitivas-texto.js +21 -21
  43. package/bibliotecas/primitivas-texto.js.map +1 -1
  44. package/bibliotecas/primitivas-tupla.d.ts.map +1 -1
  45. package/bibliotecas/primitivas-tupla.js +2 -2
  46. package/bibliotecas/primitivas-tupla.js.map +1 -1
  47. package/bibliotecas/primitivas-vetor.d.ts.map +1 -1
  48. package/bibliotecas/primitivas-vetor.js +19 -39
  49. package/bibliotecas/primitivas-vetor.js.map +1 -1
  50. package/bin/package.json +1 -1
  51. package/interpretador/estruturas/metodo-primitiva.d.ts +2 -2
  52. package/interpretador/estruturas/metodo-primitiva.js +4 -4
  53. package/interpretador/estruturas/metodo-primitiva.js.map +1 -1
  54. package/interpretador/interpretador-base.d.ts +15 -0
  55. package/interpretador/interpretador-base.d.ts.map +1 -1
  56. package/interpretador/interpretador-base.js +190 -7
  57. package/interpretador/interpretador-base.js.map +1 -1
  58. package/interpretador/interpretador.d.ts +2 -1
  59. package/interpretador/interpretador.d.ts.map +1 -1
  60. package/interpretador/interpretador.js +28 -18
  61. package/interpretador/interpretador.js.map +1 -1
  62. package/lexador/dialetos/lexador-pitugues.d.ts.map +1 -1
  63. package/lexador/dialetos/lexador-pitugues.js +36 -1
  64. package/lexador/dialetos/lexador-pitugues.js.map +1 -1
  65. package/package.json +1 -1
  66. package/umd/delegua.js +369 -109
package/umd/delegua.js CHANGED
@@ -1551,6 +1551,26 @@ class AvaliadorSintaticoBase {
1551
1551
  }
1552
1552
  return expressao;
1553
1553
  }
1554
+ /**
1555
+ * Processa tuplas, que são expressões separadas por vírgula entre parênteses.
1556
+ * Se não houver vírgula, retorna apenas a expressão simples.
1557
+ */
1558
+ async tupla() {
1559
+ let expressao = await this.ou();
1560
+ // Se não há vírgula, retorna a expressão simples
1561
+ if (!this.verificarSeSimboloAtualEIgualA(comum_1.default.VIRGULA)) {
1562
+ return expressao;
1563
+ }
1564
+ // Se há vírgula, então é uma tupla
1565
+ const elementos = [expressao];
1566
+ do {
1567
+ if (this.verificarTipoSimboloAtual(comum_1.default.PARENTESE_DIREITO)) {
1568
+ break;
1569
+ }
1570
+ elementos.push(await this.ou());
1571
+ } while (this.verificarSeSimboloAtualEIgualA(comum_1.default.VIRGULA));
1572
+ return new construtos_1.TuplaN(this.hashArquivo, expressao.linha, elementos);
1573
+ }
1554
1574
  async expressao() {
1555
1575
  return await this.atribuir();
1556
1576
  }
@@ -1909,7 +1929,7 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
1909
1929
  if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.PARENTESE_ESQUERDO)) {
1910
1930
  return this.construtoTupla();
1911
1931
  }
1912
- // Ao resolver a expressão aqui, identificadores dentro da expressão de compreensão
1932
+ // Ao resolver a expressão aqui, identificadores dentro da expressão de compreensão
1913
1933
  // de lista serão tratados como 'qualquer', para evitar erros de tipo.
1914
1934
  this.intuirTipoQualquerParaIdentificadores = true;
1915
1935
  const retornoExpressaoOuPrimeiroValor = await this.seTernario();
@@ -1989,7 +2009,7 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
1989
2009
  const simboloIdentificador = this.avancarEDevolverAnterior();
1990
2010
  let tipoOperando;
1991
2011
  if (this.intuirTipoQualquerParaIdentificadores) {
1992
- // Esta indicação é utilizada para compreensões de lista, onde o
2012
+ // Esta indicação é utilizada para compreensões de lista, onde o
1993
2013
  // tipo do identificador de iteração é 'qualquer' por definição.
1994
2014
  tipoOperando = 'qualquer';
1995
2015
  this.pilhaEscopos.definirInformacoesVariavel(simboloIdentificador.lexema, new informacao_elemento_sintatico_1.InformacaoElementoSintatico(simboloIdentificador.lexema, 'qualquer') // TODO: Talvez um dia inferir o tipo aqui.
@@ -2038,7 +2058,14 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
2038
2058
  return await this.paraComoConstruto(simboloPara);
2039
2059
  case delegua_2.default.PARENTESE_ESQUERDO:
2040
2060
  this.avancarEDevolverAnterior();
2041
- const expressao = await this.expressao();
2061
+ if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.PARENTESE_DIREITO)) {
2062
+ return new construtos_1.TuplaN(this.hashArquivo, Number(simboloAtual.linha), []);
2063
+ }
2064
+ const expressao = await this.tupla();
2065
+ if (expressao instanceof construtos_1.TuplaN) {
2066
+ this.consumir(delegua_2.default.PARENTESE_DIREITO, "Esperado ')' após itens da tupla.");
2067
+ return expressao;
2068
+ }
2042
2069
  this.consumir(delegua_2.default.PARENTESE_DIREITO, "Esperado ')' após a expressão.");
2043
2070
  return new construtos_1.Agrupamento(this.hashArquivo, Number(simboloAtual.linha), expressao);
2044
2071
  case delegua_2.default.SUPER:
@@ -2115,7 +2142,7 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
2115
2142
  }
2116
2143
  return new construtos_1.TipoDe(this.hashArquivo, simboloAtual, construto);
2117
2144
  }
2118
- // TODO: O correto seria emitir algum aviso aqui que este avaliador sintático não consegue
2145
+ // TODO: O correto seria emitir algum aviso aqui que este avaliador sintático não consegue
2119
2146
  // lidar com tópicos de ajuda neste ponto.
2120
2147
  if (this.emAjuda) {
2121
2148
  console.log(this.simbolos[this.atual]);
@@ -2545,6 +2572,31 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
2545
2572
  }
2546
2573
  return expressaoOuCondicao;
2547
2574
  }
2575
+ /**
2576
+ * Método que resolve atribuições.
2577
+ * @returns Um construto do tipo `Atribuir`, `Conjunto` ou `AtribuicaoPorIndice`.
2578
+ */
2579
+ /**
2580
+ * Processa tuplas, que são expressões separadas por vírgula entre parênteses.
2581
+ * Se não houver vírgula, retorna apenas a expressão simples.
2582
+ * Sobrescreve o método da base para usar seTernario() em vez de ou().
2583
+ */
2584
+ async tupla() {
2585
+ let expressao = await this.seTernario();
2586
+ // Se não há vírgula, retorna a expressão simples
2587
+ if (!this.verificarSeSimboloAtualEIgualA(delegua_2.default.VIRGULA)) {
2588
+ return expressao;
2589
+ }
2590
+ // Se há vírgula, então é uma tupla
2591
+ const elementos = [expressao];
2592
+ do {
2593
+ if (this.verificarTipoSimboloAtual(delegua_2.default.PARENTESE_DIREITO)) {
2594
+ break;
2595
+ }
2596
+ elementos.push(await this.seTernario());
2597
+ } while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.VIRGULA));
2598
+ return new construtos_1.TuplaN(this.hashArquivo, expressao.linha, elementos);
2599
+ }
2548
2600
  /**
2549
2601
  * Método que resolve atribuições.
2550
2602
  * @returns Um construto do tipo `Atribuir`, `Conjunto` ou `AtribuicaoPorIndice`.
@@ -2815,7 +2867,7 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
2815
2867
  else {
2816
2868
  importar.elementosImportacao = elementosImportacao;
2817
2869
  }
2818
- return importar;
2870
+ return Promise.resolve(importar);
2819
2871
  }
2820
2872
  async declaracaoPara() {
2821
2873
  try {
@@ -3600,7 +3652,7 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
3600
3652
  return await this.declaracaoFazer(simboloFazer);
3601
3653
  case delegua_2.default.IMPORTAR:
3602
3654
  this.avancarEDevolverAnterior();
3603
- return this.declaracaoImportar();
3655
+ return await this.declaracaoImportar();
3604
3656
  case delegua_2.default.LINHA_COMENTARIO:
3605
3657
  return this.declaracaoComentarioMultilinha();
3606
3658
  case delegua_2.default.PARA:
@@ -4052,7 +4104,7 @@ class AvaliadorSintaticoEguaClassico {
4052
4104
  return new construtos_1.Agrupamento(this.hashArquivo, 0, expressao);
4053
4105
  }
4054
4106
  if (this.verificarSeSimboloAtualEIgualA(egua_classico_1.default.IMPORTAR))
4055
- return this.declaracaoImportar();
4107
+ return this.construtoImportar();
4056
4108
  throw this.erro(this.simboloAtual(), 'Esperado expressão.');
4057
4109
  }
4058
4110
  finalizarChamada(entidadeChamada) {
@@ -4389,7 +4441,7 @@ class AvaliadorSintaticoEguaClassico {
4389
4441
  this.blocos -= 1;
4390
4442
  }
4391
4443
  }
4392
- declaracaoImportar() {
4444
+ construtoImportar() {
4393
4445
  this.consumir(egua_classico_1.default.PARENTESE_ESQUERDO, "Esperado '(' após declaração.");
4394
4446
  const caminho = this.expressao();
4395
4447
  this.consumir(egua_classico_1.default.PARENTESE_DIREITO, "Esperado ')' após declaração.");
@@ -9635,10 +9687,10 @@ exports.default = {
9635
9687
  paraVetor: {
9636
9688
  tipoRetorno: 'vetor',
9637
9689
  argumentos: [],
9638
- implementacao: (interpretador, nomePrimitiva, tupla) => {
9690
+ implementacao: (interpretador, tupla) => {
9639
9691
  const objetoTupla = interpretador.resolverValor(tupla);
9640
9692
  if (!(objetoTupla instanceof construtos_1.TuplaN)) {
9641
- return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(null, `A função "${nomePrimitiva}" só pode ser chamada em tuplas.`, interpretador.linhaDeclaracaoAtual));
9693
+ return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(null, `A função "paraVetor" só pode ser chamada em tuplas.`, interpretador.linhaDeclaracaoAtual));
9642
9694
  }
9643
9695
  const valoresPuros = objetoTupla.elementos.map(elemento => interpretador.resolverValor(elemento));
9644
9696
  return Promise.resolve(valoresPuros);
@@ -9661,7 +9713,7 @@ const contemComum = (nome) => {
9661
9713
  argumentos: [
9662
9714
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('chave', 'qualquer', true, [], 'O elemento como chave do dicionário.'),
9663
9715
  ],
9664
- implementacao: (interpretador, nomePrimitiva, valor, chave) => Promise.resolve(chave in valor),
9716
+ implementacao: (interpretador, valor, chave) => Promise.resolve(chave in valor),
9665
9717
  assinaturaFormato: `dicionário.${nome}(chave: qualquer)`,
9666
9718
  documentacao: `# \`dicionário.${nome}(chave)\`\n\n` +
9667
9719
  'Retorna verdadeiro se o elemento passado como parâmetro existe como chave do dicionário. Devolve falso em caso contrário.\n' +
@@ -9678,7 +9730,7 @@ exports.default = {
9678
9730
  chaves: {
9679
9731
  tipoRetorno: 'texto[]',
9680
9732
  argumentos: [],
9681
- implementacao: (interpretador, nomePrimitiva, valor) => {
9733
+ implementacao: (interpretador, valor) => {
9682
9734
  return Promise.resolve(Object.keys(valor));
9683
9735
  },
9684
9736
  assinaturaFormato: 'dicionário.chaves()',
@@ -9696,7 +9748,7 @@ exports.default = {
9696
9748
  itens: {
9697
9749
  tipoRetorno: 'Dupla[]',
9698
9750
  argumentos: [],
9699
- implementacao: (interpretador, nomePrimitiva, valor) => {
9751
+ implementacao: (interpretador, valor) => {
9700
9752
  const hashArquivo = interpretador.hashArquivoDeclaracaoAtual;
9701
9753
  const linha = interpretador.linhaDeclaracaoAtual;
9702
9754
  const pares = Object.entries(valor).map(([chave, valor]) => {
@@ -9720,13 +9772,13 @@ exports.default = {
9720
9772
  remover: {
9721
9773
  tipoRetorno: 'lógico',
9722
9774
  argumentos: [new informacao_elemento_sintatico_1.InformacaoElementoSintatico('chave', 'texto')],
9723
- implementacao: (interpretador, nomePrimitiva, valor, chave) => Promise.resolve(delete valor[chave]),
9775
+ implementacao: (interpretador, valor, chave) => Promise.resolve(delete valor[chave]),
9724
9776
  assinaturaFormato: `dicionário.remover(chave: qualquer)`,
9725
9777
  },
9726
9778
  valores: {
9727
9779
  tipoRetorno: '<T>[]',
9728
9780
  argumentos: [],
9729
- implementacao: (interpretador, nomePrimitiva, valor) => {
9781
+ implementacao: (interpretador, valor) => {
9730
9782
  return Promise.resolve(Object.values(valor));
9731
9783
  },
9732
9784
  }
@@ -9740,7 +9792,7 @@ exports.default = {
9740
9792
  absoluto: {
9741
9793
  tipoRetorno: 'número',
9742
9794
  argumentos: [],
9743
- implementacao: (interpretador, nomePrimitiva, valor) => {
9795
+ implementacao: (interpretador, valor) => {
9744
9796
  return Promise.resolve(Math.abs(valor));
9745
9797
  },
9746
9798
  assinaturaFormato: 'número.absoluto()',
@@ -9756,7 +9808,7 @@ exports.default = {
9756
9808
  arredondarParaBaixo: {
9757
9809
  tipoRetorno: 'número',
9758
9810
  argumentos: [],
9759
- implementacao: (interpretador, nomePrimitiva, valor) => {
9811
+ implementacao: (interpretador, valor) => {
9760
9812
  return Promise.resolve(Math.floor(valor));
9761
9813
  },
9762
9814
  assinaturaFormato: 'número.arredondarParaBaixo()',
@@ -9772,7 +9824,7 @@ exports.default = {
9772
9824
  arredondarParaCima: {
9773
9825
  tipoRetorno: 'número',
9774
9826
  argumentos: [],
9775
- implementacao: (interpretador, nomePrimitiva, valor) => {
9827
+ implementacao: (interpretador, valor) => {
9776
9828
  return Promise.resolve(Math.ceil(valor));
9777
9829
  },
9778
9830
  assinaturaFormato: 'número.arredondarParaCima()',
@@ -9790,7 +9842,7 @@ exports.default = {
9790
9842
  argumentos: [
9791
9843
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('opcoesFormatacao', 'dicionário', false, [], 'Dicionário com opções de formatação, como número de casas decimais.'),
9792
9844
  ],
9793
- implementacao: (interpretador, nomePrimitiva, valor, opcoes) => {
9845
+ implementacao: (interpretador, valor, opcoes) => {
9794
9846
  let minimoCasasDecimais = 2;
9795
9847
  if (opcoes && opcoes.casasDecimais !== undefined) {
9796
9848
  minimoCasasDecimais = opcoes.casasDecimais;
@@ -9824,15 +9876,15 @@ exports.implementacaoParticao = void 0;
9824
9876
  const informacao_elemento_sintatico_1 = require("../informacao-elemento-sintatico");
9825
9877
  const construtos_1 = require("../construtos");
9826
9878
  const excecoes_1 = require("../excecoes");
9827
- const implementacaoParticao = (interpretador, nomePrimitiva, texto, separador, ...args) => {
9879
+ const implementacaoParticao = (interpretador, texto, separador, ...args) => {
9828
9880
  if (args.length > 0) {
9829
- return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(null, `A função "${nomePrimitiva}" aceita apenas um argumento.`, interpretador.linhaDeclaracaoAtual));
9881
+ return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(null, `A função "partição" aceita apenas um argumento.`, interpretador.linhaDeclaracaoAtual));
9830
9882
  }
9831
9883
  if (typeof texto !== 'string') {
9832
- return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(null, `A função "${nomePrimitiva}" só pode ser chamada em textos.`, interpretador.linhaDeclaracaoAtual));
9884
+ return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(null, `A função "partição" só pode ser chamada em textos.`, interpretador.linhaDeclaracaoAtual));
9833
9885
  }
9834
9886
  if (separador === undefined) {
9835
- return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(null, `A função "${nomePrimitiva}" requer um argumento separador.`, interpretador.linhaDeclaracaoAtual));
9887
+ return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(null, `A função "partição" requer um argumento separador.`, interpretador.linhaDeclaracaoAtual));
9836
9888
  }
9837
9889
  if (typeof separador !== 'string') {
9838
9890
  return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(null, 'O separador deve ser do tipo texto.', interpretador.linhaDeclaracaoAtual));
@@ -9859,7 +9911,7 @@ exports.default = {
9859
9911
  aparar: {
9860
9912
  tipoRetorno: 'texto',
9861
9913
  argumentos: [],
9862
- implementacao: (interpretador, nomePrimitiva, texto) => Promise.resolve(texto.trim()),
9914
+ implementacao: (interpretador, texto) => Promise.resolve(texto.trim()),
9863
9915
  assinaturaFormato: 'texto.aparar()',
9864
9916
  documentacao: '# `texto.aparar()` \n \n' +
9865
9917
  'Remove espaços em branco no início e no fim de um texto.' +
@@ -9872,7 +9924,7 @@ exports.default = {
9872
9924
  apararFim: {
9873
9925
  tipoRetorno: 'texto',
9874
9926
  argumentos: [],
9875
- implementacao: (interpretador, nomePrimitiva, texto) => Promise.resolve(texto.trimEnd()),
9927
+ implementacao: (interpretador, texto) => Promise.resolve(texto.trimEnd()),
9876
9928
  assinaturaFormato: 'texto.apararFim()',
9877
9929
  documentacao: '# `texto.apararFim()` \n \n' +
9878
9930
  'Remove espaços em branco no no fim de um texto.' +
@@ -9885,7 +9937,7 @@ exports.default = {
9885
9937
  apararInicio: {
9886
9938
  tipoRetorno: 'texto',
9887
9939
  argumentos: [],
9888
- implementacao: (interpretador, nomePrimitiva, texto) => Promise.resolve(texto.trimStart()),
9940
+ implementacao: (interpretador, texto) => Promise.resolve(texto.trimStart()),
9889
9941
  assinaturaFormato: 'texto.apararInicio()',
9890
9942
  documentacao: '# `texto.apararInicio()` \n \n' +
9891
9943
  'Remover espaços em branco no início e no fim de um texto.' +
@@ -9900,7 +9952,7 @@ exports.default = {
9900
9952
  argumentos: [
9901
9953
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('outroTexto', 'texto', true, [], 'O texto a ser concatenado.'),
9902
9954
  ],
9903
- implementacao: (interpretador, nomePrimitiva, ...texto) => Promise.resolve(''.concat(...texto)),
9955
+ implementacao: (interpretador, ...textos) => Promise.resolve(''.concat(...textos)),
9904
9956
  assinaturaFormato: 'texto.concatenar(...outroTexto: texto)',
9905
9957
  documentacao: '# `texto.concatenar(outroTexto)` \n \n' +
9906
9958
  'Realiza a junção de palavras/textos.' +
@@ -9917,7 +9969,7 @@ exports.default = {
9917
9969
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('delimitador', 'texto', true, [], 'O delimitador usado para dividir o texto.'),
9918
9970
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('limite', 'número', false, [], '(Opcional) Número limite de elementos a serem retornados.'),
9919
9971
  ],
9920
- implementacao: (interpretador, nomePrimitiva, texto, divisor, limite) => {
9972
+ implementacao: (interpretador, texto, divisor, limite) => {
9921
9973
  if (limite) {
9922
9974
  return Promise.resolve(texto.split(divisor, limite));
9923
9975
  }
@@ -9938,7 +9990,7 @@ exports.default = {
9938
9990
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('subtexto', 'texto', true, [], 'O texto que deve ser buscado.'),
9939
9991
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('indiceInicio', 'número', false, [], '(Opcional) O índice opcional para iniciar a busca.'),
9940
9992
  ],
9941
- implementacao: (interpretador, nomePrimitiva, texto, subtexto, indiceInicio) => {
9993
+ implementacao: (interpretador, texto, subtexto, indiceInicio) => {
9942
9994
  if (indiceInicio !== undefined) {
9943
9995
  return Promise.resolve(texto.indexOf(subtexto, indiceInicio));
9944
9996
  }
@@ -9961,7 +10013,7 @@ exports.default = {
9961
10013
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('inicio', 'número', true, [], 'A posição inicial da fatia.'),
9962
10014
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('fim', 'número', false, [], '(Opcional) A posição final da fatia. Se não fornecido, seleciona até o final do texto.'),
9963
10015
  ],
9964
- implementacao: (interpretador, nomePrimitiva, texto, inicio, fim) => Promise.resolve(texto.slice(inicio, fim)),
10016
+ implementacao: (interpretador, texto, inicio, fim) => Promise.resolve(texto.slice(inicio, fim)),
9965
10017
  assinaturaFormato: 'texto.fatiar(inicio: número, fim?: número)',
9966
10018
  documentacao: '# `texto.fatiar(inicio)` \n \n' +
9967
10019
  'Extrai uma fatia do texto, dadas posições de início e fim.' +
@@ -9979,7 +10031,7 @@ exports.default = {
9979
10031
  argumentos: [
9980
10032
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('elemento', 'texto', true, [], 'O elemento a ser verificado se está contido no texto.'),
9981
10033
  ],
9982
- implementacao: (interpretador, nomePrimitiva, texto, elemento) => Promise.resolve(texto.includes(elemento)),
10034
+ implementacao: (interpretador, texto, elemento) => Promise.resolve(texto.includes(elemento)),
9983
10035
  assinaturaFormato: 'inclui(elemento: texto)',
9984
10036
  documentacao: '# `texto.inclui(elemento)` \n \n' +
9985
10037
  'Devolve verdadeiro se elemento passado por parâmetro está contido no texto, e falso em caso contrário.' +
@@ -9993,7 +10045,7 @@ exports.default = {
9993
10045
  inverter: {
9994
10046
  tipoRetorno: 'texto',
9995
10047
  argumentos: [],
9996
- implementacao: (interpretador, nomePrimitiva, texto) => Promise.resolve(texto.split('').reduce((texto, caracter) => (texto = caracter + texto), '')),
10048
+ implementacao: (interpretador, texto) => Promise.resolve(texto.split('').reduce((texto, caracter) => (texto = caracter + texto), '')),
9997
10049
  assinaturaFormato: 'texto.inverter()',
9998
10050
  documentacao: '# `texto.inverter()` \n \n' +
9999
10051
  'Inverte as letras de um texto.' +
@@ -10006,7 +10058,7 @@ exports.default = {
10006
10058
  maiusculo: {
10007
10059
  tipoRetorno: 'texto',
10008
10060
  argumentos: [],
10009
- implementacao: (interpretador, nomePrimitiva, texto) => Promise.resolve(texto.toUpperCase()),
10061
+ implementacao: (interpretador, texto) => Promise.resolve(texto.toUpperCase()),
10010
10062
  assinaturaFormato: 'texto.maiusculo()',
10011
10063
  documentacao: '# `texto.maiusculo()` \n \n' +
10012
10064
  'Converte todos os caracteres alfabéticos para suas respectivas formas em maiúsculo.' +
@@ -10019,7 +10071,7 @@ exports.default = {
10019
10071
  minusculo: {
10020
10072
  tipoRetorno: 'texto',
10021
10073
  argumentos: [],
10022
- implementacao: (interpretador, nomePrimitiva, texto) => Promise.resolve(texto.toLowerCase()),
10074
+ implementacao: (interpretador, texto) => Promise.resolve(texto.toLowerCase()),
10023
10075
  assinaturaFormato: 'texto.minusculo()',
10024
10076
  documentacao: '# `texto.minusculo()` \n \n' +
10025
10077
  'Converte todos os caracteres alfabéticos para suas respectivas formas em minúsculo.' +
@@ -10059,7 +10111,7 @@ exports.default = {
10059
10111
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('textoASerSubstituido', 'texto', true, [], 'Texto a ser substituído.'),
10060
10112
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('substituto', 'texto', true, [], 'A substituição'),
10061
10113
  ],
10062
- implementacao: (interpretador, nomePrimitiva, texto, elemento, substituto) => Promise.resolve(texto.replace(elemento, substituto)),
10114
+ implementacao: (interpretador, texto, elemento, substituto) => Promise.resolve(texto.replace(elemento, substituto)),
10063
10115
  assinaturaFormato: 'texto.substituir(textoASerSubstituido: texto, substituto: texto)',
10064
10116
  documentacao: '# `texto.substituir(textoASerSubstituido, substituto)` \n \n' +
10065
10117
  'Substitui a primeira ocorrência no texto do primeiro parâmetro pelo segundo parâmetro.' +
@@ -10075,7 +10127,7 @@ exports.default = {
10075
10127
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('inicio', 'inteiro', true, [], 'A posição de início do texto a ser extraído.'),
10076
10128
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('fim', 'inteiro', true, [], 'A posição de fim do texto a ser extraído.'),
10077
10129
  ],
10078
- implementacao: (interpretador, nomePrimitiva, texto, inicio, fim) => Promise.resolve(texto.slice(inicio, fim)),
10130
+ implementacao: (interpretador, texto, inicio, fim) => Promise.resolve(texto.slice(inicio, fim)),
10079
10131
  assinaturaFormato: 'texto.subtexto(inicio: inteiro, fim: inteiro)',
10080
10132
  documentacao: '# `texto.subtexto(inicio, fim)` \n\n' +
10081
10133
  'Extrai uma fatia do texto, dadas posições de início e fim.' +
@@ -10088,7 +10140,7 @@ exports.default = {
10088
10140
  tamanho: {
10089
10141
  tipoRetorno: 'inteiro',
10090
10142
  argumentos: [],
10091
- implementacao: (interpretador, nomePrimitiva, texto) => Promise.resolve(texto.length),
10143
+ implementacao: (interpretador, texto) => Promise.resolve(texto.length),
10092
10144
  assinaturaFormato: 'texto.tamanho()',
10093
10145
  documentacao: '# `texto.tamanho()` \n\n' +
10094
10146
  'Devolve um número inteiro com o número de caracteres do texto.' +
@@ -10103,7 +10155,7 @@ exports.default = {
10103
10155
  argumentos: [
10104
10156
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('sufixo', 'texto', true, [], 'O sufixo a ser verificado no final do texto.'),
10105
10157
  ],
10106
- implementacao: (interpretador, nomePrimitiva, texto, sufixo) => Promise.resolve(texto.endsWith(sufixo)),
10158
+ implementacao: (interpretador, texto, sufixo) => Promise.resolve(texto.endsWith(sufixo)),
10107
10159
  assinaturaFormato: 'texto.terminaCom(sufixo: texto)',
10108
10160
  documentacao: '# `texto.terminaCom(sufixo)` \n \n' +
10109
10161
  'Verifica se um texto termina com o sufixo especificado e retorna um valor lógico (verdadeiro ou falso).' +
@@ -10118,7 +10170,7 @@ exports.default = {
10118
10170
  tudoMaiusculo: {
10119
10171
  tipoRetorno: 'lógico',
10120
10172
  argumentos: [],
10121
- implementacao: (interpretador, nomePrimitiva, texto) => Promise.resolve(texto === texto.toUpperCase()),
10173
+ implementacao: (interpretador, texto) => Promise.resolve(texto === texto.toUpperCase()),
10122
10174
  assinaturaFormato: 'texto.tudoMaiusculo()',
10123
10175
  documentacao: '# `texto.tudoMaiusculo()` \n\n' +
10124
10176
  'Devolve verdadeiro se todos os caracteres alfabéticos do texto estão em maiúsculo, e falso em caso contrário.' +
@@ -10133,7 +10185,7 @@ exports.default = {
10133
10185
  tudoMinusculo: {
10134
10186
  tipoRetorno: 'lógico',
10135
10187
  argumentos: [],
10136
- implementacao: (interpretador, nomePrimitiva, texto) => Promise.resolve(texto === texto.toLowerCase()),
10188
+ implementacao: (interpretador, texto) => Promise.resolve(texto === texto.toLowerCase()),
10137
10189
  assinaturaFormato: 'texto.tudoMinusculo()',
10138
10190
  documentacao: '# `texto.tudoMinusculo()` \n\n' +
10139
10191
  'Devolve verdadeiro se todos os caracteres alfabéticos do texto estão em minúsculo, e falso em caso contrário.' +
@@ -10171,12 +10223,8 @@ exports.default = {
10171
10223
  argumentos: [
10172
10224
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('elemento', 'qualquer', true, [], 'Os elementos a serem adicionados ao vetor.'),
10173
10225
  ],
10174
- implementacao: (interpretador, nomePrimitiva, vetor, elemento) => {
10226
+ implementacao: (interpretador, vetor, elemento) => {
10175
10227
  vetor.push(elemento);
10176
- // TODO: Será que apenas isso é suficiente aqui?
10177
- if (nomePrimitiva !== '') {
10178
- interpretador.pilhaEscoposExecucao.atribuirVariavel({ lexema: nomePrimitiva }, vetor);
10179
- }
10180
10228
  return Promise.resolve(vetor);
10181
10229
  },
10182
10230
  assinaturaFormato: 'vetor.adicionar(...elemento: qualquer)',
@@ -10195,7 +10243,7 @@ exports.default = {
10195
10243
  argumentos: [
10196
10244
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('outroVetor', 'qualquer[]', true, [], 'O outro vetorm ou outros vetores, a serem concatenados a este vetor.'),
10197
10245
  ],
10198
- implementacao: (interpretador, nomePrimitiva, vetor, outroVetor) => {
10246
+ implementacao: (interpretador, vetor, outroVetor) => {
10199
10247
  return Promise.resolve(vetor.concat(outroVetor));
10200
10248
  },
10201
10249
  assinaturaFormato: 'vetor.concatenar(...outroVetor: qualquer[])',
@@ -10210,7 +10258,7 @@ exports.default = {
10210
10258
  empilhar: {
10211
10259
  tipoRetorno: 'qualquer[]',
10212
10260
  argumentos: [new informacao_elemento_sintatico_1.InformacaoElementoSintatico('elemento', 'qualquer', true, [], '')],
10213
- implementacao: (interpretador, nomePrimitiva, vetor, elemento) => {
10261
+ implementacao: (interpretador, vetor, elemento) => {
10214
10262
  vetor.push(elemento);
10215
10263
  return Promise.resolve(vetor);
10216
10264
  },
@@ -10233,25 +10281,19 @@ exports.default = {
10233
10281
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('excluirQuantidade', 'número'),
10234
10282
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('itens', 'qualquer[]'),
10235
10283
  ],
10236
- implementacao: (interpretador, nomePrimitiva, vetor, posicaoInicial, quantidadeExclusao, ...itens) => {
10284
+ implementacao: (interpretador, vetor, posicaoInicial, quantidadeExclusao, ...itens) => {
10237
10285
  let elementos = [];
10238
10286
  if (quantidadeExclusao || quantidadeExclusao === 0) {
10239
10287
  elementos = !itens.length
10240
10288
  ? vetor.splice(posicaoInicial, quantidadeExclusao)
10241
10289
  : vetor.splice(posicaoInicial, quantidadeExclusao, ...itens);
10242
- if (nomePrimitiva !== '') {
10243
- interpretador.pilhaEscoposExecucao.atribuirVariavel({ lexema: nomePrimitiva }, vetor);
10244
- }
10245
10290
  return Promise.resolve(elementos);
10246
10291
  }
10247
10292
  else {
10248
10293
  elementos = !itens.length
10249
10294
  ? vetor.splice(posicaoInicial)
10250
10295
  : vetor.splice(posicaoInicial, ...itens);
10251
- if (nomePrimitiva !== '') {
10252
- interpretador.pilhaEscoposExecucao.atribuirVariavel({ lexema: nomePrimitiva }, elementos);
10253
- }
10254
- return Promise.resolve(vetor);
10296
+ return Promise.resolve(elementos);
10255
10297
  }
10256
10298
  },
10257
10299
  assinaturaFormato: 'vetor.encaixar(posicaoInicial?: número, quantidadeExclusao?: número, itens?: qualquer[])',
@@ -10281,7 +10323,7 @@ exports.default = {
10281
10323
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('inicio', 'número', false, [], 'A posição de início do vetor a ser fatiado. Se não fornecido, retorna o vetor inteiro.'),
10282
10324
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('fim', 'número', false, [], 'A posição de fim do vetor a ser fatiado.'),
10283
10325
  ],
10284
- implementacao: (interpretador, nomePrimitiva, vetor, inicio, fim) => Promise.resolve(vetor.slice(inicio, fim)),
10326
+ implementacao: (interpretador, vetor, inicio, fim) => Promise.resolve(vetor.slice(inicio, fim)),
10285
10327
  assinaturaFormato: 'vetor.fatiar(inicio?: número, fim?: número)',
10286
10328
  documentacao: '# `vetor.fatiar(inicio, fim)` \n \n' +
10287
10329
  'Extrai uma fatia do vetor, dadas posições de início e fim. \n' +
@@ -10300,7 +10342,7 @@ exports.default = {
10300
10342
  argumentos: [
10301
10343
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('funcao', 'função', true, [], 'A função de filtragem.'),
10302
10344
  ],
10303
- implementacao: async (interpretador, nomePrimitiva, vetor, funcao) => {
10345
+ implementacao: async (interpretador, vetor, funcao) => {
10304
10346
  if (funcao === undefined || funcao === null) {
10305
10347
  return Promise.reject("É necessário passar uma função para o método 'filtrarPor'");
10306
10348
  }
@@ -10329,7 +10371,7 @@ exports.default = {
10329
10371
  argumentos: [
10330
10372
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('elemento', 'qualquer', true, [], 'O elemento a ser verificado se está presente no vetor.'),
10331
10373
  ],
10332
- implementacao: (interpretador, nomePrimitiva, vetor, elemento) => Promise.resolve(vetor.includes(elemento)),
10374
+ implementacao: (interpretador, vetor, elemento) => Promise.resolve(vetor.includes(elemento)),
10333
10375
  assinaturaFormato: 'vetor.inclui(elemento: qualquer)',
10334
10376
  documentacao: '# `vetor.inclui(elemento)` \n \n' +
10335
10377
  'Verifica se o elemento existe no vetor. Devolve `verdadeiro` se existe, e `falso` em caso contrário.\n' +
@@ -10343,7 +10385,7 @@ exports.default = {
10343
10385
  inverter: {
10344
10386
  tipoRetorno: 'qualquer[]',
10345
10387
  argumentos: [],
10346
- implementacao: (interpretador, nomePrimitiva, vetor) => Promise.resolve(vetor.reverse()),
10388
+ implementacao: (interpretador, vetor) => Promise.resolve(vetor.reverse()),
10347
10389
  assinaturaFormato: 'vetor.inverter()',
10348
10390
  documentacao: '# `vetor.inverter()` \n \n' +
10349
10391
  'Inverte a ordem dos elementos de um vetor.\n' +
@@ -10358,7 +10400,7 @@ exports.default = {
10358
10400
  argumentos: [
10359
10401
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('separador', 'texto', true, [], 'O separador entre elementos do vetor para o texto.'),
10360
10402
  ],
10361
- implementacao: (interpretador, nomePrimitiva, vetor, separador) => Promise.resolve(vetor.join(separador)),
10403
+ implementacao: (interpretador, vetor, separador) => Promise.resolve(vetor.join(separador)),
10362
10404
  assinaturaFormato: 'vetor.juntar(separador: texto)',
10363
10405
  documentacao: '# `vetor.juntar(separador = ",")` \n \n' +
10364
10406
  'Junta todos os elementos de um vetor em um texto, separando cada elemento pelo separador passado como parâmetro.\n' +
@@ -10373,14 +10415,14 @@ exports.default = {
10373
10415
  argumentos: [
10374
10416
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('funcao', 'função', true, [], 'A função que transforma cada elemento de um vetor em outro elemento a ser retornado em um novo vetor.'),
10375
10417
  ],
10376
- implementacao: async (interpretador, nomePrimitiva, vetor, funcao) => {
10418
+ implementacao: async (interpretador, vetor, funcao) => {
10377
10419
  if (funcao === undefined || funcao === null) {
10378
10420
  return Promise.reject("É necessário passar uma função para o método 'mapear'");
10379
10421
  }
10380
10422
  const retorno = [];
10381
10423
  for (let elemento of vetor) {
10382
10424
  let resultado = await funcao.chamar(interpretador, [elemento]);
10383
- retorno.push(resultado);
10425
+ retorno.push(interpretador.resolverValor(resultado));
10384
10426
  }
10385
10427
  return retorno;
10386
10428
  },
@@ -10400,7 +10442,7 @@ exports.default = {
10400
10442
  argumentos: [
10401
10443
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('funcaoOrdenacao', 'função', false, [], '(Opcional) Função para guiar a ordenação.'),
10402
10444
  ],
10403
- implementacao: async (interpretador, nomePrimitiva, vetor, funcaoOrdenacao) => {
10445
+ implementacao: async (interpretador, vetor, funcaoOrdenacao) => {
10404
10446
  if (funcaoOrdenacao !== undefined && funcaoOrdenacao !== null) {
10405
10447
  for (let i = 0; i < vetor.length - 1; i++) {
10406
10448
  for (let j = 1; j < vetor.length; j++) {
@@ -10416,11 +10458,6 @@ exports.default = {
10416
10458
  }
10417
10459
  }
10418
10460
  }
10419
- if (nomePrimitiva !== '') {
10420
- interpretador.pilhaEscoposExecucao.atribuirVariavel({
10421
- lexema: nomePrimitiva,
10422
- }, vetor);
10423
- }
10424
10461
  return vetor;
10425
10462
  }
10426
10463
  if (!vetor.every((v) => typeof v === 'number')) {
@@ -10429,11 +10466,6 @@ exports.default = {
10429
10466
  else {
10430
10467
  vetor.sort((a, b) => a - b);
10431
10468
  }
10432
- if (nomePrimitiva !== '') {
10433
- interpretador.pilhaEscoposExecucao.atribuirVariavel({
10434
- lexema: nomePrimitiva,
10435
- }, vetor);
10436
- }
10437
10469
  return vetor;
10438
10470
  },
10439
10471
  assinaturaFormato: 'vetor.ordenar()',
@@ -10452,7 +10484,7 @@ exports.default = {
10452
10484
  paraTupla: {
10453
10485
  tipoRetorno: 'tupla',
10454
10486
  argumentos: [],
10455
- implementacao: (interpretador, nomePrimitiva, vetor) => {
10487
+ implementacao: (interpretador, vetor) => {
10456
10488
  if (vetor.length < 2) {
10457
10489
  return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
10458
10490
  hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
@@ -10478,7 +10510,7 @@ exports.default = {
10478
10510
  argumentos: [
10479
10511
  new informacao_elemento_sintatico_1.InformacaoElementoSintatico('elemento', 'qualquer', true, [], 'O elemento a ser removido do vetor.'),
10480
10512
  ],
10481
- implementacao: (interpretador, nomePrimitiva, vetor, elemento) => {
10513
+ implementacao: (interpretador, vetor, elemento) => {
10482
10514
  const index = vetor.indexOf(elemento);
10483
10515
  if (index !== -1)
10484
10516
  vetor.splice(index, 1);
@@ -10497,7 +10529,7 @@ exports.default = {
10497
10529
  removerPrimeiro: {
10498
10530
  tipoRetorno: 'qualquer',
10499
10531
  argumentos: [],
10500
- implementacao: (interpretador, nomePrimitiva, vetor) => {
10532
+ implementacao: (interpretador, vetor) => {
10501
10533
  let elemento = vetor.shift();
10502
10534
  return Promise.resolve(elemento);
10503
10535
  },
@@ -10515,7 +10547,7 @@ exports.default = {
10515
10547
  removerUltimo: {
10516
10548
  tipoRetorno: 'qualquer',
10517
10549
  argumentos: [],
10518
- implementacao: (interpretador, nomePrimitiva, vetor) => {
10550
+ implementacao: (interpretador, vetor) => {
10519
10551
  let elemento = vetor.pop();
10520
10552
  return Promise.resolve(elemento);
10521
10553
  },
@@ -10533,7 +10565,7 @@ exports.default = {
10533
10565
  somar: {
10534
10566
  tipoRetorno: 'qualquer',
10535
10567
  argumentos: [],
10536
- implementacao: (interpretador, nomePrimitiva, vetor) => {
10568
+ implementacao: (interpretador, vetor) => {
10537
10569
  return Promise.resolve(vetor.reduce((acc, item) => acc + (typeof item === 'number' ? item : item.valor), 0));
10538
10570
  },
10539
10571
  assinaturaFormato: 'vetor.somar()',
@@ -10548,7 +10580,7 @@ exports.default = {
10548
10580
  tamanho: {
10549
10581
  tipoRetorno: 'número',
10550
10582
  argumentos: [],
10551
- implementacao: (interpretador, nomePrimitiva, vetor) => Promise.resolve(vetor.length),
10583
+ implementacao: (interpretador, vetor) => Promise.resolve(vetor.length),
10552
10584
  assinaturaFormato: 'vetor.tamanho()',
10553
10585
  documentacao: '# `vetor.tamanho()` \n \n' +
10554
10586
  'Retorna o número de elementos que compõem o vetor.\n' +
@@ -16055,8 +16087,8 @@ const chamavel_1 = require("./chamavel");
16055
16087
  * - `v.inclui(1)` (`v` é um vetor)
16056
16088
  * - `t.minusculo()` (`t` é um texto)
16057
16089
  *
16058
- * A aridade é sempre a quantidade de argumentos do método menos um porque o
16059
- * primeiro parâmetro é sempre a referência para a primitiva.
16090
+ * A aridade é sempre a quantidade de argumentos do método menos dois porque os
16091
+ * dois primeiros parâmetros são sempre o interpretador e a referência para a primitiva.
16060
16092
  */
16061
16093
  class MetodoPrimitiva extends chamavel_1.Chamavel {
16062
16094
  constructor(nome, primitiva, metodo, nomeMetodo, tipo = 'qualquer') {
@@ -16067,10 +16099,10 @@ class MetodoPrimitiva extends chamavel_1.Chamavel {
16067
16099
  this.metodo = metodo;
16068
16100
  this.nomeMetodo = nomeMetodo;
16069
16101
  this.tipo = tipo;
16070
- this.valorAridade = metodo.length - 1;
16102
+ this.valorAridade = metodo.length - 2;
16071
16103
  }
16072
16104
  async chamar(interpretador, argumentos = []) {
16073
- return await this.metodo(interpretador, this.nome, this.primitiva, ...argumentos);
16105
+ return await this.metodo(interpretador, this.primitiva, ...argumentos);
16074
16106
  }
16075
16107
  /**
16076
16108
  * Método utilizado por Delégua para inspecionar este método em depuração.
@@ -16389,6 +16421,39 @@ class InterpretadorBase {
16389
16421
  }
16390
16422
  return objeto;
16391
16423
  }
16424
+ /**
16425
+ * Resolve valores recursivamente, incluindo valores aninhados em arrays e dicionários.
16426
+ * Remove metadados que não devem ser serializados.
16427
+ * @param objeto O objeto a ser resolvido
16428
+ * @returns O valor resolvido sem metadados
16429
+ */
16430
+ resolverValorRecursivo(objeto) {
16431
+ // Null, undefined, ou tipos primitivos
16432
+ if (objeto === null || objeto === undefined || typeof objeto !== 'object') {
16433
+ return objeto;
16434
+ }
16435
+ // Resolve metadados primeiro (valorRetornado ou valor)
16436
+ if (objeto.hasOwnProperty && objeto.hasOwnProperty('valorRetornado')) {
16437
+ return this.resolverValorRecursivo(objeto.valorRetornado);
16438
+ }
16439
+ if (objeto.hasOwnProperty && objeto.hasOwnProperty('valor')) {
16440
+ return this.resolverValorRecursivo(objeto.valor);
16441
+ }
16442
+ // Se é array, resolve recursivamente todos os elementos
16443
+ if (Array.isArray(objeto)) {
16444
+ return objeto.map(elemento => this.resolverValorRecursivo(elemento));
16445
+ }
16446
+ // Se é objeto plano, resolve recursivamente todas as propriedades
16447
+ if (objeto && objeto.constructor && objeto.constructor === Object) {
16448
+ const objetoResolvido = {};
16449
+ for (const chave in objeto) {
16450
+ objetoResolvido[chave] = this.resolverValorRecursivo(objeto[chave]);
16451
+ }
16452
+ return objetoResolvido;
16453
+ }
16454
+ // Outros tipos de objetos (Date, classes customizadas, etc.)
16455
+ return objeto;
16456
+ }
16392
16457
  visitarExpressaoArgumentoReferenciaFuncao(expressao) {
16393
16458
  throw new Error('Método não implementado.');
16394
16459
  }
@@ -16430,11 +16495,17 @@ class InterpretadorBase {
16430
16495
  throw new Error('Método não implementado.');
16431
16496
  }
16432
16497
  async visitarExpressaoTupla(expressao) {
16433
- const chaves = Object.keys(expressao);
16498
+ // Lista de propriedades válidas para tuplas (ignorar propriedades de controle)
16499
+ const propriedadesValidas = [
16500
+ 'primeiro', 'segundo', 'terceiro', 'quarto', 'quinto',
16501
+ 'sexto', 'sétimo', 'setimo', 'oitavo', 'nono', 'décimo', 'decimo'
16502
+ ];
16434
16503
  const valores = [];
16435
- for (let chave of chaves) {
16436
- const valor = await this.avaliar(expressao[chave]);
16437
- valores.push(valor);
16504
+ for (let propriedade of propriedadesValidas) {
16505
+ if (expressao.hasOwnProperty(propriedade) && expressao[propriedade] !== undefined) {
16506
+ const valor = await this.avaliar(expressao[propriedade]);
16507
+ valores.push(valor);
16508
+ }
16438
16509
  }
16439
16510
  return valores;
16440
16511
  }
@@ -16806,6 +16877,12 @@ class InterpretadorBase {
16806
16877
  return Number(valorEsquerdo) * Number(valorDireito);
16807
16878
  case delegua_1.default.MODULO:
16808
16879
  case delegua_1.default.MODULO_IGUAL:
16880
+ // Se o operando esquerdo é uma string, usar formatação de string
16881
+ if (tipoEsquerdo === delegua_2.default.TEXTO || typeof valorEsquerdo === 'string') {
16882
+ return this.formatarStringComOperadorPorcentagem(String(valorEsquerdo), direita, // Passar 'direita' ao invés de 'valorDireito' para preservar arrays de tuplas
16883
+ expressao.operador);
16884
+ }
16885
+ // Caso contrário, operação matemática normal
16809
16886
  this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
16810
16887
  return Number(valorEsquerdo) % Number(valorDireito);
16811
16888
  case delegua_1.default.BIT_AND:
@@ -17669,7 +17746,7 @@ class InterpretadorBase {
17669
17746
  ]);
17670
17747
  if (typeof promises[0] === 'boolean') {
17671
17748
  const chaveLogico = promises[0] === true ? 'verdadeiro' : 'falso';
17672
- dicionario[chaveLogico] = promises[1];
17749
+ dicionario[chaveLogico] = this.resolverValor(promises[1]);
17673
17750
  continue;
17674
17751
  }
17675
17752
  dicionario[promises[0]] = this.resolverValor(promises[1]);
@@ -17680,7 +17757,7 @@ class InterpretadorBase {
17680
17757
  async visitarExpressaoVetor(expressao) {
17681
17758
  const valores = [];
17682
17759
  for (let i = 0; i < expressao.valores.length; i++) {
17683
- valores.push(await this.avaliar(expressao.valores[i]));
17760
+ valores.push(this.resolverValor(await this.avaliar(expressao.valores[i])));
17684
17761
  }
17685
17762
  return valores.filter((v) => v !== null && v !== undefined);
17686
17763
  }
@@ -17721,6 +17798,143 @@ class InterpretadorBase {
17721
17798
  }
17722
17799
  return null;
17723
17800
  }
17801
+ /**
17802
+ * Formata uma string usando o operador % (similar ao Python).
17803
+ * @param formato A string de formato com especificadores (ex: "Olá %s").
17804
+ * @param valores Os valores para substituir (pode ser um único valor ou uma tupla/vetor).
17805
+ * @param operador O símbolo do operador para mensagens de erro.
17806
+ * @returns A string formatada.
17807
+ */
17808
+ formatarStringComOperadorPorcentagem(formato, valores, operador) {
17809
+ let valoresArray;
17810
+ // Verificar se é uma TuplaN (verifica instanceof OU propriedade elementos/tipo para maior compatibilidade)
17811
+ if (valores instanceof construtos_1.TuplaN ||
17812
+ (valores && valores.tipo === 'tupla' && valores.elementos && Array.isArray(valores.elementos))) {
17813
+ valoresArray = valores.elementos.map((elem) => {
17814
+ if (elem instanceof construtos_1.Literal || (elem && typeof elem === 'object' && elem.hasOwnProperty('valor'))) {
17815
+ return this.resolverValor(elem.valor);
17816
+ }
17817
+ return this.resolverValor(elem);
17818
+ });
17819
+ }
17820
+ else if (Array.isArray(valores)) {
17821
+ valoresArray = valores.map(v => this.resolverValor(v));
17822
+ }
17823
+ else {
17824
+ const valorResolvido = this.resolverValor(valores);
17825
+ if (Array.isArray(valorResolvido)) {
17826
+ valoresArray = valorResolvido.map(v => this.resolverValor(v));
17827
+ }
17828
+ else {
17829
+ valoresArray = [valorResolvido];
17830
+ }
17831
+ }
17832
+ let indiceValor = 0;
17833
+ let resultado = '';
17834
+ let i = 0;
17835
+ while (i < formato.length) {
17836
+ if (formato[i] === '%') {
17837
+ if (i + 1 >= formato.length) {
17838
+ throw new excecoes_1.ErroEmTempoDeExecucao(operador, 'Formato inválido: % no final da string', operador.linha);
17839
+ }
17840
+ const proximoChar = formato[i + 1];
17841
+ // %% -> % literal
17842
+ if (proximoChar === '%') {
17843
+ resultado += '%';
17844
+ i += 2;
17845
+ continue;
17846
+ }
17847
+ // Verificar se ainda temos valores para substituir
17848
+ if (indiceValor >= valoresArray.length) {
17849
+ throw new excecoes_1.ErroEmTempoDeExecucao(operador, 'Argumentos insuficientes para a string de formatação', operador.linha);
17850
+ }
17851
+ const valor = valoresArray[indiceValor];
17852
+ indiceValor++;
17853
+ // Processar especificadores de formato
17854
+ if (proximoChar === 's') {
17855
+ // %s - string
17856
+ resultado += this.paraTexto(valor);
17857
+ i += 2;
17858
+ }
17859
+ else if (proximoChar === 'd') {
17860
+ // %d - inteiro
17861
+ const valorNumerico = Number(valor);
17862
+ if (isNaN(valorNumerico)) {
17863
+ throw new excecoes_1.ErroEmTempoDeExecucao(operador, `Esperado número para %d, mas recebeu ${typeof valor}`, operador.linha);
17864
+ }
17865
+ resultado += Math.floor(valorNumerico).toString();
17866
+ i += 2;
17867
+ }
17868
+ else if (proximoChar === 'f') {
17869
+ // %f - flutuante
17870
+ const valorNumerico = Number(valor);
17871
+ if (isNaN(valorNumerico)) {
17872
+ throw new excecoes_1.ErroEmTempoDeExecucao(operador, `Esperado número para %f, mas recebeu ${typeof valor}`, operador.linha);
17873
+ }
17874
+ resultado += valorNumerico.toString();
17875
+ i += 2;
17876
+ }
17877
+ else if (proximoChar === '.') {
17878
+ // %.nf - flutuante com n casas decimais
17879
+ let j = i + 2;
17880
+ let casasDecimais = '';
17881
+ while (j < formato.length && formato[j] >= '0' && formato[j] <= '9') {
17882
+ casasDecimais += formato[j];
17883
+ j++;
17884
+ }
17885
+ if (j >= formato.length || formato[j] !== 'f') {
17886
+ throw new excecoes_1.ErroEmTempoDeExecucao(operador, 'Formato inválido: esperado %.nf (ex: %.2f)', operador.linha);
17887
+ }
17888
+ const precisao = parseInt(casasDecimais, 10);
17889
+ const valorNumerico = Number(valor);
17890
+ if (isNaN(valorNumerico)) {
17891
+ throw new excecoes_1.ErroEmTempoDeExecucao(operador, `Esperado número para %.${precisao}f, mas recebeu ${typeof valor}`, operador.linha);
17892
+ }
17893
+ resultado += valorNumerico.toFixed(precisao);
17894
+ i = j + 1;
17895
+ }
17896
+ else if (proximoChar === 'x') {
17897
+ // %x - hexadecimal (caixa baixa)
17898
+ const valorNumerico = Number(valor);
17899
+ if (isNaN(valorNumerico)) {
17900
+ throw new excecoes_1.ErroEmTempoDeExecucao(operador, `Esperado número para %x, mas recebeu ${typeof valor}`, operador.linha);
17901
+ }
17902
+ resultado += Math.floor(valorNumerico).toString(16);
17903
+ i += 2;
17904
+ }
17905
+ else if (proximoChar === 'X') {
17906
+ // %X - hexadecimal (caixa alta)
17907
+ const valorNumerico = Number(valor);
17908
+ if (isNaN(valorNumerico)) {
17909
+ throw new excecoes_1.ErroEmTempoDeExecucao(operador, `Esperado número para %X, mas recebeu ${typeof valor}`, operador.linha);
17910
+ }
17911
+ resultado += Math.floor(valorNumerico).toString(16).toUpperCase();
17912
+ i += 2;
17913
+ }
17914
+ else if (proximoChar === 'o') {
17915
+ // %o - octal
17916
+ const valorNumerico = Number(valor);
17917
+ if (isNaN(valorNumerico)) {
17918
+ throw new excecoes_1.ErroEmTempoDeExecucao(operador, `Esperado número para %o, mas recebeu ${typeof valor}`, operador.linha);
17919
+ }
17920
+ resultado += Math.floor(valorNumerico).toString(8);
17921
+ i += 2;
17922
+ }
17923
+ else {
17924
+ throw new excecoes_1.ErroEmTempoDeExecucao(operador, `Especificador de formato desconhecido: %${proximoChar}`, operador.linha);
17925
+ }
17926
+ }
17927
+ else {
17928
+ resultado += formato[i];
17929
+ i++;
17930
+ }
17931
+ }
17932
+ // Verificar se há valores não utilizados
17933
+ if (indiceValor < valoresArray.length) {
17934
+ throw new excecoes_1.ErroEmTempoDeExecucao(operador, 'Nem todos os argumentos foram convertidos durante a formatação da string.', operador.linha);
17935
+ }
17936
+ return resultado;
17937
+ }
17724
17938
  paraTexto(objeto) {
17725
17939
  if (objeto === null || objeto === undefined)
17726
17940
  return delegua_2.default.NULO;
@@ -17767,7 +17981,8 @@ class InterpretadorBase {
17767
17981
  if ('tipo' in objeto) {
17768
17982
  switch (objeto.tipo) {
17769
17983
  case 'dicionário':
17770
- return JSON.stringify(objeto.valor);
17984
+ const valorResolvido = this.resolverValorRecursivo(objeto.valor);
17985
+ return JSON.stringify(valorResolvido);
17771
17986
  default:
17772
17987
  return objeto.valor;
17773
17988
  }
@@ -17968,15 +18183,7 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
17968
18183
  return objeto;
17969
18184
  }
17970
18185
  if (Array.isArray(objeto)) {
17971
- // Caso interpretador precise da referência ao vetor original (por exemplo, visita a `AcessoMetodoOuPropriedade`).
17972
- if (referencia) {
17973
- return objeto;
17974
- }
17975
- const vetorResolvido = [];
17976
- for (const elemento of objeto) {
17977
- vetorResolvido.push(this.resolverValor(elemento));
17978
- }
17979
- return vetorResolvido;
18186
+ return objeto;
17980
18187
  }
17981
18188
  if (objeto instanceof estruturas_1.ReferenciaMontao) {
17982
18189
  return this.resolverReferenciaMontao(objeto);
@@ -18035,10 +18242,20 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
18035
18242
  if (Array.isArray(objeto)) {
18036
18243
  let retornoVetor = '[';
18037
18244
  for (let elemento of objeto) {
18245
+ // Resolve referências ao montão antes de processar
18246
+ if (elemento instanceof estruturas_1.ReferenciaMontao) {
18247
+ elemento = this.resolverValor(elemento);
18248
+ }
18038
18249
  if (elemento instanceof construtos_1.Tupla) {
18039
18250
  retornoVetor += elemento.paraTextoSaida() + ', ';
18040
18251
  continue;
18041
18252
  }
18253
+ // Se o elemento é um array (incluindo arrays resolvidos de referências),
18254
+ // chama paraTexto recursivamente para processá-lo corretamente
18255
+ if (Array.isArray(elemento)) {
18256
+ retornoVetor += this.paraTexto(elemento) + ', ';
18257
+ continue;
18258
+ }
18042
18259
  if (typeof elemento === 'object') {
18043
18260
  retornoVetor += `${this.serializarSemEspacos(elemento)}, `;
18044
18261
  continue;
@@ -18139,7 +18356,7 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
18139
18356
  retornoExecucao = null;
18140
18357
  }
18141
18358
  if (acumularRetornos) {
18142
- retornos.push(retornoExecucao);
18359
+ retornos.push(this.resolverValor(retornoExecucao));
18143
18360
  }
18144
18361
  }
18145
18362
  catch (erro) {
@@ -18181,7 +18398,7 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
18181
18398
  retornoExecucao = null;
18182
18399
  }
18183
18400
  if (acumularRetornos) {
18184
- retornos.push(retornoExecucao);
18401
+ retornos.push(this.resolverValor(retornoExecucao));
18185
18402
  }
18186
18403
  }
18187
18404
  catch (erro) {
@@ -18233,7 +18450,7 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
18233
18450
  retornoExecucao = null;
18234
18451
  }
18235
18452
  if (acumularRetornos) {
18236
- retornos.push(retornoExecucao);
18453
+ retornos.push(this.resolverValor(retornoExecucao));
18237
18454
  }
18238
18455
  if (para.incrementar !== null) {
18239
18456
  await this.avaliar(para.incrementar);
@@ -18305,7 +18522,7 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
18305
18522
  retornoExecucao = null;
18306
18523
  }
18307
18524
  if (acumularRetornos) {
18308
- retornos.push(retornoExecucao);
18525
+ retornos.push(this.resolverValor(retornoExecucao));
18309
18526
  }
18310
18527
  paraCada.posicaoAtual++;
18311
18528
  }
@@ -18441,7 +18658,7 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
18441
18658
  }
18442
18659
  let tipoObjeto = variavelObjeto.tipo;
18443
18660
  if (tipoObjeto === null || tipoObjeto === undefined) {
18444
- tipoObjeto = (0, inferenciador_1.inferirTipoVariavel)(variavelObjeto);
18661
+ tipoObjeto = (0, inferenciador_1.inferirTipoVariavel)(objeto);
18445
18662
  }
18446
18663
  // Como internamente um dicionário de Delégua é simplesmente um objeto de
18447
18664
  // JavaScript, as primitivas de dicionário, especificamente, são tratadas
@@ -18529,7 +18746,7 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
18529
18746
  }
18530
18747
  let tipoObjeto = variavelObjeto.tipo;
18531
18748
  if (tipoObjeto === null || tipoObjeto === undefined) {
18532
- tipoObjeto = (0, inferenciador_1.inferirTipoVariavel)(variavelObjeto);
18749
+ tipoObjeto = (0, inferenciador_1.inferirTipoVariavel)(objeto);
18533
18750
  }
18534
18751
  // Como internamente um dicionário de Delégua é simplesmente um objeto de
18535
18752
  // JavaScript, as primitivas de dicionário, especificamente, são tratadas
@@ -18632,7 +18849,7 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
18632
18849
  }
18633
18850
  let tipoObjeto = variavelObjeto.tipo;
18634
18851
  if (tipoObjeto === null || tipoObjeto === undefined) {
18635
- tipoObjeto = (0, inferenciador_1.inferirTipoVariavel)(variavelObjeto);
18852
+ tipoObjeto = (0, inferenciador_1.inferirTipoVariavel)(objeto);
18636
18853
  }
18637
18854
  return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(null, `Propriedade para objeto ou primitiva não encontrado: ${expressao.nomePropriedade}.`, expressao.linha));
18638
18855
  }
@@ -18685,9 +18902,9 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
18685
18902
  objeto.push(null);
18686
18903
  }
18687
18904
  objeto[indice] = valor;
18688
- this.pilhaEscoposExecucao.atribuirVariavel(expressao.objeto.simbolo, objeto);
18905
+ // this.pilhaEscoposExecucao.atribuirVariavel((expressao.objeto as any).simbolo, objeto);
18689
18906
  }
18690
- else if (objeto.constructor === Object ||
18907
+ else if ((objeto && objeto.constructor === Object) ||
18691
18908
  objeto instanceof estruturas_1.ObjetoDeleguaClasse ||
18692
18909
  objeto instanceof estruturas_1.DeleguaFuncao ||
18693
18910
  objeto instanceof estruturas_1.DescritorTipoClasse ||
@@ -18899,6 +19116,14 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
18899
19116
  return (0, inferenciador_1.inferirTipoVariavel)(valorTipoDe);
18900
19117
  }
18901
19118
  }
19119
+ async visitarExpressaoVetor(expressao) {
19120
+ // Delega ao interpretador base para processar o vetor
19121
+ const vetor = await super.visitarExpressaoVetor(expressao);
19122
+ // Adiciona referência no montão (comportamento específico deste interpretador)
19123
+ const enderecoVetorMontao = this.montao.adicionarReferencia(vetor);
19124
+ this.pilhaEscoposExecucao.registrarReferenciaMontao(enderecoVetorMontao);
19125
+ return new estruturas_1.ReferenciaMontao(enderecoVetorMontao);
19126
+ }
18902
19127
  /**
18903
19128
  * Executa o último escopo empilhado no topo na pilha de escopos do interpretador.
18904
19129
  * Esse método pega exceções, mas apenas as devolve.
@@ -20133,7 +20358,42 @@ class LexadorPitugues {
20133
20358
  }
20134
20359
  analisarTexto(delimitador = '"', ehFString = false) {
20135
20360
  const linhaPrimeiroCaracter = this.linha;
20361
+ let valor = '';
20136
20362
  while (this.simboloAtual() !== delimitador && !this.eFinalDoCodigo()) {
20363
+ const caractereAtual = this.simboloAtual();
20364
+ if (caractereAtual === '\\') {
20365
+ this.avancar();
20366
+ const proximoCaractere = this.simboloAtual();
20367
+ switch (proximoCaractere) {
20368
+ case 'r':
20369
+ valor += '\r';
20370
+ break;
20371
+ case 'b':
20372
+ valor += '\b';
20373
+ break;
20374
+ case 'n':
20375
+ valor += '\n';
20376
+ break;
20377
+ case 't':
20378
+ valor += '\t';
20379
+ break;
20380
+ case "'":
20381
+ valor += "'";
20382
+ break;
20383
+ case '"':
20384
+ valor += '"';
20385
+ break;
20386
+ case '\\':
20387
+ valor += '\\';
20388
+ break;
20389
+ default:
20390
+ valor += '\\' + proximoCaractere;
20391
+ break;
20392
+ }
20393
+ }
20394
+ else {
20395
+ valor += caractereAtual;
20396
+ }
20137
20397
  this.avancar();
20138
20398
  }
20139
20399
  if (this.eFinalDoCodigo()) {
@@ -20152,7 +20412,7 @@ class LexadorPitugues {
20152
20412
  return;
20153
20413
  }
20154
20414
  const tipoSimbolo = ehFString ? pitugues_2.default.INTERPOLACAO : pitugues_2.default.TEXTO;
20155
- this.simbolos.push(new simbolo_1.Simbolo(tipoSimbolo, textoCompleto, textoCompleto, linhaPrimeiroCaracter + 1, this.hashArquivo));
20415
+ this.simbolos.push(new simbolo_1.Simbolo(tipoSimbolo, textoCompleto, valor, linhaPrimeiroCaracter + 1, this.hashArquivo));
20156
20416
  }
20157
20417
  analisarNumero() {
20158
20418
  const linhaPrimeiroDigito = this.linha;