-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reimplementação das bibliotecas com a nova especificação de funções d…
…e biblioteca de Delégua.
- Loading branch information
1 parent
fce19d2
commit 142c1c7
Showing
6 changed files
with
419 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,72 @@ | ||
import { FuncaoPadrao } from '@designliquido/delegua/estruturas'; | ||
import { PilhaEscoposExecucaoInterface } from '@designliquido/delegua/interfaces/pilha-escopos-execucao-interface'; | ||
import { InterpretadorInterface } from '@designliquido/delegua/interfaces'; | ||
|
||
export function registrarBibliotecaCaracteresVisuAlg( | ||
pilhaEscoposExecucao: PilhaEscoposExecucaoInterface | ||
) { | ||
pilhaEscoposExecucao.definirVariavel( | ||
'asc', | ||
new FuncaoPadrao(1, function (valor: any) { | ||
const valorResolvido = valor.hasOwnProperty('valor') ? valor.valor : valor; | ||
return String(valorResolvido).charCodeAt(0); | ||
}) | ||
); | ||
|
||
pilhaEscoposExecucao.definirVariavel( | ||
'carac', | ||
new FuncaoPadrao(1, function (valor: number) { | ||
return String.fromCharCode(valor); | ||
}) | ||
); | ||
export function asc( | ||
interpretador: InterpretadorInterface, | ||
valor: any | ||
): Promise<number> { | ||
const valorResolvido = valor.hasOwnProperty('valor') ? valor.valor : valor; | ||
return Promise.resolve(String(valorResolvido).charCodeAt(0)); | ||
} | ||
|
||
pilhaEscoposExecucao.definirVariavel( | ||
'caracpnum', | ||
new FuncaoPadrao(1, function (valor: any) { | ||
const valorResolvido = valor.hasOwnProperty('valor') ? valor.valor : valor; | ||
return Number(valorResolvido); | ||
}) | ||
); | ||
export function carac( | ||
interpretador: InterpretadorInterface, | ||
valor: number | ||
): Promise<string> { | ||
return Promise.resolve(String.fromCharCode(valor)); | ||
} | ||
|
||
pilhaEscoposExecucao.definirVariavel( | ||
'compr', | ||
new FuncaoPadrao(1, function (valor: any) { | ||
const valorResolvido = valor.hasOwnProperty('valor') ? valor.valor : valor; | ||
return String(valorResolvido).length; | ||
}) | ||
); | ||
export function caracpnum( | ||
interpretador: InterpretadorInterface, | ||
valor: any | ||
): Promise<number> { | ||
const valorResolvido = valor.hasOwnProperty('valor') ? valor.valor : valor; | ||
return Promise.resolve(Number(valorResolvido)); | ||
} | ||
|
||
pilhaEscoposExecucao.definirVariavel( | ||
'copia', | ||
new FuncaoPadrao(3, function (valor: string, inicio: number, fim: number) { | ||
return valor.substring(inicio, inicio + fim); | ||
}) | ||
); | ||
export function compr( | ||
interpretador: InterpretadorInterface, | ||
valor: any | ||
): Promise<number> { | ||
const valorResolvido = valor.hasOwnProperty('valor') ? valor.valor : valor; | ||
return Promise.resolve(String(valorResolvido).length); | ||
} | ||
|
||
// Esse método não existe na biblioteca padrão. É usado para outros | ||
// projetos montarem lógicas de tratamento de erro. | ||
// TODO: Reencontrar onde isso é usado e refatorar. | ||
pilhaEscoposExecucao.definirVariavel( | ||
'erro2', | ||
new FuncaoPadrao(0, function () { | ||
throw new Error('Essa função atira erro também. É usada para testes variados.'); | ||
}) | ||
); | ||
export function copia( | ||
interpretador: InterpretadorInterface, | ||
valor: string, | ||
inicio: number, | ||
fim: number | ||
): Promise<string> { | ||
return Promise.resolve(valor.substring(inicio, inicio + fim)); | ||
} | ||
|
||
pilhaEscoposExecucao.definirVariavel( | ||
'maiusc', | ||
new FuncaoPadrao(1, function (valor: any) { | ||
const valorResolvido = valor.hasOwnProperty('valor') ? valor.valor : valor; | ||
return String(valorResolvido).toUpperCase(); | ||
}) | ||
); | ||
export function maiusc( | ||
interpretador: InterpretadorInterface, | ||
valor: any | ||
): Promise<string> { | ||
const valorResolvido = valor.hasOwnProperty('valor') ? valor.valor : valor; | ||
return Promise.resolve(String(valorResolvido).toUpperCase()); | ||
} | ||
|
||
pilhaEscoposExecucao.definirVariavel( | ||
'minusc', | ||
new FuncaoPadrao(1, function (valor: string) { | ||
return valor.toLowerCase(); | ||
}) | ||
); | ||
export function minusc( | ||
interpretador: InterpretadorInterface, | ||
valor: string | ||
): Promise<string> { | ||
return Promise.resolve(valor.toLowerCase()); | ||
} | ||
|
||
pilhaEscoposExecucao.definirVariavel( | ||
'numpcarac', | ||
new FuncaoPadrao(1, function (valor: number) { | ||
return String(valor); | ||
}) | ||
); | ||
export function numpcarac( | ||
interpretador: InterpretadorInterface, | ||
valor: number | ||
): Promise<string> { | ||
return Promise.resolve(String(valor)); | ||
} | ||
|
||
pilhaEscoposExecucao.definirVariavel( | ||
'pos', | ||
new FuncaoPadrao(2, function (busca: string, valor: any) { | ||
const valorResolvido = valor.hasOwnProperty('valor') ? valor.valor : valor; | ||
return String(valorResolvido).indexOf(busca) + 1; | ||
}) | ||
); | ||
export function pos( | ||
interpretador: InterpretadorInterface, | ||
busca: string, | ||
valor: any | ||
): Promise<number> { | ||
const valorResolvido = valor.hasOwnProperty('valor') ? valor.valor : valor; | ||
return Promise.resolve(String(valorResolvido).indexOf(busca) + 1); | ||
} |
Oops, something went wrong.