Skip to content

Commit

Permalink
spanish errors (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
elbraulio committed Sep 30, 2023
2 parents acbe61d + d259de0 commit 1b32c6d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void syntaxError(
new ParseError(
line,
column,
msg
new SyntaxError(exception).message()
)
);
}
Expand Down
23 changes: 23 additions & 0 deletions anilang-parser/src/main/java/com/anilang/parser/SyntaxError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Property of ani-lang project.
*/

package com.anilang.parser;

import org.antlr.v4.runtime.NoViableAltException;
import org.antlr.v4.runtime.RecognitionException;

final class SyntaxError {
private final RecognitionException exception;

public SyntaxError(final RecognitionException exception) {
this.exception = exception;
}

String message() {
if(exception instanceof NoViableAltException) {
return "Token no esperado.";
}
return exception.getMessage();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ void invalidCharacterAssignation() throws IOException {
);
}

@Test
void spanishDefaultError() throws IOException {
Assertions.assertEquals(
"[1:4]: Token no esperado.",
new AniParserCheck(
new ExampleFile(
ExampleCode.INVALID_ASSIGNATION
).inputStream()
).errors().get(0).getError(),
"spanish default"
);
}

@Test
void validCharacterAssignation() throws IOException {
Assertions.assertEquals(
Expand Down

0 comments on commit 1b32c6d

Please sign in to comment.