diff --git a/.vscode/launch.json b/.vscode/launch.json index db32ffb4..ae0ac451 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -191,14 +191,13 @@ { "type": "node", "request": "launch", - "name": "Importação (Delégua)", + "name": "Classes > Construtor (Delégua)", "skipFiles": ["/**", "node_modules/**"], "cwd": "${workspaceRoot}", "console": "integratedTerminal", "args": [ "${workspaceFolder}\\index.ts", - "--depurador", - "./testes/exemplos/importacao/importacao-1.egua" + "./testes/exemplos/classes/construtor-classe.egua" ], "runtimeExecutable": "node", "runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"] @@ -206,12 +205,14 @@ { "type": "node", "request": "launch", - "name": "Classes > Construtor (Delégua)", + "name": "Classes > Construtor (Égua Clássico)", "skipFiles": ["/**", "node_modules/**"], "cwd": "${workspaceRoot}", "console": "integratedTerminal", "args": [ "${workspaceFolder}\\index.ts", + "--dialeto", + "egua", "./testes/exemplos/classes/construtor-classe.egua" ], "runtimeExecutable": "node", @@ -220,15 +221,29 @@ { "type": "node", "request": "launch", - "name": "Classes > Construtor (Égua Clássico)", + "name": "Funções Anônimas (Delégua)", "skipFiles": ["/**", "node_modules/**"], "cwd": "${workspaceRoot}", "console": "integratedTerminal", "args": [ "${workspaceFolder}\\index.ts", - "--dialeto", - "egua", - "./testes/exemplos/classes/construtor-classe.egua" + "--depurador", + "./testes/exemplos/funcoes/funcoes-anonimas.delegua" + ], + "runtimeExecutable": "node", + "runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"] + }, + { + "type": "node", + "request": "launch", + "name": "Importação (Delégua)", + "skipFiles": ["/**", "node_modules/**"], + "cwd": "${workspaceRoot}", + "console": "integratedTerminal", + "args": [ + "${workspaceFolder}\\index.ts", + "--depurador", + "./testes/exemplos/importacao/importacao-1.egua" ], "runtimeExecutable": "node", "runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"] diff --git a/fontes/avaliador-sintatico/avaliador-sintatico.ts b/fontes/avaliador-sintatico/avaliador-sintatico.ts index 0553048c..d139c779 100644 --- a/fontes/avaliador-sintatico/avaliador-sintatico.ts +++ b/fontes/avaliador-sintatico/avaliador-sintatico.ts @@ -166,11 +166,7 @@ export class AvaliadorSintatico implements AvaliadorSintaticoInterface { return new Super(this.hashArquivo, simboloChave, metodo); } - if ( - this.verificarSeSimboloAtualEIgualA( - tiposDeSimbolos.COLCHETE_ESQUERDO - ) - ) { + if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.COLCHETE_ESQUERDO)) { const valores = []; if ( @@ -181,11 +177,7 @@ export class AvaliadorSintatico implements AvaliadorSintaticoInterface { return new Vetor(this.hashArquivo, Number(simboloAtual.linha), []); } - while ( - !this.verificarSeSimboloAtualEIgualA( - tiposDeSimbolos.COLCHETE_DIREITO - ) - ) { + while (!this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.COLCHETE_DIREITO)) { const valor = this.atribuir(); valores.push(valor); if ( @@ -202,25 +194,15 @@ export class AvaliadorSintatico implements AvaliadorSintaticoInterface { return new Vetor(this.hashArquivo, Number(simboloAtual.linha), valores); } - if ( - this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.CHAVE_ESQUERDA) - ) { + if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.CHAVE_ESQUERDA)) { const chaves = []; const valores = []; - if ( - this.verificarSeSimboloAtualEIgualA( - tiposDeSimbolos.CHAVE_DIREITA - ) - ) { + if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.CHAVE_DIREITA)) { return new Dicionario(this.hashArquivo, Number(simboloAtual.linha), [], []); } - while ( - !this.verificarSeSimboloAtualEIgualA( - tiposDeSimbolos.CHAVE_DIREITA - ) - ) { + while (!this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.CHAVE_DIREITA)) { let chave = this.atribuir(); this.consumir( tiposDeSimbolos.DOIS_PONTOS, @@ -231,9 +213,7 @@ export class AvaliadorSintatico implements AvaliadorSintaticoInterface { chaves.push(chave); valores.push(valor); - if ( - this.simboloAtual().tipo !== tiposDeSimbolos.CHAVE_DIREITA - ) { + if (this.simboloAtual().tipo !== tiposDeSimbolos.CHAVE_DIREITA) { this.consumir( tiposDeSimbolos.VIRGULA, 'Esperado vírgula antes da próxima expressão.' @@ -244,6 +224,8 @@ export class AvaliadorSintatico implements AvaliadorSintaticoInterface { return new Dicionario(this.hashArquivo, Number(simboloAtual.linha), chaves, valores); } + if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.FUNÇÃO, tiposDeSimbolos.FUNCAO)) + return this.corpoDaFuncao(this.simboloAnterior().lexema); if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.FALSO)) return new Literal(this.hashArquivo, Number(simboloAtual.linha), false); if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.VERDADEIRO)) @@ -253,8 +235,7 @@ export class AvaliadorSintatico implements AvaliadorSintaticoInterface { if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.ISTO)) return new Isto(this.hashArquivo, Number(simboloAtual.linha), this.simboloAnterior()); - if ( - this.verificarSeSimboloAtualEIgualA( + if (this.verificarSeSimboloAtualEIgualA( tiposDeSimbolos.NUMERO, tiposDeSimbolos.TEXTO ) @@ -263,17 +244,11 @@ export class AvaliadorSintatico implements AvaliadorSintaticoInterface { return new Literal(this.hashArquivo, Number(simboloAnterior.linha), simboloAnterior.literal); } - if ( - this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.IDENTIFICADOR) - ) { + if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.IDENTIFICADOR)) { return new Variavel(this.hashArquivo, this.simboloAnterior()); } - if ( - this.verificarSeSimboloAtualEIgualA( - tiposDeSimbolos.PARENTESE_ESQUERDO - ) - ) { + if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.PARENTESE_ESQUERDO)) { let expressao = this.expressao(); this.consumir( tiposDeSimbolos.PARENTESE_DIREITO, diff --git a/testes/avaliador-sintatico.test.ts b/testes/avaliador-sintatico.test.ts index 9749528a..9cb22b3a 100644 --- a/testes/avaliador-sintatico.test.ts +++ b/testes/avaliador-sintatico.test.ts @@ -33,5 +33,24 @@ describe('Avaliador sintático', () => { expect(retornoAvaliadorSintatico).toBeTruthy(); expect(retornoAvaliadorSintatico.declaracoes).toHaveLength(0); }); + + describe('Funções Anônimas', () => { + it('Função anônima com mais de 255 parâmetros', () => { + let acumulador = ""; + for (let i = 1; i <= 256; i++) { + acumulador += "a" + i + ", " + } + + acumulador = acumulador.substring(0, acumulador.length - 2); + + const funcaoCom256Argumentos = "var f = funcao(" + acumulador + ") {}" + const retornoLexador = delegua.lexador.mapear([funcaoCom256Argumentos], -1); + const retornoAvaliadorSintatico = delegua.avaliadorSintatico.analisar(retornoLexador); + + expect(retornoAvaliadorSintatico).toBeTruthy(); + expect(retornoAvaliadorSintatico.erros).toHaveLength(1); + expect(retornoAvaliadorSintatico.erros[0].message).toBe('Não pode haver mais de 255 parâmetros'); + }) + }); }); }); \ No newline at end of file diff --git a/testes/exemplos/funcoes/funcoes-anonimas.delegua b/testes/exemplos/funcoes/funcoes-anonimas.delegua new file mode 100644 index 00000000..8fc9deee --- /dev/null +++ b/testes/exemplos/funcoes/funcoes-anonimas.delegua @@ -0,0 +1,4 @@ +var funcaoParaMapear = função(a) { + retorna a * 2; +}; +escreva(mapear([5, 3], funcaoParaMapear)); \ No newline at end of file