Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions fontes/lexador/lexador.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,12 +572,7 @@ export class Lexador extends LexadorBase {
} else if (this.eAlfabeto(c)) {
this.identificarPalavraChave();
} else {
this.erros.push({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nào concordo com essa modificação. Aqui você está simplesmente se livrando de qualquer erro léxico, o que é previsto na arquitetura de Delégua. Quando há um erro léxico, as etapas seguintes não podem seguir. Por isso os testes unitários em outros arquivos não fazem sentido.

linha: this.linha + 1,
caractere: c,
mensagem: 'Caractere inesperado.'
} as ErroLexador);

this.adicionarSimbolo(tiposDeSimbolos.INVALIDO, c);
this.avancar();
}
}
Expand Down
1 change: 1 addition & 0 deletions fontes/tipos-de-simbolos/delegua.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default {
IMPLEMENTA: 'IMPLEMENTA',
MESCLA: 'MESCLA',
INTERFACE: 'INTERFACE',
INVALIDO: 'INVALIDO',
IGUAL: 'IGUAL',
IGUAL_IGUAL: 'IGUAL_IGUAL',
IMPORTAR: 'IMPORTAR',
Expand Down
16 changes: 16 additions & 0 deletions testes/avaliador-sintatico/avaliador-sintatico.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1745,6 +1745,22 @@ describe('Avaliador sintático', () => {
const erro = retornoAvaliadorSintatico.erros[0];
expect(erro.message).toBe("Função retorna valores com mais de um tipo. Tipo esperado: número. Tipos encontrados: texto, número.");
});

it('Deve apontar erro ao utilizar `#` como retorno de função', async () => {
const retornoLexador = lexador.mapear(
[
'funcao teste() {',
' retorna #',
'}',
'escreva(teste())',
],
-1
);
const retornoAvaliadorSintatico = await avaliadorSintatico.analisar(retornoLexador, -1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quando há um erro léxico, essa etapa nem poderia executar. Isso está presente em todos os componentes que fazem parte de Delégua, como delegua-web, delegua-node e todos os compiladores.


expect(retornoAvaliadorSintatico.erros.length).toBeGreaterThan(0);
expect(retornoAvaliadorSintatico.erros[0].message).toBe("Esperado expressão.");
});
});

describe('Laços de repetição', () => {
Expand Down
17 changes: 17 additions & 0 deletions testes/interpretador/interpretador.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5392,6 +5392,23 @@ describe('Interpretador', () => {

expect(retornoInterpretador.erros).toHaveLength(1);
});

it('Deve apontar erro ao utilizar `#`', async () => {
const codigo = [
'funcao teste() {',
' retorna #',
'}',
'escreva(teste())',
];
const retornoLexador = lexador.mapear(codigo, -1);
const retornoAvaliadorSintatico = await avaliadorSintatico.analisar(retornoLexador, -1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idem.

const retornoInterpretador = await interpretador.interpretar(
retornoAvaliadorSintatico.declaracoes
);

expect(retornoAvaliadorSintatico.erros).toHaveLength(1);
expect(retornoAvaliadorSintatico.erros[0].message).toBe('Esperado expressão.');
});
});

describe('Verificação de tipos em atribuição', () => {
Expand Down
13 changes: 11 additions & 2 deletions testes/lexador/lexador.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,17 @@ describe('Lexador', () => {

it('Falha léxica - caractere inesperado', () => {
const resultado = lexador.mapear(['平'], -1);
expect(resultado.simbolos).toHaveLength(0);
expect(resultado.erros).toHaveLength(1);
expect(resultado.simbolos).toHaveLength(1);
expect(resultado.simbolos[0].tipo).toBe('INVALIDO');
expect(resultado.erros).toHaveLength(0);
});

it('Deve apontar erro ao utilizar `#`', () => {
const resultado = lexador.mapear(['#'], -1);

expect(resultado.simbolos).toHaveLength(1);
expect(resultado.simbolos[0].tipo).toBe('INVALIDO');
expect(resultado.erros).toHaveLength(0);
});

describe('Emojis', () => {
Expand Down
Loading