@designliquido/delegua 1.23.4 → 1.23.5
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-base.d.ts +3 -0
- package/avaliador-sintatico/avaliador-sintatico-base.d.ts.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico-base.js +16 -5
- package/avaliador-sintatico/avaliador-sintatico-base.js.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.d.ts +2 -0
- package/avaliador-sintatico/avaliador-sintatico.d.ts.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.js +7 -9
- package/avaliador-sintatico/avaliador-sintatico.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts +8 -5
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js +44 -11
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js.map +1 -1
- package/bin/package.json +1 -1
- package/interpretador/depuracao/comum.js +1 -1
- package/interpretador/depuracao/comum.js.map +1 -1
- package/interpretador/dialetos/pitugues/interpretador-pitugues.d.ts +2 -2
- package/interpretador/dialetos/pitugues/interpretador-pitugues.d.ts.map +1 -1
- package/interpretador/dialetos/pitugues/interpretador-pitugues.js +15 -25
- package/interpretador/dialetos/pitugues/interpretador-pitugues.js.map +1 -1
- package/interpretador/interpretador-base.d.ts +5 -1
- package/interpretador/interpretador-base.d.ts.map +1 -1
- package/interpretador/interpretador-base.js +40 -18
- package/interpretador/interpretador-base.js.map +1 -1
- package/interpretador/interpretador.d.ts +2 -7
- package/interpretador/interpretador.d.ts.map +1 -1
- package/interpretador/interpretador.js +11 -47
- package/interpretador/interpretador.js.map +1 -1
- package/lexador/lexador.d.ts +15 -13
- package/lexador/lexador.d.ts.map +1 -1
- package/lexador/lexador.js +52 -17
- package/lexador/lexador.js.map +1 -1
- package/package.json +1 -1
- package/umd/delegua.js +171 -108
package/umd/delegua.js
CHANGED
|
@@ -2245,15 +2245,26 @@ class AvaliadorSintaticoBase {
|
|
|
2245
2245
|
declaracaoDeVariaveis() {
|
|
2246
2246
|
throw new Error('Método não implementado.');
|
|
2247
2247
|
}
|
|
2248
|
-
|
|
2249
|
-
|
|
2248
|
+
validacaoComparacao(operador, esquerda, direita) { }
|
|
2249
|
+
criarConstrutoComparacao(esquerda, operador, direita) {
|
|
2250
|
+
return new construtos_1.Binario(this.hashArquivo, esquerda, operador, direita);
|
|
2251
|
+
}
|
|
2252
|
+
async logicaComumComparacao(metodoProximoNivel) {
|
|
2253
|
+
let expressao = await metodoProximoNivel();
|
|
2250
2254
|
while (this.verificarSeSimboloAtualEIgualA(comum_1.default.MAIOR, comum_1.default.MAIOR_IGUAL, comum_1.default.MENOR, comum_1.default.MENOR_IGUAL)) {
|
|
2251
|
-
const operador = this.
|
|
2252
|
-
|
|
2253
|
-
|
|
2255
|
+
const operador = this.simboloAnterior
|
|
2256
|
+
? this.simboloAnterior()
|
|
2257
|
+
: this.simbolos[this.atual - 1];
|
|
2258
|
+
const esquerda = expressao;
|
|
2259
|
+
const direita = await metodoProximoNivel();
|
|
2260
|
+
this.validacaoComparacao(operador, esquerda, direita);
|
|
2261
|
+
expressao = this.criarConstrutoComparacao(esquerda, operador, direita);
|
|
2254
2262
|
}
|
|
2255
2263
|
return expressao;
|
|
2256
2264
|
}
|
|
2265
|
+
async comparar() {
|
|
2266
|
+
return await this.logicaComumComparacao(() => this.adicaoOuSubtracao());
|
|
2267
|
+
}
|
|
2257
2268
|
async comparacaoIgualdade() {
|
|
2258
2269
|
let expressao = await this.comparar();
|
|
2259
2270
|
while (this.verificarSeSimboloAtualEIgualA(comum_1.default.DIFERENTE, comum_1.default.IGUAL, comum_1.default.IGUAL_IGUAL)) {
|
|
@@ -3520,16 +3531,14 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
3520
3531
|
}
|
|
3521
3532
|
return expressao;
|
|
3522
3533
|
}
|
|
3534
|
+
validacaoComparacao(operador, esquerda, direita) {
|
|
3535
|
+
this.verificarOperandosComparacao(operador, esquerda, direita);
|
|
3536
|
+
}
|
|
3537
|
+
criarConstrutoComparacao(esquerda, operador, direita) {
|
|
3538
|
+
return new construtos_1.Binario(this.hashArquivo, esquerda, operador, direita);
|
|
3539
|
+
}
|
|
3523
3540
|
async comparar() {
|
|
3524
|
-
|
|
3525
|
-
while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.MAIOR, delegua_2.default.MAIOR_IGUAL, delegua_2.default.MENOR, delegua_2.default.MENOR_IGUAL)) {
|
|
3526
|
-
const operador = this.simbolos[this.atual - 1];
|
|
3527
|
-
const esquerda = expressao;
|
|
3528
|
-
const direito = await this.bitOu();
|
|
3529
|
-
this.verificarOperandosComparacao(operador, esquerda, direito);
|
|
3530
|
-
expressao = new construtos_1.Binario(this.hashArquivo, esquerda, operador, direito);
|
|
3531
|
-
}
|
|
3532
|
-
return expressao;
|
|
3541
|
+
return await this.logicaComumComparacao(() => this.bitOu());
|
|
3533
3542
|
}
|
|
3534
3543
|
async comparacaoIgualdade() {
|
|
3535
3544
|
let expressao = await this.comparar();
|
|
@@ -6334,6 +6343,7 @@ const primitivas_numero_1 = __importDefault(require("../../bibliotecas/primitiva
|
|
|
6334
6343
|
const primitivas_texto_1 = __importDefault(require("../../bibliotecas/primitivas-texto"));
|
|
6335
6344
|
const primitivas_vetor_1 = __importDefault(require("../../bibliotecas/primitivas-vetor"));
|
|
6336
6345
|
const primitivas_tupla_1 = __importDefault(require("../../bibliotecas/dialetos/pitugues/primitivas-tupla"));
|
|
6346
|
+
const avaliador_sintatico_base_1 = require("../avaliador-sintatico-base");
|
|
6337
6347
|
/**
|
|
6338
6348
|
* O avaliador sintático (_Parser_) é responsável por transformar os símbolos do Lexador em estruturas de alto nível.
|
|
6339
6349
|
* Essas estruturas de alto nível são as partes que executam lógica de programação de fato.
|
|
@@ -6342,8 +6352,9 @@ const primitivas_tupla_1 = __importDefault(require("../../bibliotecas/dialetos/p
|
|
|
6342
6352
|
* A grande diferença entre este avaliador e os demais é a forma como são entendidos os blocos de escopo.
|
|
6343
6353
|
* Este avaliador espera uma estrutura de pragmas, que explica quantos espaços há na frente de cada linha.
|
|
6344
6354
|
*/
|
|
6345
|
-
class AvaliadorSintaticoPitugues {
|
|
6355
|
+
class AvaliadorSintaticoPitugues extends avaliador_sintatico_base_1.AvaliadorSintaticoBase {
|
|
6346
6356
|
constructor(performance = false) {
|
|
6357
|
+
super();
|
|
6347
6358
|
this.atual = 0;
|
|
6348
6359
|
this.blocos = 0;
|
|
6349
6360
|
this.performance = performance;
|
|
@@ -7108,14 +7119,42 @@ class AvaliadorSintaticoPitugues {
|
|
|
7108
7119
|
}
|
|
7109
7120
|
return expressao;
|
|
7110
7121
|
}
|
|
7111
|
-
|
|
7112
|
-
|
|
7113
|
-
|
|
7114
|
-
|
|
7115
|
-
|
|
7116
|
-
|
|
7122
|
+
eOperadorDeComparacao(tipo) {
|
|
7123
|
+
return [
|
|
7124
|
+
pitugues_2.default.MAIOR,
|
|
7125
|
+
pitugues_2.default.MAIOR_IGUAL,
|
|
7126
|
+
pitugues_2.default.MENOR,
|
|
7127
|
+
pitugues_2.default.MENOR_IGUAL
|
|
7128
|
+
].includes(tipo);
|
|
7129
|
+
}
|
|
7130
|
+
criarConstrutoComparacao(esquerda, operador, direita) {
|
|
7131
|
+
let operandoCentral = null;
|
|
7132
|
+
// Lógica de desugaring para comparações encadeadas (ex: 1 < x < 10)
|
|
7133
|
+
if (esquerda instanceof construtos_1.Binario &&
|
|
7134
|
+
this.eOperadorDeComparacao(esquerda.operador.tipo)) {
|
|
7135
|
+
operandoCentral = esquerda.direita;
|
|
7136
|
+
}
|
|
7137
|
+
else if (esquerda instanceof construtos_1.Logico &&
|
|
7138
|
+
esquerda.direita instanceof construtos_1.Binario &&
|
|
7139
|
+
this.eOperadorDeComparacao(esquerda.direita.operador.tipo)) {
|
|
7140
|
+
operandoCentral = esquerda.direita.direita;
|
|
7141
|
+
}
|
|
7142
|
+
if (operandoCentral !== null) {
|
|
7143
|
+
const operadorE = {
|
|
7144
|
+
tipo: pitugues_2.default.E,
|
|
7145
|
+
lexema: 'e',
|
|
7146
|
+
literal: null,
|
|
7147
|
+
linha: operador.linha,
|
|
7148
|
+
hashArquivo: this.hashArquivo
|
|
7149
|
+
};
|
|
7150
|
+
const novaComparacaoDireita = new construtos_1.Binario(this.hashArquivo, operandoCentral, operador, direita);
|
|
7151
|
+
return new construtos_1.Logico(this.hashArquivo, esquerda, operadorE, novaComparacaoDireita);
|
|
7117
7152
|
}
|
|
7118
|
-
|
|
7153
|
+
// Se não for encadeada, cria o Binário normal
|
|
7154
|
+
return new construtos_1.Binario(this.hashArquivo, esquerda, operador, direita);
|
|
7155
|
+
}
|
|
7156
|
+
async comparar() {
|
|
7157
|
+
return await this.logicaComumComparacao(() => this.bitOu());
|
|
7119
7158
|
}
|
|
7120
7159
|
async comparacaoIgualdade() {
|
|
7121
7160
|
let expressao = await this.comparar();
|
|
@@ -7258,7 +7297,10 @@ class AvaliadorSintaticoPitugues {
|
|
|
7258
7297
|
}
|
|
7259
7298
|
return expressao;
|
|
7260
7299
|
}
|
|
7261
|
-
async declaracaoEscreva(
|
|
7300
|
+
async declaracaoEscreva() {
|
|
7301
|
+
const simboloEscreva = this.simboloAnterior
|
|
7302
|
+
? this.simboloAnterior()
|
|
7303
|
+
: this.simbolos[this.atual - 1];
|
|
7262
7304
|
this.consumir(pitugues_2.default.PARENTESE_ESQUERDO, "Esperado '(' antes dos valores em escreva.");
|
|
7263
7305
|
const argumentos = [];
|
|
7264
7306
|
do {
|
|
@@ -7949,8 +7991,8 @@ class AvaliadorSintaticoPitugues {
|
|
|
7949
7991
|
return this.declaracaoEscolha();
|
|
7950
7992
|
case pitugues_2.default.IMPRIMA:
|
|
7951
7993
|
case pitugues_2.default.ESCREVA:
|
|
7952
|
-
|
|
7953
|
-
return this.declaracaoEscreva(
|
|
7994
|
+
this.avancarEDevolverAnterior();
|
|
7995
|
+
return this.declaracaoEscreva();
|
|
7954
7996
|
case pitugues_2.default.FALHAR:
|
|
7955
7997
|
this.avancarEDevolverAnterior();
|
|
7956
7998
|
return await this.declaracaoFalhar();
|
|
@@ -8168,7 +8210,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
8168
8210
|
}
|
|
8169
8211
|
exports.AvaliadorSintaticoPitugues = AvaliadorSintaticoPitugues;
|
|
8170
8212
|
|
|
8171
|
-
},{"../../bibliotecas/dialetos/pitugues/primitivas-tupla":30,"../../bibliotecas/primitivas-dicionario":31,"../../bibliotecas/primitivas-numero":32,"../../bibliotecas/primitivas-texto":33,"../../bibliotecas/primitivas-vetor":34,"../../construtos":67,"../../declaracoes":116,"../../inferenciador":146,"../../informacao-elemento-sintatico":147,"../../lexador":238,"../../lexador/micro-lexador-pitugues":243,"../../tipos-de-dados/dialetos/pitugues":249,"../../tipos-de-simbolos/pitugues":257,"../comum":12,"../erro-avaliador-sintatico":21,"../informacao-escopo":23,"../pilha-escopos":27,"./micro-avaliador-sintatico-pitugues":19,"browser-process-hrtime":446}],15:[function(require,module,exports){
|
|
8213
|
+
},{"../../bibliotecas/dialetos/pitugues/primitivas-tupla":30,"../../bibliotecas/primitivas-dicionario":31,"../../bibliotecas/primitivas-numero":32,"../../bibliotecas/primitivas-texto":33,"../../bibliotecas/primitivas-vetor":34,"../../construtos":67,"../../declaracoes":116,"../../inferenciador":146,"../../informacao-elemento-sintatico":147,"../../lexador":238,"../../lexador/micro-lexador-pitugues":243,"../../tipos-de-dados/dialetos/pitugues":249,"../../tipos-de-simbolos/pitugues":257,"../avaliador-sintatico-base":10,"../comum":12,"../erro-avaliador-sintatico":21,"../informacao-escopo":23,"../pilha-escopos":27,"./micro-avaliador-sintatico-pitugues":19,"browser-process-hrtime":446}],15:[function(require,module,exports){
|
|
8172
8214
|
"use strict";
|
|
8173
8215
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8174
8216
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -22290,7 +22332,7 @@ class InterpretadorBase {
|
|
|
22290
22332
|
* @param esquerda O operando esquerdo.
|
|
22291
22333
|
* @returns Se ambos os operandos são números ou não.
|
|
22292
22334
|
*/
|
|
22293
|
-
verificarOperandosNumeros(operador,
|
|
22335
|
+
verificarOperandosNumeros(operador, esquerda, direita) {
|
|
22294
22336
|
const tipoDireita = direita.tipo
|
|
22295
22337
|
? direita.tipo
|
|
22296
22338
|
: typeof direita === primitivos_1.default.NUMERO
|
|
@@ -22368,23 +22410,33 @@ class InterpretadorBase {
|
|
|
22368
22410
|
const resultadoExponenciacao = Math.pow(valorEsquerdo, valorDireito);
|
|
22369
22411
|
return resultadoExponenciacao;
|
|
22370
22412
|
case delegua_1.default.MAIOR:
|
|
22371
|
-
if (
|
|
22372
|
-
|
|
22413
|
+
if (typeof valorEsquerdo === 'string' &&
|
|
22414
|
+
typeof valorDireito === 'string') {
|
|
22373
22415
|
return valorEsquerdo > valorDireito;
|
|
22374
22416
|
}
|
|
22375
|
-
|
|
22417
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
22418
|
+
return Number(valorEsquerdo) > Number(valorDireito);
|
|
22376
22419
|
case delegua_1.default.MAIOR_IGUAL:
|
|
22420
|
+
if (typeof valorEsquerdo === 'string' &&
|
|
22421
|
+
typeof valorDireito === 'string') {
|
|
22422
|
+
return valorEsquerdo >= valorDireito;
|
|
22423
|
+
}
|
|
22377
22424
|
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
22378
|
-
return valorEsquerdo >= valorDireito;
|
|
22425
|
+
return Number(valorEsquerdo) >= Number(valorDireito);
|
|
22379
22426
|
case delegua_1.default.MENOR:
|
|
22380
|
-
if (
|
|
22381
|
-
|
|
22427
|
+
if (typeof valorEsquerdo === 'string' &&
|
|
22428
|
+
typeof valorDireito === 'string') {
|
|
22382
22429
|
return valorEsquerdo < valorDireito;
|
|
22383
22430
|
}
|
|
22384
|
-
|
|
22431
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
22432
|
+
return Number(valorEsquerdo) < Number(valorDireito);
|
|
22385
22433
|
case delegua_1.default.MENOR_IGUAL:
|
|
22434
|
+
if (typeof valorEsquerdo === 'string' &&
|
|
22435
|
+
typeof valorDireito === 'string') {
|
|
22436
|
+
return valorEsquerdo <= valorDireito;
|
|
22437
|
+
}
|
|
22386
22438
|
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
22387
|
-
return valorEsquerdo <= valorDireito;
|
|
22439
|
+
return Number(valorEsquerdo) <= Number(valorDireito);
|
|
22388
22440
|
case delegua_1.default.SUBTRACAO:
|
|
22389
22441
|
case delegua_1.default.MENOS_IGUAL:
|
|
22390
22442
|
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
@@ -22714,13 +22766,29 @@ class InterpretadorBase {
|
|
|
22714
22766
|
});
|
|
22715
22767
|
}
|
|
22716
22768
|
}
|
|
22769
|
+
/** Gancho para linguagens definirem lógica de escopo (Pituguês LEGB) ou de memória (Delégua) */
|
|
22770
|
+
atribuirVariavel(alvoVariavel, valorResolvido, indice) {
|
|
22771
|
+
this.pilhaEscoposExecucao.atribuirVariavel(alvoVariavel.simbolo, valorResolvido, indice);
|
|
22772
|
+
}
|
|
22773
|
+
/** Gancho para linguagens definirem como acessar propriedades de objetos */
|
|
22774
|
+
async definirPropriedadeObjeto(objeto, simbolo, valor) {
|
|
22775
|
+
if (objeto instanceof estruturas_1.ObjetoDeleguaClasse) {
|
|
22776
|
+
await objeto.definir(simbolo, valor, this);
|
|
22777
|
+
}
|
|
22778
|
+
else if (objeto !== null && objeto !== undefined) {
|
|
22779
|
+
objeto[simbolo.lexema] = valor;
|
|
22780
|
+
}
|
|
22781
|
+
}
|
|
22717
22782
|
/**
|
|
22718
22783
|
* Execução de uma expressão de atribuição.
|
|
22719
22784
|
* @param expressao A expressão.
|
|
22720
22785
|
* @returns O valor atribuído.
|
|
22721
22786
|
*/
|
|
22722
22787
|
async visitarExpressaoDeAtribuicao(expressao) {
|
|
22723
|
-
|
|
22788
|
+
let valor = await this.avaliar(expressao.valor);
|
|
22789
|
+
if (valor && valor.hasOwnProperty('valorRetornado')) {
|
|
22790
|
+
valor = valor.valorRetornado;
|
|
22791
|
+
}
|
|
22724
22792
|
const valorResolvido = this.resolverValor(valor);
|
|
22725
22793
|
let indice = null;
|
|
22726
22794
|
if (expressao.indice) {
|
|
@@ -22728,22 +22796,18 @@ class InterpretadorBase {
|
|
|
22728
22796
|
}
|
|
22729
22797
|
switch (expressao.alvo.constructor) {
|
|
22730
22798
|
case construtos_1.AcessoMetodoOuPropriedade:
|
|
22731
|
-
// Nunca será método aqui: apenas propriedade.
|
|
22732
22799
|
const alvoPropriedade = expressao.alvo;
|
|
22733
22800
|
const variavelObjeto = await this.avaliar(alvoPropriedade.objeto);
|
|
22734
22801
|
const objeto = this.resolverValor(variavelObjeto);
|
|
22735
|
-
const
|
|
22736
|
-
|
|
22737
|
-
const objetoDeleguaClasse = objeto;
|
|
22738
|
-
await objetoDeleguaClasse.definir(alvoPropriedade.simbolo, valor, this);
|
|
22739
|
-
}
|
|
22802
|
+
const valorProp = await this.avaliar(expressao.valor);
|
|
22803
|
+
await this.definirPropriedadeObjeto(objeto, alvoPropriedade.simbolo, valorProp);
|
|
22740
22804
|
break;
|
|
22741
22805
|
case construtos_1.Variavel:
|
|
22742
22806
|
const alvoVariavel = expressao.alvo;
|
|
22743
|
-
this.
|
|
22807
|
+
this.atribuirVariavel(alvoVariavel, valorResolvido, indice);
|
|
22744
22808
|
break;
|
|
22745
22809
|
default:
|
|
22746
|
-
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloOperador,
|
|
22810
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloOperador, "Alvo da atribuição inválido. O lado esquerdo de uma atribuição deve ser uma variável, propriedade ou índice.");
|
|
22747
22811
|
}
|
|
22748
22812
|
return valorResolvido;
|
|
22749
22813
|
}
|
|
@@ -24037,6 +24101,17 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
24037
24101
|
pontoInicializacaoBibliotecasGlobais() {
|
|
24038
24102
|
(0, comum_1.carregarBibliotecasGlobais)(this.pilhaEscoposExecucao);
|
|
24039
24103
|
}
|
|
24104
|
+
atribuirVariavel(alvoVariavel, valorResolvido, indice) {
|
|
24105
|
+
const variavelResolvida = this.pilhaEscoposExecucao.obterValorVariavel(alvoVariavel.simbolo);
|
|
24106
|
+
if (variavelResolvida.valor instanceof estruturas_1.ReferenciaMontao) {
|
|
24107
|
+
const referenciaMontao = this.montao.obterReferencia(this.hashArquivoDeclaracaoAtual, this.linhaDeclaracaoAtual, variavelResolvida.valor.endereco);
|
|
24108
|
+
referenciaMontao[indice] = valorResolvido;
|
|
24109
|
+
}
|
|
24110
|
+
else {
|
|
24111
|
+
// Se não for montão, usa o comportamento padrão da Pilha
|
|
24112
|
+
super.atribuirVariavel(alvoVariavel, valorResolvido, indice);
|
|
24113
|
+
}
|
|
24114
|
+
}
|
|
24040
24115
|
async avaliarArgumentosEscreva(argumentos) {
|
|
24041
24116
|
if (this.constructor !== Interpretador) {
|
|
24042
24117
|
return await super.avaliarArgumentosEscreva(argumentos);
|
|
@@ -25215,53 +25290,6 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
25215
25290
|
async visitarExpressaoComentario(expressao) {
|
|
25216
25291
|
return Promise.resolve();
|
|
25217
25292
|
}
|
|
25218
|
-
/**
|
|
25219
|
-
* Execução de uma expressão de atribuição.
|
|
25220
|
-
* @param expressao A expressão.
|
|
25221
|
-
* @returns O valor atribuído.
|
|
25222
|
-
*/
|
|
25223
|
-
async visitarExpressaoDeAtribuicao(expressao) {
|
|
25224
|
-
let valor = await this.avaliar(expressao.valor);
|
|
25225
|
-
if (valor && valor.hasOwnProperty('valorRetornado')) {
|
|
25226
|
-
valor = valor.valorRetornado;
|
|
25227
|
-
}
|
|
25228
|
-
const valorResolvido = this.resolverValor(valor);
|
|
25229
|
-
let indice = null;
|
|
25230
|
-
if (expressao.indice) {
|
|
25231
|
-
indice = this.resolverValor(await this.avaliar(expressao.indice));
|
|
25232
|
-
}
|
|
25233
|
-
switch (expressao.alvo.constructor) {
|
|
25234
|
-
case construtos_1.Variavel:
|
|
25235
|
-
const alvoVariavel = expressao.alvo;
|
|
25236
|
-
const variavelResolvida = this.pilhaEscoposExecucao.obterValorVariavel(alvoVariavel.simbolo);
|
|
25237
|
-
if (variavelResolvida.valor instanceof estruturas_1.ReferenciaMontao) {
|
|
25238
|
-
const referenciaMontao = this.montao.obterReferencia(this.hashArquivoDeclaracaoAtual, this.linhaDeclaracaoAtual, variavelResolvida.valor.endereco);
|
|
25239
|
-
referenciaMontao[indice] = valorResolvido;
|
|
25240
|
-
}
|
|
25241
|
-
else {
|
|
25242
|
-
this.pilhaEscoposExecucao.atribuirVariavel(alvoVariavel.simbolo, valorResolvido, indice);
|
|
25243
|
-
}
|
|
25244
|
-
break;
|
|
25245
|
-
case construtos_1.AcessoMetodoOuPropriedade:
|
|
25246
|
-
// Nunca será método aqui: apenas propriedade.
|
|
25247
|
-
const alvoPropriedade = expressao.alvo;
|
|
25248
|
-
const variavelObjeto = await this.avaliar(alvoPropriedade.objeto);
|
|
25249
|
-
const objeto = this.resolverValor(variavelObjeto);
|
|
25250
|
-
const valor = await this.avaliar(expressao.valor);
|
|
25251
|
-
if (objeto.constructor === estruturas_1.ObjetoDeleguaClasse) {
|
|
25252
|
-
const objetoDeleguaClasse = objeto;
|
|
25253
|
-
await objetoDeleguaClasse.definir(alvoPropriedade.simbolo, valor, this);
|
|
25254
|
-
}
|
|
25255
|
-
else {
|
|
25256
|
-
// Se cair aqui, provavelmente `objeto.constructor.name` é 'Object'.
|
|
25257
|
-
objeto[alvoPropriedade.simbolo.lexema] = valor;
|
|
25258
|
-
}
|
|
25259
|
-
break;
|
|
25260
|
-
default:
|
|
25261
|
-
throw new excecoes_1.ErroEmTempoDeExecucao(undefined, `Atribuição com caso faltante: ${JSON.stringify(expressao)}.`);
|
|
25262
|
-
}
|
|
25263
|
-
return valorResolvido;
|
|
25264
|
-
}
|
|
25265
25293
|
async visitarExpressaoDefinirValor(expressao) {
|
|
25266
25294
|
const variavelObjeto = await this.avaliar(expressao.objeto);
|
|
25267
25295
|
const objeto = this.resolverValor(variavelObjeto);
|
|
@@ -28955,11 +28983,11 @@ const simbolo_1 = require("./simbolo");
|
|
|
28955
28983
|
const palavras_reservadas_1 = require("./palavras-reservadas");
|
|
28956
28984
|
const delegua_1 = __importDefault(require("../tipos-de-simbolos/delegua"));
|
|
28957
28985
|
/**
|
|
28958
|
-
|
|
28959
|
-
|
|
28960
|
-
|
|
28961
|
-
|
|
28962
|
-
|
|
28986
|
+
* O Lexador é responsável por transformar o código em uma coleção de tokens de linguagem.
|
|
28987
|
+
* Cada token de linguagem é representado por um tipo, um lexema e informações da linha de código em que foi expresso.
|
|
28988
|
+
* Também é responsável por mapear as palavras reservadas da linguagem, que não podem ser usadas por outras
|
|
28989
|
+
* estruturas, tais como nomes de variáveis, funções, literais, classes e assim por diante.
|
|
28990
|
+
*/
|
|
28963
28991
|
class Lexador {
|
|
28964
28992
|
constructor(performance = false) {
|
|
28965
28993
|
this.codigo = [];
|
|
@@ -29027,10 +29055,10 @@ class Lexador {
|
|
|
29027
29055
|
return this.atual >= this.codigo[this.linha].length;
|
|
29028
29056
|
}
|
|
29029
29057
|
/**
|
|
29030
|
-
|
|
29031
|
-
|
|
29032
|
-
|
|
29033
|
-
|
|
29058
|
+
* Indica se o código está na última linha.
|
|
29059
|
+
* @returns Verdadeiro se contador de linhas está na última linha.
|
|
29060
|
+
* Falso caso contrário.
|
|
29061
|
+
*/
|
|
29034
29062
|
eUltimaLinha() {
|
|
29035
29063
|
return this.linha >= this.codigo.length - 1;
|
|
29036
29064
|
}
|
|
@@ -29038,7 +29066,9 @@ class Lexador {
|
|
|
29038
29066
|
return this.eUltimaLinha() && this.codigo[this.codigo.length - 1].length <= this.atual;
|
|
29039
29067
|
}
|
|
29040
29068
|
avancar() {
|
|
29041
|
-
this.
|
|
29069
|
+
const linha = this.codigo[this.linha];
|
|
29070
|
+
const codePoint = linha.codePointAt(this.atual);
|
|
29071
|
+
this.atual += codePoint && codePoint > 0xffff ? 2 : 1;
|
|
29042
29072
|
if (this.eFinalDaLinha() && !this.eUltimaLinha()) {
|
|
29043
29073
|
this.linha++;
|
|
29044
29074
|
this.atual = 0;
|
|
@@ -29056,7 +29086,12 @@ class Lexador {
|
|
|
29056
29086
|
simboloAtual() {
|
|
29057
29087
|
if (this.eFinalDaLinha())
|
|
29058
29088
|
return '\0';
|
|
29059
|
-
|
|
29089
|
+
const linha = this.codigo[this.linha];
|
|
29090
|
+
const codePoint = linha.codePointAt(this.atual);
|
|
29091
|
+
if (codePoint === undefined) {
|
|
29092
|
+
return '\0';
|
|
29093
|
+
}
|
|
29094
|
+
return String.fromCodePoint(codePoint);
|
|
29060
29095
|
}
|
|
29061
29096
|
comentarioMultilinha() {
|
|
29062
29097
|
let conteudo = '';
|
|
@@ -29080,10 +29115,10 @@ class Lexador {
|
|
|
29080
29115
|
}
|
|
29081
29116
|
}
|
|
29082
29117
|
/**
|
|
29083
|
-
|
|
29084
|
-
|
|
29085
|
-
|
|
29086
|
-
|
|
29118
|
+
* Lê um comentário documentário (iniciado com `/**`), agregando o conteúdo
|
|
29119
|
+
* em um único token DOCUMENTARIO. Linhas com `*` inicial (convenção JSDoc)
|
|
29120
|
+
* têm o asterisco removido.
|
|
29121
|
+
*/
|
|
29087
29122
|
comentarioDocumentario() {
|
|
29088
29123
|
// Cursor está no primeiro '*' de '/**'. Avança para pular o segundo '*'.
|
|
29089
29124
|
this.avancar();
|
|
@@ -29121,10 +29156,23 @@ class Lexador {
|
|
|
29121
29156
|
this.adicionarSimbolo(delegua_1.default.COMENTARIO, conteudo.trim());
|
|
29122
29157
|
}
|
|
29123
29158
|
proximoSimbolo() {
|
|
29124
|
-
|
|
29159
|
+
const linha = this.codigo[this.linha];
|
|
29160
|
+
const atual = this.simboloAtual();
|
|
29161
|
+
const incremento = atual.length;
|
|
29162
|
+
const codePoint = linha.codePointAt(this.atual + incremento);
|
|
29163
|
+
if (codePoint === undefined) {
|
|
29164
|
+
return '\0';
|
|
29165
|
+
}
|
|
29166
|
+
return String.fromCodePoint(codePoint);
|
|
29125
29167
|
}
|
|
29126
29168
|
simboloAnterior() {
|
|
29127
|
-
|
|
29169
|
+
const linha = this.codigo[this.linha];
|
|
29170
|
+
const indiceAnterior = this.atual -
|
|
29171
|
+
(linha.codePointAt(this.atual - 2) > 0xffff ? 2 : 1);
|
|
29172
|
+
const codePoint = linha.codePointAt(indiceAnterior);
|
|
29173
|
+
if (codePoint === undefined) {
|
|
29174
|
+
return '\0';
|
|
29175
|
+
}
|
|
29128
29176
|
}
|
|
29129
29177
|
analisarTexto(delimitador = '"') {
|
|
29130
29178
|
let valor = '';
|
|
@@ -29310,6 +29358,19 @@ class Lexador {
|
|
|
29310
29358
|
: delegua_1.default.IDENTIFICADOR;
|
|
29311
29359
|
this.adicionarSimbolo(tipo);
|
|
29312
29360
|
}
|
|
29361
|
+
eEmoji(caractere) {
|
|
29362
|
+
const emojiRegex = /\p{Extended_Pictographic}(?:\uFE0F|\u200D\p{Extended_Pictographic})*/u;
|
|
29363
|
+
return emojiRegex.test(caractere);
|
|
29364
|
+
}
|
|
29365
|
+
analisarEmoji() {
|
|
29366
|
+
const simboloAtual = this.simboloAtual();
|
|
29367
|
+
this.erros.push({
|
|
29368
|
+
linha: this.linha + 1,
|
|
29369
|
+
caractere: simboloAtual,
|
|
29370
|
+
mensagem: 'Emojis devem estar envoltos por aspas.',
|
|
29371
|
+
});
|
|
29372
|
+
this.avancar();
|
|
29373
|
+
}
|
|
29313
29374
|
analisarToken() {
|
|
29314
29375
|
const caractere = this.simboloAtual();
|
|
29315
29376
|
switch (caractere) {
|
|
@@ -29573,6 +29634,8 @@ class Lexador {
|
|
|
29573
29634
|
default:
|
|
29574
29635
|
if (this.eDigito(caractere))
|
|
29575
29636
|
this.analisarNumero();
|
|
29637
|
+
else if (this.eEmoji(caractere))
|
|
29638
|
+
this.analisarEmoji();
|
|
29576
29639
|
else if (this.eAlfabeto(caractere))
|
|
29577
29640
|
this.identificarPalavraChave();
|
|
29578
29641
|
else {
|