@designliquido/delegua 1.11.1 → 1.13.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/analisador-documentario/index.d.ts +3 -0
- package/analisador-documentario/index.d.ts.map +1 -0
- package/analisador-documentario/index.js +83 -0
- package/analisador-documentario/index.js.map +1 -0
- package/avaliador-sintatico/avaliador-sintatico.d.ts.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.js +23 -10
- package/avaliador-sintatico/avaliador-sintatico.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js +36 -51
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js.map +1 -1
- package/bin/package.json +1 -1
- package/declaracoes/funcao.d.ts +2 -1
- package/declaracoes/funcao.d.ts.map +1 -1
- package/declaracoes/funcao.js +2 -1
- package/declaracoes/funcao.js.map +1 -1
- package/interfaces/documentario/documentario-analisado.d.ts +11 -0
- package/interfaces/documentario/documentario-analisado.d.ts.map +1 -0
- package/interfaces/documentario/documentario-analisado.js +3 -0
- package/interfaces/documentario/documentario-analisado.js.map +1 -0
- package/interfaces/documentario/index.d.ts +4 -0
- package/interfaces/documentario/index.d.ts.map +1 -0
- package/interfaces/documentario/index.js +20 -0
- package/interfaces/documentario/index.js.map +1 -0
- package/interfaces/documentario/parametro-doc.d.ts +6 -0
- package/interfaces/documentario/parametro-doc.d.ts.map +1 -0
- package/interfaces/documentario/parametro-doc.js +3 -0
- package/interfaces/documentario/parametro-doc.js.map +1 -0
- package/interfaces/documentario/retorna-doc.d.ts +5 -0
- package/interfaces/documentario/retorna-doc.d.ts.map +1 -0
- package/interfaces/documentario/retorna-doc.js +3 -0
- package/interfaces/documentario/retorna-doc.js.map +1 -0
- package/interpretador/interpretador-base.d.ts.map +1 -1
- package/interpretador/interpretador-base.js +2 -4
- package/interpretador/interpretador-base.js.map +1 -1
- package/interpretador/interpretador.d.ts.map +1 -1
- package/interpretador/interpretador.js +14 -4
- package/interpretador/interpretador.js.map +1 -1
- package/lexador/dialetos/lexador-pitugues.d.ts.map +1 -1
- package/lexador/dialetos/lexador-pitugues.js +18 -12
- package/lexador/dialetos/lexador-pitugues.js.map +1 -1
- package/package.json +1 -1
- package/umd/delegua.js +95 -82
package/umd/delegua.js
CHANGED
|
@@ -4343,13 +4343,26 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4343
4343
|
const simboloDoc = this.avancarEDevolverAnterior();
|
|
4344
4344
|
docTopLevel = new construtos_1.ComentarioComoConstruto(simboloDoc);
|
|
4345
4345
|
}
|
|
4346
|
-
if (
|
|
4347
|
-
this.verificarTipoSimboloAtual(delegua_2.default.FUNÇÃO))
|
|
4348
|
-
this.verificarTipoProximoSimbolo(delegua_2.default.
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4346
|
+
if (this.verificarTipoSimboloAtual(delegua_2.default.FUNCAO) ||
|
|
4347
|
+
this.verificarTipoSimboloAtual(delegua_2.default.FUNÇÃO)) {
|
|
4348
|
+
if (this.verificarTipoProximoSimbolo(delegua_2.default.DE)) {
|
|
4349
|
+
this.avancarEDevolverAnterior(); // `função`
|
|
4350
|
+
this.avancarEDevolverAnterior(); // `de`
|
|
4351
|
+
const simboloDecorador = this.consumir(delegua_2.default.IDENTIFICADOR, "Esperado 'decorador' após 'função de'.");
|
|
4352
|
+
if (simboloDecorador.lexema !== 'decorador') {
|
|
4353
|
+
throw this.erro(simboloDecorador, "Esperado 'decorador' após 'função de'.");
|
|
4354
|
+
}
|
|
4355
|
+
const declaracaoFuncao = (await this.funcao('funcao'));
|
|
4356
|
+
declaracaoFuncao.eFuncaoDeDecorador = true;
|
|
4357
|
+
declaracaoFuncao.documentacao = docTopLevel;
|
|
4358
|
+
return declaracaoFuncao;
|
|
4359
|
+
}
|
|
4360
|
+
if (this.verificarTipoProximoSimbolo(delegua_2.default.IDENTIFICADOR)) {
|
|
4361
|
+
this.avancarEDevolverAnterior();
|
|
4362
|
+
const declaracaoFuncao = (await this.funcao('funcao'));
|
|
4363
|
+
declaracaoFuncao.documentacao = docTopLevel;
|
|
4364
|
+
return declaracaoFuncao;
|
|
4365
|
+
}
|
|
4353
4366
|
}
|
|
4354
4367
|
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.CLASSE)) {
|
|
4355
4368
|
return await this.declaracaoDeClasse();
|
|
@@ -4414,7 +4427,7 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4414
4427
|
case delegua_2.default.COMENTARIO:
|
|
4415
4428
|
return this.declaracaoComentarioUmaLinha();
|
|
4416
4429
|
case delegua_2.default.DOCUMENTARIO: {
|
|
4417
|
-
const
|
|
4430
|
+
const simboloDocumentario = this.avancarEDevolverAnterior();
|
|
4418
4431
|
// Se o próximo token for uma declaração de função com identificador,
|
|
4419
4432
|
// anexa o documentário como documentação da função.
|
|
4420
4433
|
if ((this.verificarTipoSimboloAtual(delegua_2.default.FUNCAO) ||
|
|
@@ -4422,10 +4435,10 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4422
4435
|
this.verificarTipoProximoSimbolo(delegua_2.default.IDENTIFICADOR)) {
|
|
4423
4436
|
this.avancarEDevolverAnterior();
|
|
4424
4437
|
const declaracaoFuncao = (await this.funcao('funcao'));
|
|
4425
|
-
declaracaoFuncao.documentacao = new construtos_1.ComentarioComoConstruto(
|
|
4438
|
+
declaracaoFuncao.documentacao = new construtos_1.ComentarioComoConstruto(simboloDocumentario);
|
|
4426
4439
|
return declaracaoFuncao;
|
|
4427
4440
|
}
|
|
4428
|
-
return new declaracoes_1.Comentario(
|
|
4441
|
+
return new declaracoes_1.Comentario(simboloDocumentario.hashArquivo, simboloDocumentario.linha, simboloDocumentario.literal, false);
|
|
4429
4442
|
}
|
|
4430
4443
|
case delegua_2.default.CONSTANTE:
|
|
4431
4444
|
this.avancarEDevolverAnterior();
|
|
@@ -5841,7 +5854,8 @@ class AvaliadorSintaticoPitugues {
|
|
|
5841
5854
|
}
|
|
5842
5855
|
}
|
|
5843
5856
|
erro(simbolo, mensagemDeErro) {
|
|
5844
|
-
const
|
|
5857
|
+
const simboloParaErro = simbolo || this.simboloAnterior();
|
|
5858
|
+
const excecao = new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(simboloParaErro, mensagemDeErro);
|
|
5845
5859
|
this.erros.push(excecao);
|
|
5846
5860
|
return excecao;
|
|
5847
5861
|
}
|
|
@@ -5856,7 +5870,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
5856
5870
|
return this.simboloAtual().tipo === tipo;
|
|
5857
5871
|
}
|
|
5858
5872
|
verificarTipoProximoSimbolo(tipo) {
|
|
5859
|
-
if (this.
|
|
5873
|
+
if (this.atual + 1 >= this.simbolos.length)
|
|
5860
5874
|
return false;
|
|
5861
5875
|
return this.simbolos[this.atual + 1].tipo === tipo;
|
|
5862
5876
|
}
|
|
@@ -6226,7 +6240,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
6226
6240
|
while (this.verificarSeSimboloAtualEIgualA(pitugues_2.default.SE)) {
|
|
6227
6241
|
const operador = this.simbolos[this.atual - 1];
|
|
6228
6242
|
const expressaoOuCondicao = await this.seTernario();
|
|
6229
|
-
this.consumir(pitugues_2.default.SENAO, `Esperado 'senão' ou 'senao' após caminho positivo em se ternário. Atual:
|
|
6243
|
+
this.consumir(pitugues_2.default.SENAO, `Esperado 'senão' ou 'senao' após caminho positivo em se ternário. Atual:
|
|
6230
6244
|
${this.simbolos[this.atual].lexema}.`);
|
|
6231
6245
|
const expressaoSenao = await this.seTernario();
|
|
6232
6246
|
expressaoEntao = new construtos_1.SeTernario(this.hashArquivo, expressaoOuCondicao, expressaoEntao, operador, expressaoSenao);
|
|
@@ -6324,55 +6338,40 @@ class AvaliadorSintaticoPitugues {
|
|
|
6324
6338
|
let declaracoes = [];
|
|
6325
6339
|
let simboloAtual = this.simboloAtual();
|
|
6326
6340
|
const simboloAnterior = this.simboloAnterior();
|
|
6327
|
-
|
|
6328
|
-
|
|
6329
|
-
|
|
6330
|
-
//
|
|
6341
|
+
if (!simboloAtual) {
|
|
6342
|
+
throw this.erro(simboloAnterior, 'Esperado corpo do escopo após a declaração.');
|
|
6343
|
+
}
|
|
6344
|
+
// Declaração na mesma linha (ex: 'se verdadeiro: escreva("Oi")')
|
|
6331
6345
|
if (simboloAtual.linha === simboloAnterior.linha) {
|
|
6332
|
-
const
|
|
6333
|
-
if (
|
|
6334
|
-
|
|
6335
|
-
declaracoes = declaracoes.concat(declaracoesBloco);
|
|
6336
|
-
}
|
|
6337
|
-
else {
|
|
6338
|
-
declaracoes.push(declaracoesBloco);
|
|
6339
|
-
}
|
|
6340
|
-
}
|
|
6346
|
+
const retorno = await this.resolverDeclaracaoForaDeBloco();
|
|
6347
|
+
if (retorno !== null)
|
|
6348
|
+
declaracoes = declaracoes.concat(retorno);
|
|
6341
6349
|
}
|
|
6342
6350
|
else {
|
|
6343
|
-
//
|
|
6344
|
-
|
|
6345
|
-
|
|
6346
|
-
|
|
6347
|
-
|
|
6348
|
-
|
|
6349
|
-
|
|
6350
|
-
if (
|
|
6351
|
+
// Bloco de múltiplas linhas baseado em indentação
|
|
6352
|
+
let espacosAtual = this
|
|
6353
|
+
.localizacoes[simboloAtual.linha]
|
|
6354
|
+
.espacosIndentacao;
|
|
6355
|
+
const espacosAnterior = this
|
|
6356
|
+
.localizacoes[simboloAnterior.linha]
|
|
6357
|
+
.espacosIndentacao;
|
|
6358
|
+
if (espacosAtual <= espacosAnterior) {
|
|
6351
6359
|
throw this.erro(simboloAtual, `Indentação inconsistente na linha ${simboloAtual.linha}. ` +
|
|
6352
|
-
`Esperado: >= ${
|
|
6353
|
-
`Atual: ${
|
|
6354
|
-
}
|
|
6355
|
-
|
|
6356
|
-
//
|
|
6357
|
-
|
|
6358
|
-
|
|
6359
|
-
|
|
6360
|
-
|
|
6361
|
-
while (espacosIndentacaoLinhaAtual === espacosIndentacaoBloco) {
|
|
6362
|
-
const retornoDeclaracao = await this.resolverDeclaracaoForaDeBloco();
|
|
6363
|
-
if (retornoDeclaracao !== null) {
|
|
6364
|
-
if (Array.isArray(retornoDeclaracao)) {
|
|
6365
|
-
declaracoes = declaracoes.concat(retornoDeclaracao);
|
|
6366
|
-
}
|
|
6367
|
-
else {
|
|
6368
|
-
declaracoes.push(retornoDeclaracao);
|
|
6369
|
-
}
|
|
6370
|
-
}
|
|
6360
|
+
`Esperado: >= ${espacosAnterior}. ` +
|
|
6361
|
+
`Atual: ${espacosAtual}`);
|
|
6362
|
+
}
|
|
6363
|
+
const indentacaoBloco = espacosAtual;
|
|
6364
|
+
// Consome as declarações enquanto a indentação for estritamente igual à do bloco
|
|
6365
|
+
while (simboloAtual && espacosAtual === indentacaoBloco) {
|
|
6366
|
+
const retorno = await this.resolverDeclaracaoForaDeBloco();
|
|
6367
|
+
if (retorno !== null)
|
|
6368
|
+
declaracoes = declaracoes.concat(retorno);
|
|
6371
6369
|
simboloAtual = this.simboloAtual();
|
|
6372
|
-
if (
|
|
6373
|
-
|
|
6374
|
-
|
|
6375
|
-
|
|
6370
|
+
if (simboloAtual) {
|
|
6371
|
+
espacosAtual = this
|
|
6372
|
+
.localizacoes[simboloAtual.linha]
|
|
6373
|
+
.espacosIndentacao;
|
|
6374
|
+
}
|
|
6376
6375
|
}
|
|
6377
6376
|
}
|
|
6378
6377
|
this.pilhaEscopos.removerUltimo();
|
|
@@ -6848,11 +6847,10 @@ class AvaliadorSintaticoPitugues {
|
|
|
6848
6847
|
*/
|
|
6849
6848
|
async resolverDeclaracaoForaDeBloco() {
|
|
6850
6849
|
try {
|
|
6851
|
-
if (
|
|
6852
|
-
this.verificarTipoSimboloAtual(pitugues_2.default.FUNÇÃO))
|
|
6853
|
-
this.verificarTipoProximoSimbolo(pitugues_2.default.IDENTIFICADOR)) {
|
|
6850
|
+
if (this.verificarTipoSimboloAtual(pitugues_2.default.FUNCAO) ||
|
|
6851
|
+
this.verificarTipoSimboloAtual(pitugues_2.default.FUNÇÃO)) {
|
|
6854
6852
|
this.avancarEDevolverAnterior();
|
|
6855
|
-
return await this.funcao('
|
|
6853
|
+
return await this.funcao('da função');
|
|
6856
6854
|
}
|
|
6857
6855
|
if (this.verificarSeSimboloAtualEIgualA(pitugues_2.default.CLASSE))
|
|
6858
6856
|
return await this.declaracaoDeClasse();
|
|
@@ -14172,7 +14170,7 @@ const geracao_identificadores_1 = require("../geracao-identificadores");
|
|
|
14172
14170
|
* Uma declaração de função.
|
|
14173
14171
|
*/
|
|
14174
14172
|
class FuncaoDeclaracao extends declaracao_1.Declaracao {
|
|
14175
|
-
constructor(simbolo, funcao, tipoRetorno = 'qualquer', decoradores = [], acesso = 'publico', estatico = false, abstrato = false, eObtenedor = false, eDefinidor = false) {
|
|
14173
|
+
constructor(simbolo, funcao, tipoRetorno = 'qualquer', decoradores = [], acesso = 'publico', estatico = false, abstrato = false, eObtenedor = false, eDefinidor = false, eFuncaoDeDecorador = false) {
|
|
14176
14174
|
super(Number(simbolo.linha), simbolo.hashArquivo);
|
|
14177
14175
|
this.id = (0, geracao_identificadores_1.uuidv4)();
|
|
14178
14176
|
this.simbolo = simbolo;
|
|
@@ -14184,6 +14182,7 @@ class FuncaoDeclaracao extends declaracao_1.Declaracao {
|
|
|
14184
14182
|
this.abstrato = abstrato;
|
|
14185
14183
|
this.eObtenedor = eObtenedor;
|
|
14186
14184
|
this.eDefinidor = eDefinidor;
|
|
14185
|
+
this.eFuncaoDeDecorador = eFuncaoDeDecorador;
|
|
14187
14186
|
}
|
|
14188
14187
|
async aceitar(visitante) {
|
|
14189
14188
|
return await visitante.visitarDeclaracaoDefinicaoFuncao(this);
|
|
@@ -20247,14 +20246,12 @@ class InterpretadorBase {
|
|
|
20247
20246
|
objeto[expressao.nome.lexema] = valor;
|
|
20248
20247
|
}
|
|
20249
20248
|
}
|
|
20250
|
-
visitarDeclaracaoDefinicaoFuncao(declaracao) {
|
|
20249
|
+
async visitarDeclaracaoDefinicaoFuncao(declaracao) {
|
|
20251
20250
|
const funcao = new estruturas_1.DeleguaFuncao(declaracao.simbolo.lexema, declaracao.funcao);
|
|
20252
20251
|
funcao.documentacao = declaracao.documentacao;
|
|
20253
20252
|
this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, funcao);
|
|
20254
20253
|
this.pilhaEscoposExecucao.registrarReferenciaFuncao(declaracao.id, funcao);
|
|
20255
|
-
return
|
|
20256
|
-
declaracao: funcao,
|
|
20257
|
-
});
|
|
20254
|
+
return { declaracao: funcao };
|
|
20258
20255
|
}
|
|
20259
20256
|
/**
|
|
20260
20257
|
* Executa uma declaração de classe.
|
|
@@ -21160,15 +21157,25 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
21160
21157
|
async visitarDeclaracaoAjuda(declaracao) {
|
|
21161
21158
|
return Promise.resolve((0, comum_1.pontoEntradaAjuda)(declaracao.funcao, declaracao.elemento));
|
|
21162
21159
|
}
|
|
21163
|
-
visitarDeclaracaoDefinicaoFuncao(declaracao) {
|
|
21164
|
-
|
|
21160
|
+
async visitarDeclaracaoDefinicaoFuncao(declaracao) {
|
|
21161
|
+
var _a, _b;
|
|
21162
|
+
let funcao = new estruturas_1.DeleguaFuncao(declaracao.simbolo.lexema, declaracao.funcao);
|
|
21165
21163
|
funcao.documentacao = declaracao.documentacao;
|
|
21164
|
+
if (declaracao.decoradores && declaracao.decoradores.length > 0) {
|
|
21165
|
+
for (const decorador of [...declaracao.decoradores].reverse()) {
|
|
21166
|
+
const nomeDecorador = decorador.nome.slice(1);
|
|
21167
|
+
const variavelDecoradora = this.pilhaEscoposExecucao.obterVariavelPorNome(nomeDecorador);
|
|
21168
|
+
const funcaoDecoradora = variavelDecoradora.valor;
|
|
21169
|
+
const resultado = await funcaoDecoradora.chamar(this, [{ nome: null, valor: funcao }]);
|
|
21170
|
+
funcao = this.resolverValorRecursivo(resultado);
|
|
21171
|
+
}
|
|
21172
|
+
}
|
|
21166
21173
|
// TODO: Depreciar essa abordagem a favor do uso por referências?
|
|
21167
21174
|
this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, funcao);
|
|
21168
21175
|
this.pilhaEscoposExecucao.registrarReferenciaFuncao(declaracao.id, funcao);
|
|
21169
21176
|
return Promise.resolve({
|
|
21170
|
-
tipo: `função<${funcao.declaracao.tipo || 'qualquer'}>`,
|
|
21171
|
-
tipoExplicito: funcao.declaracao.tipoExplicito,
|
|
21177
|
+
tipo: `função<${((_a = funcao.declaracao) === null || _a === void 0 ? void 0 : _a.tipo) || 'qualquer'}>`,
|
|
21178
|
+
tipoExplicito: (_b = funcao.declaracao) === null || _b === void 0 ? void 0 : _b.tipoExplicito,
|
|
21172
21179
|
declaracao: funcao,
|
|
21173
21180
|
});
|
|
21174
21181
|
}
|
|
@@ -23465,25 +23472,26 @@ class LexadorPitugues {
|
|
|
23465
23472
|
this.simbolos.push(new simbolo_1.Simbolo(tipoSimbolo, textoCompleto, valor, linhaPrimeiroCaracter + 1, this.hashArquivo));
|
|
23466
23473
|
}
|
|
23467
23474
|
analisarNumero() {
|
|
23468
|
-
const
|
|
23469
|
-
while (this.
|
|
23475
|
+
const linhaInicial = this.linha;
|
|
23476
|
+
while (this.linha === linhaInicial &&
|
|
23477
|
+
this.eDigito(this.simboloAtual()))
|
|
23470
23478
|
this.avancar();
|
|
23471
|
-
|
|
23472
|
-
|
|
23479
|
+
const temPonto = this.simboloAtual() === '.';
|
|
23480
|
+
const proximoEhDigito = this.eDigito(this.proximoSimbolo());
|
|
23481
|
+
if (this.linha === linhaInicial && temPonto && proximoEhDigito) {
|
|
23473
23482
|
this.avancar();
|
|
23474
|
-
while (this.
|
|
23483
|
+
while (this.linha === linhaInicial &&
|
|
23484
|
+
this.eDigito(this.simboloAtual()))
|
|
23475
23485
|
this.avancar();
|
|
23476
|
-
}
|
|
23477
23486
|
}
|
|
23478
23487
|
let numeroCompleto;
|
|
23479
|
-
if (
|
|
23480
|
-
|
|
23481
|
-
numeroCompleto = linhaNumero.substring(this.inicioSimbolo, linhaNumero.length);
|
|
23488
|
+
if (linhaInicial < this.linha) {
|
|
23489
|
+
numeroCompleto = this.codigo[linhaInicial].substring(this.inicioSimbolo, this.codigo[linhaInicial].length);
|
|
23482
23490
|
}
|
|
23483
23491
|
else {
|
|
23484
23492
|
numeroCompleto = this.codigo[this.linha].substring(this.inicioSimbolo, this.atual);
|
|
23485
23493
|
}
|
|
23486
|
-
this.simbolos.push(new simbolo_1.Simbolo(pitugues_2.default.NUMERO, numeroCompleto, parseFloat(numeroCompleto),
|
|
23494
|
+
this.simbolos.push(new simbolo_1.Simbolo(pitugues_2.default.NUMERO, numeroCompleto, parseFloat(numeroCompleto), linhaInicial + 1, this.hashArquivo));
|
|
23487
23495
|
}
|
|
23488
23496
|
identificarPalavraChave() {
|
|
23489
23497
|
const linhaPrimeiroCaracter = this.linha;
|
|
@@ -23587,8 +23595,13 @@ class LexadorPitugues {
|
|
|
23587
23595
|
this.avancar();
|
|
23588
23596
|
break;
|
|
23589
23597
|
case '.':
|
|
23590
|
-
this.
|
|
23591
|
-
|
|
23598
|
+
if (this.eDigito(this.proximoSimbolo())) {
|
|
23599
|
+
this.analisarNumero();
|
|
23600
|
+
}
|
|
23601
|
+
else {
|
|
23602
|
+
this.adicionarSimbolo(pitugues_2.default.PONTO);
|
|
23603
|
+
this.avancar();
|
|
23604
|
+
}
|
|
23592
23605
|
break;
|
|
23593
23606
|
case '-':
|
|
23594
23607
|
this.avancar();
|