@designliquido/delegua 0.57.2 → 0.59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/avaliador-sintatico/avaliador-sintatico.d.ts +7 -1
- package/avaliador-sintatico/avaliador-sintatico.d.ts.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.js +74 -14
- package/avaliador-sintatico/avaliador-sintatico.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts +3 -3
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js +26 -10
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js.map +1 -1
- package/avaliador-sintatico/dialetos/micro-avaliador-sintatico-pitugues.d.ts +23 -0
- package/avaliador-sintatico/dialetos/micro-avaliador-sintatico-pitugues.d.ts.map +1 -0
- package/avaliador-sintatico/dialetos/micro-avaliador-sintatico-pitugues.js +199 -0
- package/avaliador-sintatico/dialetos/micro-avaliador-sintatico-pitugues.js.map +1 -0
- package/avaliador-sintatico/elemento-montao-tipos.d.ts.map +1 -1
- package/avaliador-sintatico/elemento-montao-tipos.js.map +1 -1
- package/avaliador-sintatico/micro-avaliador-sintatico.d.ts.map +1 -1
- package/avaliador-sintatico/micro-avaliador-sintatico.js.map +1 -1
- package/avaliador-sintatico/montao-tipos.d.ts +1 -1
- package/avaliador-sintatico/montao-tipos.d.ts.map +1 -1
- package/avaliador-sintatico/montao-tipos.js.map +1 -1
- package/avaliador-sintatico/pilha-escopos.d.ts.map +1 -1
- package/avaliador-sintatico/pilha-escopos.js.map +1 -1
- package/bibliotecas/biblioteca-global.d.ts +7 -0
- package/bibliotecas/biblioteca-global.d.ts.map +1 -1
- package/bibliotecas/biblioteca-global.js +206 -0
- package/bibliotecas/biblioteca-global.js.map +1 -1
- package/bibliotecas/dialetos/egua-classico/biblioteca-global.d.ts.map +1 -1
- package/bibliotecas/dialetos/egua-classico/biblioteca-global.js +8 -2
- package/bibliotecas/dialetos/egua-classico/biblioteca-global.js.map +1 -1
- package/bibliotecas/dialetos/pitugues/biblioteca-global.d.ts +169 -0
- package/bibliotecas/dialetos/pitugues/biblioteca-global.d.ts.map +1 -0
- package/bibliotecas/dialetos/pitugues/biblioteca-global.js +686 -0
- package/bibliotecas/dialetos/pitugues/biblioteca-global.js.map +1 -0
- package/bibliotecas/dialetos/pitugues/primitivas-dicionario.d.ts +6 -0
- package/bibliotecas/dialetos/pitugues/primitivas-dicionario.d.ts.map +1 -0
- package/bibliotecas/dialetos/pitugues/primitivas-dicionario.js +56 -0
- package/bibliotecas/dialetos/pitugues/primitivas-dicionario.js.map +1 -0
- package/bibliotecas/dialetos/pitugues/primitivas-numero.d.ts +6 -0
- package/bibliotecas/dialetos/pitugues/primitivas-numero.d.ts.map +1 -0
- package/bibliotecas/dialetos/pitugues/primitivas-numero.js +84 -0
- package/bibliotecas/dialetos/pitugues/primitivas-numero.js.map +1 -0
- package/bibliotecas/dialetos/pitugues/primitivas-texto.d.ts +6 -0
- package/bibliotecas/dialetos/pitugues/primitivas-texto.d.ts.map +1 -0
- package/bibliotecas/dialetos/pitugues/primitivas-texto.js +254 -0
- package/bibliotecas/dialetos/pitugues/primitivas-texto.js.map +1 -0
- package/bibliotecas/dialetos/pitugues/primitivas-vetor.d.ts +6 -0
- package/bibliotecas/dialetos/pitugues/primitivas-vetor.d.ts.map +1 -0
- package/bibliotecas/dialetos/pitugues/primitivas-vetor.js +373 -0
- package/bibliotecas/dialetos/pitugues/primitivas-vetor.js.map +1 -0
- package/bibliotecas/primitivas-vetor.d.ts.map +1 -1
- package/bibliotecas/primitivas-vetor.js +6 -5
- package/bibliotecas/primitivas-vetor.js.map +1 -1
- package/bin/package.json +1 -1
- package/construtos/elvis.d.ts +2 -2
- package/construtos/elvis.d.ts.map +1 -1
- package/construtos/elvis.js.map +1 -1
- package/construtos/enquanto-como-construto.d.ts +4 -4
- package/construtos/fazer-como-construto.d.ts +4 -4
- package/construtos/importar-como-construto.d.ts +3 -3
- package/construtos/importar-como-construto.d.ts.map +1 -1
- package/construtos/importar-como-construto.js.map +1 -1
- package/construtos/para-cada-como-construto.d.ts +6 -6
- package/construtos/para-como-construto.d.ts +4 -4
- package/construtos/se-ternario.d.ts +2 -2
- package/formatadores/formatador-pitugues.d.ts.map +1 -1
- package/formatadores/formatador-pitugues.js.map +1 -1
- package/geracao-identificadores/index.d.ts.map +1 -1
- package/geracao-identificadores/index.js.map +1 -1
- package/informacao-elemento-sintatico.d.ts +1 -1
- package/interfaces/delegua/enquanto-interface.d.ts +2 -2
- package/interfaces/delegua/fazer-interface.d.ts +2 -2
- package/interfaces/delegua/para-cada-interface.d.ts +2 -2
- package/interfaces/delegua/para-interface.d.ts +2 -2
- package/interfaces/visitante-comum-interface.d.ts.map +1 -1
- package/interfaces/visitante-delegua-interface.d.ts +3 -3
- package/interfaces/visitante-delegua-interface.d.ts.map +1 -1
- package/interpretador/comum.d.ts.map +1 -1
- package/interpretador/comum.js +1 -0
- package/interpretador/comum.js.map +1 -1
- package/interpretador/depuracao/comum.d.ts.map +1 -1
- package/interpretador/depuracao/comum.js +6 -3
- package/interpretador/depuracao/comum.js.map +1 -1
- package/interpretador/dialetos/pitugues/index.d.ts +2 -0
- package/interpretador/dialetos/pitugues/index.d.ts.map +1 -0
- package/interpretador/dialetos/pitugues/index.js +18 -0
- package/interpretador/dialetos/pitugues/index.js.map +1 -0
- package/interpretador/dialetos/pitugues/interpretador-pitugues.d.ts +17 -0
- package/interpretador/dialetos/pitugues/interpretador-pitugues.d.ts.map +1 -0
- package/interpretador/dialetos/pitugues/interpretador-pitugues.js +248 -0
- package/interpretador/dialetos/pitugues/interpretador-pitugues.js.map +1 -0
- package/interpretador/estruturas/classe-de-modulo.d.ts +1 -1
- package/interpretador/estruturas/classe-de-modulo.d.ts.map +1 -1
- package/interpretador/estruturas/classe-de-modulo.js.map +1 -1
- package/interpretador/interpretador-base.d.ts.map +1 -1
- package/interpretador/interpretador-base.js +6 -5
- package/interpretador/interpretador-base.js.map +1 -1
- package/interpretador/interpretador.d.ts +5 -0
- package/interpretador/interpretador.d.ts.map +1 -1
- package/interpretador/interpretador.js +39 -22
- package/interpretador/interpretador.js.map +1 -1
- package/lexador/dialetos/lexador-pitugues.js.map +1 -1
- package/lexador/dialetos/palavras-reservadas/pitugues.d.ts +1 -0
- package/lexador/dialetos/palavras-reservadas/pitugues.d.ts.map +1 -1
- package/lexador/dialetos/palavras-reservadas/pitugues.js +2 -1
- package/lexador/dialetos/palavras-reservadas/pitugues.js.map +1 -1
- package/package.json +1 -1
- package/quebras/index.d.ts.map +1 -1
- package/quebras/index.js.map +1 -1
- package/tipos-de-simbolos/pitugues.d.ts.map +1 -1
- package/tipos-de-simbolos/pitugues.js.map +1 -1
- package/tradutores/tradutor-javascript.js.map +1 -1
- package/tradutores/tradutor-python.d.ts.map +1 -1
- package/tradutores/tradutor-python.js.map +1 -1
- package/umd/delegua.js +363 -60
|
@@ -0,0 +1,686 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.aleatorio = aleatorio;
|
|
4
|
+
exports.aleatorio_entre = aleatorio_entre;
|
|
5
|
+
exports.algum = algum;
|
|
6
|
+
exports.encontrar = encontrar;
|
|
7
|
+
exports.encontrar_indice = encontrar_indice;
|
|
8
|
+
exports.encontrar_ultimo = encontrar_ultimo;
|
|
9
|
+
exports.encontrar_ultimo_indice = encontrar_ultimo_indice;
|
|
10
|
+
exports.filtrar_por = filtrar_por;
|
|
11
|
+
exports.incluido = incluido;
|
|
12
|
+
exports.inteiro = inteiro;
|
|
13
|
+
exports.mapear = mapear;
|
|
14
|
+
exports.numero = numero;
|
|
15
|
+
exports.ordenar = ordenar;
|
|
16
|
+
exports.para_cada = para_cada;
|
|
17
|
+
exports.primeiro_em_condicao = primeiro_em_condicao;
|
|
18
|
+
exports.real = real;
|
|
19
|
+
exports.reduzir = reduzir;
|
|
20
|
+
exports.tamanho = tamanho;
|
|
21
|
+
exports.texto = texto;
|
|
22
|
+
exports.todos_em_condicao = todos_em_condicao;
|
|
23
|
+
exports.tupla = tupla;
|
|
24
|
+
const excecoes_1 = require("../../../excecoes");
|
|
25
|
+
const objeto_delegua_classe_1 = require("../../../interpretador/estruturas/objeto-delegua-classe");
|
|
26
|
+
const funcao_padrao_1 = require("../../../interpretador/estruturas/funcao-padrao");
|
|
27
|
+
const descritor_tipo_classe_1 = require("../../../interpretador/estruturas/descritor-tipo-classe");
|
|
28
|
+
const estruturas_1 = require("../../../interpretador/estruturas");
|
|
29
|
+
const construtos_1 = require("../../../construtos");
|
|
30
|
+
const quebras_1 = require("../../../quebras");
|
|
31
|
+
/**
|
|
32
|
+
* Retorna um número aleatório entre 0 e 1.
|
|
33
|
+
* @returns {Promise<number>} Número real.
|
|
34
|
+
*/
|
|
35
|
+
async function aleatorio(interpretador) {
|
|
36
|
+
return Promise.resolve(Math.random());
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Retorna um número aleatório de acordo com o parâmetro passado.
|
|
40
|
+
* Mínimo(inclusivo) - Máximo(exclusivo).
|
|
41
|
+
* @param {number} minimo O número mínimo.
|
|
42
|
+
* @param {number} maximo O número máximo.
|
|
43
|
+
* @returns {Promise<number>} Um número real entre os valores máximo e mínimo especificados.
|
|
44
|
+
*/
|
|
45
|
+
async function aleatorio_entre(interpretador, minimo, maximo) {
|
|
46
|
+
if (arguments.length <= 0) {
|
|
47
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
48
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
49
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
50
|
+
}, 'A função recebe ao menos um parâmetro.'));
|
|
51
|
+
}
|
|
52
|
+
const valorMinimo = minimo.hasOwnProperty('valor')
|
|
53
|
+
? minimo.valor
|
|
54
|
+
: minimo;
|
|
55
|
+
if (arguments.length === 2) {
|
|
56
|
+
if (typeof valorMinimo !== 'number') {
|
|
57
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
58
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
59
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
60
|
+
}, 'O parâmetro deve ser um número.'));
|
|
61
|
+
}
|
|
62
|
+
return Math.floor(Math.random() * (0 - valorMinimo)) + valorMinimo;
|
|
63
|
+
}
|
|
64
|
+
if (arguments.length > 3) {
|
|
65
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
66
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
67
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
68
|
+
}, 'A quantidade de parâmetros máxima para esta função é 2.'));
|
|
69
|
+
}
|
|
70
|
+
const valorMaximo = maximo.hasOwnProperty('valor')
|
|
71
|
+
? maximo.valor
|
|
72
|
+
: maximo;
|
|
73
|
+
if (typeof valorMinimo !== 'number' || typeof valorMaximo !== 'number') {
|
|
74
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
75
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
76
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
77
|
+
}, 'Os dois parâmetros devem ser do tipo número.'));
|
|
78
|
+
}
|
|
79
|
+
return Promise.resolve(Math.floor(Math.random() * (valorMaximo - valorMinimo)) + valorMinimo);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Verifica se algum dos elementos satisfaz à condição para por parâmetro.
|
|
83
|
+
* @param {InterpretadorInterface} interpretador A instância do interpretador.
|
|
84
|
+
* @param {VariavelInterface | any} vetor Uma variável de Delégua ou um vetor nativo de JavaScript.
|
|
85
|
+
* @param {VariavelInterface | any} funcaoPesquisa A função que ensina o método de pesquisa.
|
|
86
|
+
* @returns {Promise<boolean>} Verdadeiro se há algum elemento no vetor com a condição. Falso caso contrário.
|
|
87
|
+
*/
|
|
88
|
+
async function algum(interpretador, vetor, funcaoPesquisa) {
|
|
89
|
+
const valorVetor = vetor.hasOwnProperty('valor') ? vetor.valor : vetor;
|
|
90
|
+
const valorFuncaoPesquisa = funcaoPesquisa.hasOwnProperty('valor')
|
|
91
|
+
? funcaoPesquisa.valor
|
|
92
|
+
: funcaoPesquisa;
|
|
93
|
+
if (!Array.isArray(valorVetor)) {
|
|
94
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
95
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
96
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
97
|
+
}, 'Parâmetro inválido. O primeiro parâmetro da função deve ser um vetor.'));
|
|
98
|
+
}
|
|
99
|
+
if (valorFuncaoPesquisa.constructor.name !== 'DeleguaFuncao') {
|
|
100
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
101
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
102
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
103
|
+
}, 'Parâmetro inválido. O segundo parâmetro da função deve ser uma função.'));
|
|
104
|
+
}
|
|
105
|
+
for (let indice = 0; indice < valorVetor.length; ++indice) {
|
|
106
|
+
if (await valorFuncaoPesquisa.chamar(interpretador, [valorVetor[indice]])) {
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Encontra o primeiro elemento de um vetor cuja função de pesquisa retorne
|
|
114
|
+
* verdadeiro na avaliação de cada elemento.
|
|
115
|
+
* @param {InterpretadorInterface} interpretador A instância do interpretador.
|
|
116
|
+
* @param {VariavelInterface | any} vetor Uma variável de Delégua ou um vetor nativo de JavaScript.
|
|
117
|
+
* @param {VariavelInterface | any} funcaoPesquisa A função que ensina o método de pesquisa.
|
|
118
|
+
* @returns {Promise<any>} Um elemento, caso o elemento seja encontraro, ou nulo em caso contrário.
|
|
119
|
+
*/
|
|
120
|
+
async function encontrar(interpretador, vetor, funcaoPesquisa) {
|
|
121
|
+
const valorVetor = vetor.hasOwnProperty('valor') ? vetor.valor : vetor;
|
|
122
|
+
const valorFuncaoPesquisa = funcaoPesquisa.hasOwnProperty('valor')
|
|
123
|
+
? funcaoPesquisa.valor
|
|
124
|
+
: funcaoPesquisa;
|
|
125
|
+
if (!Array.isArray(valorVetor)) {
|
|
126
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
127
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
128
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
129
|
+
}, 'Parâmetro inválido. O primeiro parâmetro da função deve ser um vetor.'));
|
|
130
|
+
}
|
|
131
|
+
if (valorFuncaoPesquisa.constructor.name !== 'DeleguaFuncao') {
|
|
132
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
133
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
134
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
135
|
+
}, 'Parâmetro inválido. O segundo parâmetro da função deve ser uma função.'));
|
|
136
|
+
}
|
|
137
|
+
for (let indice = 0; indice < valorVetor.length; ++indice) {
|
|
138
|
+
if (await valorFuncaoPesquisa.chamar(interpretador, [valorVetor[indice]])) {
|
|
139
|
+
return valorVetor[indice];
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Encontra o índice do primeiro elemento de um vetor cuja função de pesquisa retorne
|
|
146
|
+
* verdadeiro na avaliação de cada elemento.
|
|
147
|
+
* @param {InterpretadorInterface} interpretador A instância do interpretador.
|
|
148
|
+
* @param {VariavelInterface | any} vetor Uma variável de Delégua ou um vetor nativo de JavaScript.
|
|
149
|
+
* @param {VariavelInterface | any} funcaoPesquisa A função que ensina o método de pesquisa.
|
|
150
|
+
* @returns {Promise<number>} O número correspondente ao índice se o elemento for encontrado, ou nulo em caso contrário.
|
|
151
|
+
*/
|
|
152
|
+
async function encontrar_indice(interpretador, vetor, funcaoPesquisa) {
|
|
153
|
+
const valorVetor = vetor.hasOwnProperty('valor') ? vetor.valor : vetor;
|
|
154
|
+
const valorFuncaoPesquisa = funcaoPesquisa.hasOwnProperty('valor')
|
|
155
|
+
? funcaoPesquisa.valor
|
|
156
|
+
: funcaoPesquisa;
|
|
157
|
+
if (!Array.isArray(valorVetor)) {
|
|
158
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
159
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
160
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
161
|
+
}, 'Parâmetro inválido. O primeiro parâmetro da função deve ser um vetor.'));
|
|
162
|
+
}
|
|
163
|
+
if (valorFuncaoPesquisa.constructor.name !== 'DeleguaFuncao') {
|
|
164
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
165
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
166
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
167
|
+
}, 'Parâmetro inválido. O segundo parâmetro da função deve ser uma função.'));
|
|
168
|
+
}
|
|
169
|
+
for (let indice = 0; indice < valorVetor.length; ++indice) {
|
|
170
|
+
if (await valorFuncaoPesquisa.chamar(interpretador, [valorVetor[indice]])) {
|
|
171
|
+
return indice;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return -1;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Encontrar o último elemento de um vetor cuja função de pesquisa retorne
|
|
178
|
+
* verdadeiro na avaliação de cada elemento.
|
|
179
|
+
* @param {InterpretadorInterface} interpretador A instância do interpretador.
|
|
180
|
+
* @param {VariavelInterface | any} vetor Uma variável de Delégua ou um vetor nativo de JavaScript.
|
|
181
|
+
* @param {VariavelInterface | any} funcaoPesquisa A função que ensina o método de pesquisa.
|
|
182
|
+
* @returns {Promise<any>} O número correspondente ao índice se o elemento for encontrado, ou nulo em caso contrário.
|
|
183
|
+
*/
|
|
184
|
+
async function encontrar_ultimo(interpretador, vetor, funcaoPesquisa) {
|
|
185
|
+
const valorVetor = vetor.hasOwnProperty('valor') ? vetor.valor : vetor;
|
|
186
|
+
const valorFuncaoPesquisa = funcaoPesquisa.hasOwnProperty('valor')
|
|
187
|
+
? funcaoPesquisa.valor
|
|
188
|
+
: funcaoPesquisa;
|
|
189
|
+
if (!Array.isArray(valorVetor)) {
|
|
190
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
191
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
192
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
193
|
+
}, 'Parâmetro inválido. O primeiro parâmetro da função deve ser um vetor.'));
|
|
194
|
+
}
|
|
195
|
+
if (valorFuncaoPesquisa.constructor.name !== 'DeleguaFuncao') {
|
|
196
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
197
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
198
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
199
|
+
}, 'Parâmetro inválido. O segundo parâmetro da função deve ser uma função.'));
|
|
200
|
+
}
|
|
201
|
+
for (let indice = valorVetor.length - 1; indice >= 0; --indice) {
|
|
202
|
+
if (await valorFuncaoPesquisa.chamar(interpretador, [valorVetor[indice]])) {
|
|
203
|
+
return valorVetor[indice];
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
*
|
|
210
|
+
* @param {InterpretadorInterface} interpretador A instância do interpretador.
|
|
211
|
+
* @param {VariavelInterface | any} vetor Uma variável de Delégua ou um vetor nativo de JavaScript.
|
|
212
|
+
* @param {VariavelInterface | any} funcaoPesquisa A função que ensina o método de pesquisa.
|
|
213
|
+
* @returns {Promise<number>} O número correspondente ao índice se o elemento for encontrado, ou nulo em caso contrário.
|
|
214
|
+
*/
|
|
215
|
+
async function encontrar_ultimo_indice(interpretador, vetor, funcaoPesquisa) {
|
|
216
|
+
const valorVetor = vetor.hasOwnProperty('valor') ? vetor.valor : vetor;
|
|
217
|
+
const valorFuncaoPesquisa = funcaoPesquisa.hasOwnProperty('valor')
|
|
218
|
+
? funcaoPesquisa.valor
|
|
219
|
+
: funcaoPesquisa;
|
|
220
|
+
if (!Array.isArray(valorVetor)) {
|
|
221
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
222
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
223
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
224
|
+
}, 'Parâmetro inválido. O primeiro parâmetro da função deve ser um vetor.'));
|
|
225
|
+
}
|
|
226
|
+
if (valorFuncaoPesquisa.constructor.name !== 'DeleguaFuncao') {
|
|
227
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
228
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
229
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
230
|
+
}, 'Parâmetro inválido. O segundo parâmetro da função deve ser uma função.'));
|
|
231
|
+
}
|
|
232
|
+
for (let indice = valorVetor.length - 1; indice >= 0; --indice) {
|
|
233
|
+
if (await valorFuncaoPesquisa.chamar(interpretador, [valorVetor[indice]])) {
|
|
234
|
+
return indice;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
*
|
|
241
|
+
* @param interpretador
|
|
242
|
+
* @param vetor
|
|
243
|
+
* @param funcaoFiltragem
|
|
244
|
+
* @returns
|
|
245
|
+
*/
|
|
246
|
+
async function filtrar_por(interpretador, vetor, funcaoFiltragem) {
|
|
247
|
+
if (vetor === null || vetor === undefined)
|
|
248
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
249
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
250
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
251
|
+
}, 'Parâmetro inválido. O primeiro parâmetro da função filtrarPor() não pode ser nulo.'));
|
|
252
|
+
const valorVetor = vetor.hasOwnProperty('valor') ? vetor.valor : vetor;
|
|
253
|
+
const valorFuncaoFiltragem = funcaoFiltragem.hasOwnProperty('valor')
|
|
254
|
+
? funcaoFiltragem.valor
|
|
255
|
+
: funcaoFiltragem;
|
|
256
|
+
if (!Array.isArray(valorVetor)) {
|
|
257
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
258
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
259
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
260
|
+
}, 'Parâmetro inválido. O primeiro parâmetro da função filtrarPor() deve ser um vetor.'));
|
|
261
|
+
}
|
|
262
|
+
const construtorResolvido = valorFuncaoFiltragem.constructor.name.replaceAll('_', '');
|
|
263
|
+
if (construtorResolvido !== 'DeleguaFuncao') {
|
|
264
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
265
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
266
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
267
|
+
}, 'Parâmetro inválido. O segundo parâmetro da função filtrarPor() deve ser uma função.'));
|
|
268
|
+
}
|
|
269
|
+
const resultados = [];
|
|
270
|
+
for (let indice = 0; indice < valorVetor.length; ++indice) {
|
|
271
|
+
const informacoesValor = await valorFuncaoFiltragem.chamar(interpretador, [
|
|
272
|
+
valorVetor[indice],
|
|
273
|
+
]);
|
|
274
|
+
if (informacoesValor === null || informacoesValor === undefined) {
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
const deveRetornarValor = informacoesValor.valorRetornado.valor;
|
|
278
|
+
if (deveRetornarValor === false)
|
|
279
|
+
continue;
|
|
280
|
+
resultados.push(valorVetor[indice]);
|
|
281
|
+
}
|
|
282
|
+
return resultados;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
*
|
|
286
|
+
* @param {InterpretadorInterface} interpretador A instância do interpretador.
|
|
287
|
+
* @param {VariavelInterface | any} vetor Uma variável de Delégua ou um vetor nativo de JavaScript.
|
|
288
|
+
* @param valor
|
|
289
|
+
* @returns
|
|
290
|
+
*/
|
|
291
|
+
async function incluido(interpretador, vetor, valor) {
|
|
292
|
+
const valorVetor = vetor.hasOwnProperty('valor') ? vetor.valor : vetor;
|
|
293
|
+
const valorValor = valor.hasOwnProperty('valor') ? valor.valor : valor;
|
|
294
|
+
if (!Array.isArray(valorVetor)) {
|
|
295
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
296
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
297
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
298
|
+
}, 'Parâmetro inválido. O primeiro parâmetro da função deve ser um vetor.'));
|
|
299
|
+
}
|
|
300
|
+
for (let indice = 0; indice < valorVetor.length; ++indice) {
|
|
301
|
+
if (valorVetor[indice] == valorValor) {
|
|
302
|
+
return true;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
function validacao_comum_numeros(interpretador, valorParaConverter) {
|
|
308
|
+
if (isNaN(valorParaConverter)) {
|
|
309
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
310
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
311
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
312
|
+
}, 'Valor não parece ser um número. Somente números ou textos com números podem ser convertidos para inteiro.'));
|
|
313
|
+
}
|
|
314
|
+
if (!/^(-)?\d+(\.\d+)?$/.test(valorParaConverter)) {
|
|
315
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
316
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
317
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
318
|
+
}, 'Valor não parece estar estruturado como um número (texto vazio, falso ou não definido). Somente números ou textos com números podem ser convertidos para inteiro.'));
|
|
319
|
+
}
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Converte um valor em um número inteiro.
|
|
324
|
+
* @param {InterpretadorInterface} interpretador A instância do interpretador.
|
|
325
|
+
* @param {VariavelInterface | any} valorParaConverter O valor a ser convertido.
|
|
326
|
+
* @returns {Promise<any>} Uma Promise com o resultado da conversão.
|
|
327
|
+
*/
|
|
328
|
+
async function inteiro(interpretador, valorParaConverter) {
|
|
329
|
+
if (valorParaConverter === null || valorParaConverter === undefined)
|
|
330
|
+
return Promise.resolve(0);
|
|
331
|
+
const valor = valorParaConverter.hasOwnProperty('valor')
|
|
332
|
+
? valorParaConverter.valor
|
|
333
|
+
: valorParaConverter;
|
|
334
|
+
const resultadoValidacao = validacao_comum_numeros(interpretador, valor);
|
|
335
|
+
return resultadoValidacao || Promise.resolve(parseInt(valor));
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Dado um vetor e uma função de mapeamento, executa a função de mapeamento
|
|
339
|
+
* passando como argumento cada elemento do vetor.
|
|
340
|
+
* @param interpretador A instância do interpretador.
|
|
341
|
+
* @param vetor O vetor
|
|
342
|
+
* @param funcaoMapeamento A função de mapeamento.
|
|
343
|
+
* @returns O resultado acumulado da execução da função de mapeamento.
|
|
344
|
+
*/
|
|
345
|
+
async function mapear(interpretador, vetor, funcaoMapeamento) {
|
|
346
|
+
if (vetor === null || vetor === undefined)
|
|
347
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
348
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
349
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
350
|
+
}, 'Parâmetro inválido. O primeiro parâmetro da função mapear() não pode ser nulo.'));
|
|
351
|
+
const valorVetor = interpretador.resolverValor(vetor);
|
|
352
|
+
const valorFuncaoMapeamento = interpretador.resolverValor(funcaoMapeamento);
|
|
353
|
+
// TODO: As lógicas de validação abaixo deixam de fazer sentido com a validação de argumentos feita
|
|
354
|
+
// na avaliação sintática. Estudar remoção.
|
|
355
|
+
if (!Array.isArray(valorVetor)) {
|
|
356
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
357
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
358
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
359
|
+
}, 'Parâmetro inválido. O primeiro parâmetro da função mapear() deve ser um vetor.'));
|
|
360
|
+
}
|
|
361
|
+
const nomeConstrutorFuncaoMapeamento = valorFuncaoMapeamento.constructor.name.replaceAll('_', '');
|
|
362
|
+
if (nomeConstrutorFuncaoMapeamento !== 'DeleguaFuncao') {
|
|
363
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
364
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
365
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
366
|
+
}, 'Parâmetro inválido. O segundo parâmetro da função mapear() deve ser uma função.'));
|
|
367
|
+
}
|
|
368
|
+
const resultados = [];
|
|
369
|
+
for (let indice = 0; indice < valorVetor.length; ++indice) {
|
|
370
|
+
const informacoesRetorno = await valorFuncaoMapeamento.chamar(interpretador, [
|
|
371
|
+
valorVetor[indice],
|
|
372
|
+
]);
|
|
373
|
+
if (!informacoesRetorno.hasOwnProperty('valorRetornado')) {
|
|
374
|
+
console.warn(`Retorno inconsistente em mapear(): ${JSON.stringify(informacoesRetorno)}.`);
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
if (!(informacoesRetorno.valorRetornado instanceof quebras_1.RetornoQuebra)) {
|
|
378
|
+
console.warn(`mapear() finalizado com valor retornado diferente do esperado: ${JSON.stringify(informacoesRetorno)}.`);
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
resultados.push(informacoesRetorno.valorRetornado.valor);
|
|
382
|
+
}
|
|
383
|
+
return resultados;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Converte um valor em um número, com parte decimal ou não.
|
|
387
|
+
* @param {InterpretadorInterface} interpretador A instância do interpretador.
|
|
388
|
+
* @param {VariavelInterface | any} valorParaConverter O valor a ser convertido.
|
|
389
|
+
* @returns {Promise<any>} Uma Promise com o resultado da conversão.
|
|
390
|
+
*/
|
|
391
|
+
async function numero(interpretador, valorParaConverter) {
|
|
392
|
+
if (valorParaConverter === null || valorParaConverter === undefined)
|
|
393
|
+
return Promise.resolve(0);
|
|
394
|
+
const valor = valorParaConverter.hasOwnProperty('valor')
|
|
395
|
+
? valorParaConverter.valor
|
|
396
|
+
: valorParaConverter;
|
|
397
|
+
const resultadoValidacao = validacao_comum_numeros(interpretador, valor);
|
|
398
|
+
return resultadoValidacao || Promise.resolve(Number(valor));
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
*
|
|
402
|
+
* @param vetor
|
|
403
|
+
* @returns
|
|
404
|
+
*/
|
|
405
|
+
async function ordenar(interpretador, vetor) {
|
|
406
|
+
if (vetor === null || vetor === undefined)
|
|
407
|
+
throw new excecoes_1.ErroEmTempoDeExecucao({
|
|
408
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
409
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
410
|
+
}, 'Parâmetro inválido. O primeiro parâmetro da função ordenar() não pode ser nulo.');
|
|
411
|
+
const objeto = vetor.hasOwnProperty('valor') ? vetor.valor : vetor;
|
|
412
|
+
if (!Array.isArray(objeto)) {
|
|
413
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
414
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
415
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
416
|
+
}, 'Valor inválido. Objeto inserido não é um vetor.'));
|
|
417
|
+
}
|
|
418
|
+
let trocado;
|
|
419
|
+
const tamanho = objeto.length;
|
|
420
|
+
do {
|
|
421
|
+
trocado = false;
|
|
422
|
+
for (let i = 0; i < tamanho - 1; i++) {
|
|
423
|
+
if (objeto[i] > objeto[i + 1]) {
|
|
424
|
+
[objeto[i], objeto[i + 1]] = [objeto[i + 1], objeto[i]];
|
|
425
|
+
trocado = true;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
} while (trocado);
|
|
429
|
+
return Promise.resolve(objeto);
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
*
|
|
433
|
+
* @param interpretador
|
|
434
|
+
* @param vetor
|
|
435
|
+
* @param funcaoFiltragem
|
|
436
|
+
* @returns
|
|
437
|
+
*/
|
|
438
|
+
async function para_cada(interpretador, vetor, funcaoFiltragem) {
|
|
439
|
+
if (vetor === null || vetor === undefined)
|
|
440
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
441
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
442
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
443
|
+
}, 'Parâmetro inválido. O primeiro parâmetro da função paraCada() não pode ser nulo.'));
|
|
444
|
+
const valorVetor = vetor.hasOwnProperty('valor') ? vetor.valor : vetor;
|
|
445
|
+
const valorFuncaoFiltragem = funcaoFiltragem.hasOwnProperty('valor')
|
|
446
|
+
? funcaoFiltragem.valor
|
|
447
|
+
: funcaoFiltragem;
|
|
448
|
+
// TODO: As lógicas de validação abaixo deixam de fazer sentido com a validação de argumentos feita
|
|
449
|
+
// na avaliação sintática. Estudar remoção.
|
|
450
|
+
if (!Array.isArray(valorVetor)) {
|
|
451
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
452
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
453
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
454
|
+
}, 'Parâmetro inválido. O primeiro parâmetro da função paraCada() deve ser um vetor.'));
|
|
455
|
+
}
|
|
456
|
+
if (valorFuncaoFiltragem.constructor.name !== 'DeleguaFuncao') {
|
|
457
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
458
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
459
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
460
|
+
}, 'Parâmetro inválido. O segundo parâmetro da função paraCada() deve ser uma função.'));
|
|
461
|
+
}
|
|
462
|
+
for (let indice = 0; indice < valorVetor.length; ++indice) {
|
|
463
|
+
await valorFuncaoFiltragem.chamar(interpretador, [valorVetor[indice]]);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
*
|
|
468
|
+
* @param interpretador
|
|
469
|
+
* @param vetor
|
|
470
|
+
* @param funcaoFiltragem
|
|
471
|
+
* @returns
|
|
472
|
+
*/
|
|
473
|
+
async function primeiro_em_condicao(interpretador, vetor, funcaoFiltragem) {
|
|
474
|
+
if (vetor === null || vetor === undefined)
|
|
475
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
476
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
477
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
478
|
+
}, 'Parâmetro inválido. O primeiro parâmetro da função primeiroEmCondicao() não pode ser nulo.'));
|
|
479
|
+
const valorVetor = vetor.hasOwnProperty('valor') ? vetor.valor : vetor;
|
|
480
|
+
const valorFuncaoFiltragem = funcaoFiltragem.hasOwnProperty('valor')
|
|
481
|
+
? funcaoFiltragem.valor
|
|
482
|
+
: funcaoFiltragem;
|
|
483
|
+
if (!Array.isArray(valorVetor)) {
|
|
484
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
485
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
486
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
487
|
+
}, 'Parâmetro inválido. O primeiro parâmetro da função primeiroEmCondicao() deve ser um vetor.'));
|
|
488
|
+
}
|
|
489
|
+
if (valorFuncaoFiltragem.constructor.name !== 'DeleguaFuncao') {
|
|
490
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
491
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
492
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
493
|
+
}, 'Parâmetro inválido. O segundo parâmetro da função primeiroEmCondicao() deve ser uma função.'));
|
|
494
|
+
}
|
|
495
|
+
for (let indice = 0; indice < valorVetor.length; ++indice) {
|
|
496
|
+
const valorResolvido = await valorFuncaoFiltragem.chamar(interpretador, [
|
|
497
|
+
valorVetor[indice],
|
|
498
|
+
]);
|
|
499
|
+
if (valorResolvido !== null) {
|
|
500
|
+
return valorResolvido;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
return undefined;
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
*
|
|
507
|
+
* @param interpretador
|
|
508
|
+
* @param numero
|
|
509
|
+
* @returns
|
|
510
|
+
*/
|
|
511
|
+
async function real(interpretador, numero) {
|
|
512
|
+
if (numero === null || numero === undefined)
|
|
513
|
+
return Promise.resolve(parseFloat('0'));
|
|
514
|
+
const valor = numero.hasOwnProperty('valor') ? numero.valor : numero;
|
|
515
|
+
if (!/^(-)?\d+(\.\d+)?$/.test(valor)) {
|
|
516
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
517
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
518
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
519
|
+
}, 'Valor não parece estar estruturado como um número (texto/valor vazio, falso ou não definido). Somente números ou textos com números podem ser convertidos para real.'));
|
|
520
|
+
}
|
|
521
|
+
return Promise.resolve(parseFloat(valor));
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
*
|
|
525
|
+
* @param interpretador
|
|
526
|
+
* @param vetor
|
|
527
|
+
* @param funcaoReducao
|
|
528
|
+
* @param valorInicial
|
|
529
|
+
* @returns
|
|
530
|
+
*/
|
|
531
|
+
async function reduzir(interpretador, vetor, funcaoReducao, valorInicial = null) {
|
|
532
|
+
const valorVetor = vetor.hasOwnProperty('valor') ? vetor.valor : vetor;
|
|
533
|
+
const valorFuncaoReducao = funcaoReducao.hasOwnProperty('valor')
|
|
534
|
+
? funcaoReducao.valor
|
|
535
|
+
: funcaoReducao;
|
|
536
|
+
const valorPadrao = valorInicial.hasOwnProperty('valor') ? valorInicial.valor : valorInicial;
|
|
537
|
+
if (!Array.isArray(valorVetor)) {
|
|
538
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
539
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
540
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
541
|
+
}, 'Parâmetro inválido. O primeiro parâmetro da função deve ser um vetor.'));
|
|
542
|
+
}
|
|
543
|
+
if (valorFuncaoReducao.constructor.name !== 'DeleguaFuncao') {
|
|
544
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
545
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
546
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
547
|
+
}, 'Parâmetro inválido. O segundo parâmetro da função deve ser uma função.'));
|
|
548
|
+
}
|
|
549
|
+
let resultado = valorPadrao;
|
|
550
|
+
let inicio = 0;
|
|
551
|
+
if (!resultado) {
|
|
552
|
+
resultado = vetor[0];
|
|
553
|
+
inicio = 1;
|
|
554
|
+
}
|
|
555
|
+
for (let index = inicio; index < vetor.length; ++index) {
|
|
556
|
+
resultado = await valorFuncaoReducao.chamar(interpretador, [resultado, vetor[index]]);
|
|
557
|
+
}
|
|
558
|
+
return resultado;
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
*
|
|
562
|
+
* @param objeto
|
|
563
|
+
* @returns
|
|
564
|
+
*/
|
|
565
|
+
async function tamanho(interpretador, objeto) {
|
|
566
|
+
const valorObjeto = objeto.hasOwnProperty('valor') ? objeto.valor : objeto;
|
|
567
|
+
if (typeof valorObjeto === 'number') {
|
|
568
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
569
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
570
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
571
|
+
}, 'Função global tamanho() não funciona com números.'));
|
|
572
|
+
}
|
|
573
|
+
if (valorObjeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse) {
|
|
574
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
575
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
576
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
577
|
+
}, 'Função global tamanho não funciona com objetos complexos.'));
|
|
578
|
+
}
|
|
579
|
+
if (valorObjeto instanceof estruturas_1.DeleguaFuncao) {
|
|
580
|
+
return Promise.resolve(valorObjeto.declaracao.parametros.length);
|
|
581
|
+
}
|
|
582
|
+
if (valorObjeto instanceof funcao_padrao_1.FuncaoPadrao) {
|
|
583
|
+
return Promise.resolve(valorObjeto.valorAridade);
|
|
584
|
+
}
|
|
585
|
+
if (valorObjeto instanceof descritor_tipo_classe_1.DescritorTipoClasse) {
|
|
586
|
+
const metodos = valorObjeto.metodos;
|
|
587
|
+
let tamanho = 0;
|
|
588
|
+
if (metodos.inicializacao && metodos.inicializacao.eInicializador) {
|
|
589
|
+
tamanho = metodos.inicializacao.declaracao.parametros.length;
|
|
590
|
+
}
|
|
591
|
+
return Promise.resolve(tamanho);
|
|
592
|
+
}
|
|
593
|
+
return Promise.resolve(valorObjeto.length);
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Transforma o valor ou variável em texto.
|
|
597
|
+
* @param {InterpretadorInterface} interpretador A instância do interpretador.
|
|
598
|
+
* @param {VariavelInterface | any} valorParaConverter O valor ou variável.
|
|
599
|
+
* @returns {Promise<string>} O valor resolvido em texto.
|
|
600
|
+
*/
|
|
601
|
+
async function texto(interpretador, valorParaConverter) {
|
|
602
|
+
return Promise.resolve(`${valorParaConverter.hasOwnProperty('valor') ? valorParaConverter.valor : valorParaConverter}`);
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Retorna verdadeiro se todos os elementos do primeiro parâmetro retornam verdadeiro ao
|
|
606
|
+
* serem aplicados como argumentos da função passada como segundo parâmetro.
|
|
607
|
+
* @param {InterpretadorInterface} interpretador A instância do interpretador.
|
|
608
|
+
* @param {VariavelInterface | any} vetor O primeiro parâmetro, um vetor.
|
|
609
|
+
* @param {VariavelInterface | any} funcaoCondicional A função que será executada com cada
|
|
610
|
+
* valor do vetor passado como primeiro parâmetro.
|
|
611
|
+
* @returns {Promise<boolean>} Verdadeiro, se todos os valores do vetor fazem a função passada
|
|
612
|
+
* por parâmetro devolver verdadeiro, ou falso em caso contrário.
|
|
613
|
+
*/
|
|
614
|
+
async function todos_em_condicao(interpretador, vetor, funcaoCondicional) {
|
|
615
|
+
if (vetor === null || vetor === undefined)
|
|
616
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
617
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
618
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
619
|
+
}, 'Parâmetro inválido. O primeiro parâmetro da função todosEmCondicao() não pode ser nulo.'));
|
|
620
|
+
const valorVetor = vetor.hasOwnProperty('valor') ? vetor.valor : vetor;
|
|
621
|
+
const valorFuncaoCondicional = funcaoCondicional.hasOwnProperty('valor')
|
|
622
|
+
? funcaoCondicional.valor
|
|
623
|
+
: funcaoCondicional;
|
|
624
|
+
if (!Array.isArray(valorVetor)) {
|
|
625
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
626
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
627
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
628
|
+
}, 'Parâmetro inválido. O primeiro parâmetro da função todosEmCondicao() deve ser um vetor.'));
|
|
629
|
+
}
|
|
630
|
+
if (valorFuncaoCondicional.constructor.name !== 'DeleguaFuncao') {
|
|
631
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
632
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
633
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
634
|
+
}, 'Parâmetro inválido. O segundo parâmetro da função todosEmCondicao() deve ser uma função.'));
|
|
635
|
+
}
|
|
636
|
+
for (let indice = 0; indice < valorVetor.length; ++indice) {
|
|
637
|
+
if (!(await valorFuncaoCondicional.chamar(interpretador, [valorVetor[indice]])))
|
|
638
|
+
return false;
|
|
639
|
+
}
|
|
640
|
+
return true;
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* Transforma um vetor de elementos em uma tupla de N elementos, sendo N a
|
|
644
|
+
* largura do vetor.
|
|
645
|
+
* @param {InterpretadorInterface} interpretador A instância do interpretador.
|
|
646
|
+
* @param {VariavelInterface | any[]} vetor O vetor.
|
|
647
|
+
* @returns A tupla resolvida.
|
|
648
|
+
*/
|
|
649
|
+
async function tupla(interpretador, vetor) {
|
|
650
|
+
const valorVetor = !Array.isArray(vetor) && vetor.hasOwnProperty('valor') ? vetor.valor : vetor;
|
|
651
|
+
// TODO: As lógicas de validação abaixo deixam de fazer sentido com a validação de argumentos feita
|
|
652
|
+
// na avaliação sintática. Estudar remoção.
|
|
653
|
+
if (!Array.isArray(valorVetor)) {
|
|
654
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
655
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
656
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
657
|
+
}, 'Argumento de função nativa `tupla` não parece ser um vetor.'));
|
|
658
|
+
}
|
|
659
|
+
switch (valorVetor.length) {
|
|
660
|
+
case 2:
|
|
661
|
+
return Promise.resolve(new construtos_1.Dupla(valorVetor[0], valorVetor[1]));
|
|
662
|
+
case 3:
|
|
663
|
+
return Promise.resolve(new construtos_1.Trio(valorVetor[0], valorVetor[1], valorVetor[2]));
|
|
664
|
+
case 4:
|
|
665
|
+
return Promise.resolve(new construtos_1.Quarteto(valorVetor[0], valorVetor[1], valorVetor[2], valorVetor[3]));
|
|
666
|
+
case 5:
|
|
667
|
+
return Promise.resolve(new construtos_1.Quinteto(valorVetor[0], valorVetor[1], valorVetor[2], valorVetor[3], valorVetor[4]));
|
|
668
|
+
case 6:
|
|
669
|
+
return Promise.resolve(new construtos_1.Sexteto(valorVetor[0], valorVetor[1], valorVetor[2], valorVetor[3], valorVetor[4], valorVetor[5]));
|
|
670
|
+
case 7:
|
|
671
|
+
return Promise.resolve(new construtos_1.Septeto(valorVetor[0], valorVetor[1], valorVetor[2], valorVetor[3], valorVetor[4], valorVetor[5], valorVetor[6]));
|
|
672
|
+
case 8:
|
|
673
|
+
return Promise.resolve(new construtos_1.Octeto(valorVetor[0], valorVetor[1], valorVetor[2], valorVetor[3], valorVetor[4], valorVetor[5], valorVetor[6], valorVetor[7]));
|
|
674
|
+
case 9:
|
|
675
|
+
return Promise.resolve(new construtos_1.Noneto(valorVetor[0], valorVetor[1], valorVetor[2], valorVetor[3], valorVetor[4], valorVetor[5], valorVetor[6], valorVetor[7], valorVetor[8]));
|
|
676
|
+
case 10:
|
|
677
|
+
return Promise.resolve(new construtos_1.Deceto(valorVetor[0], valorVetor[1], valorVetor[2], valorVetor[3], valorVetor[4], valorVetor[5], valorVetor[6], valorVetor[7], valorVetor[8], valorVetor[9]));
|
|
678
|
+
case 1:
|
|
679
|
+
default:
|
|
680
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
681
|
+
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
682
|
+
linha: interpretador.linhaDeclaracaoAtual,
|
|
683
|
+
}, 'Para ser transformado em uma tupla, vetor precisa ter de 2 a 10 elementos.'));
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
//# sourceMappingURL=biblioteca-global.js.map
|