@designliquido/delegua
Advanced tools
Comparing version 0.29.3 to 0.29.4
{ | ||
"name": "@designliquido/delegua", | ||
"version": "0.29.2", | ||
"version": "0.29.3", | ||
"description": "Linguagem de programação simples e moderna usando português estruturado, com suporte a múltiplos dialetos", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,2 +0,2 @@ | ||
import { Binario, FimPara, Logico } from '../../../construtos'; | ||
import { AcessoElementoMatriz, AtribuicaoPorIndicesMatriz, Binario, FimPara, Logico } from '../../../construtos'; | ||
import { EscrevaMesmaLinha, Escreva, Fazer, Leia, Const, Para } from '../../../declaracoes'; | ||
@@ -11,2 +11,4 @@ import { InterpretadorComDepuracao } from '../../interpretador-com-depuracao'; | ||
visitarDeclaracaoConst(declaracao: Const): Promise<any>; | ||
visitarExpressaoAcessoElementoMatriz(expressao: AcessoElementoMatriz): Promise<any>; | ||
visitarExpressaoAtribuicaoPorIndicesMatriz(expressao: AtribuicaoPorIndicesMatriz): Promise<any>; | ||
private avaliarArgumentosEscrevaVisuAlg; | ||
@@ -13,0 +15,0 @@ /** |
@@ -31,2 +31,3 @@ "use strict"; | ||
const interpretador_com_depuracao_1 = require("../../interpretador-com-depuracao"); | ||
const excecoes_1 = require("../../../excecoes"); | ||
const comum = __importStar(require("./comum")); | ||
@@ -46,2 +47,68 @@ /** | ||
} | ||
async visitarExpressaoAcessoElementoMatriz(expressao) { | ||
const promises = await Promise.all([ | ||
this.avaliar(expressao.entidadeChamada), | ||
this.avaliar(expressao.indicePrimario), | ||
this.avaliar(expressao.indiceSecundario), | ||
]); | ||
const variavelObjeto = promises[0]; | ||
const indicePrimario = promises[1]; | ||
const indiceSecundario = promises[2]; | ||
const objeto = variavelObjeto.hasOwnProperty('valor') ? variavelObjeto.valor : variavelObjeto; | ||
let valorIndicePrimario = indicePrimario.hasOwnProperty('valor') ? indicePrimario.valor : indicePrimario; | ||
let valorIndiceSecundario = indiceSecundario.hasOwnProperty('valor') ? indiceSecundario.valor : indiceSecundario; | ||
if (Array.isArray(objeto)) { | ||
if (!Number.isInteger(valorIndicePrimario) || !Number.isInteger(valorIndiceSecundario)) { | ||
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha)); | ||
} | ||
if (valorIndicePrimario < 0 && objeto.length !== 0) { | ||
while (valorIndicePrimario < 0) { | ||
valorIndicePrimario += objeto.length; | ||
} | ||
} | ||
if (valorIndiceSecundario < 0 && objeto.length !== 0) { | ||
while (valorIndiceSecundario < 0) { | ||
valorIndiceSecundario += objeto.length; | ||
} | ||
} | ||
if (valorIndicePrimario >= objeto.length || valorIndiceSecundario >= objeto.length) { | ||
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice do vetor fora do intervalo.', expressao.linha)); | ||
} | ||
return objeto[valorIndicePrimario][valorIndiceSecundario]; | ||
} | ||
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(expressao.entidadeChamada.valor, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha)); | ||
} | ||
async visitarExpressaoAtribuicaoPorIndicesMatriz(expressao) { | ||
const promises = await Promise.all([ | ||
this.avaliar(expressao.objeto), | ||
this.avaliar(expressao.indicePrimario), | ||
this.avaliar(expressao.indiceSecundario), | ||
this.avaliar(expressao.valor), | ||
]); | ||
let objeto = promises[0]; | ||
let indicePrimario = promises[1]; | ||
let indiceSecundario = promises[2]; | ||
const valor = promises[3]; | ||
objeto = objeto.hasOwnProperty('valor') ? objeto.valor : objeto; | ||
indicePrimario = indicePrimario.hasOwnProperty('valor') ? indicePrimario.valor : indicePrimario; | ||
indiceSecundario = indiceSecundario.hasOwnProperty('valor') ? indiceSecundario.valor : indiceSecundario; | ||
if (Array.isArray(objeto)) { | ||
if (indicePrimario < 0 && objeto.length !== 0) { | ||
while (indicePrimario < 0) { | ||
indicePrimario += objeto.length; | ||
} | ||
} | ||
if (indiceSecundario < 0 && objeto.length !== 0) { | ||
while (indiceSecundario < 0) { | ||
indiceSecundario += objeto.length; | ||
} | ||
} | ||
while (objeto.length < indicePrimario || objeto.length < indiceSecundario) { | ||
objeto.push(null); | ||
} | ||
objeto[indicePrimario][indiceSecundario] = valor; | ||
return Promise.resolve(); | ||
} | ||
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha)); | ||
} | ||
async avaliarArgumentosEscrevaVisuAlg(argumentos) { | ||
@@ -48,0 +115,0 @@ let formatoTexto = ''; |
{ | ||
"name": "@designliquido/delegua", | ||
"version": "0.29.3", | ||
"version": "0.29.4", | ||
"description": "Linguagem de programação simples e moderna usando português estruturado, com suporte a múltiplos dialetos", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
3134061
46294