Skip to content

Commit

Permalink
feat(#3706): add a few more puzzles
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Dec 23, 2024
1 parent 9918149 commit 5f9a018
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 8 deletions.
15 changes: 7 additions & 8 deletions eo-parser/src/main/java/org/eolang/parser/ParsingErrors.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.Optional;
import org.antlr.v4.runtime.BaseErrorListener;
import org.antlr.v4.runtime.InputMismatchException;
import org.antlr.v4.runtime.LexerNoViableAltException;
import org.antlr.v4.runtime.NoViableAltException;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Recognizer;
Expand All @@ -46,6 +45,10 @@
* Accumulates all parsing errors.
*
* @since 0.30.0
* @todo #3706:30min Split {@link ParsingErrors} into two classes.
* Currently we use the same {@link ParsingErrors} class to accumulate all the parsing errors
* despite their origin. This class should be split into two classes: one for parsing errors
* {@link ParserErrors} and another for lexer errors {@link LexerErrors}.
*/
final class ParsingErrors extends BaseErrorListener implements Iterable<Directive> {

Expand Down Expand Up @@ -86,7 +89,7 @@ public void syntaxError(
final String msg,
final RecognitionException error
) {
if (error instanceof NoViableAltException) {
if (error instanceof NoViableAltException || error instanceof InputMismatchException) {
final Token token = (Token) symbol;
final EoParser parser = (EoParser) recognizer;
final String rule = parser.getRuleInvocationStack().get(0);
Expand All @@ -96,6 +99,8 @@ public void syntaxError(
detailed = "Invalid object declaration";
} else if (names[EoParser.RULE_metas].equals(rule)) {
detailed = "Invalid meta declaration";
} else if (names[EoParser.RULE_program].equals(rule)) {
detailed = "Invalid program declaration";
} else {
detailed = "no viable alternative at input";
}
Expand All @@ -116,12 +121,6 @@ public void syntaxError(
line
)
);
} else if (error instanceof InputMismatchException) {
System.out.println(error);
//todo
} else if (error instanceof LexerNoViableAltException) {
System.out.println(error);
//todo
} else if (Objects.isNull(error)) {
this.errors.add(
new ParsingException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
# SOFTWARE.
---
line: 3
message: |-
[3:0] error: Invalid object declaration:
+meta other
^^^^^^^^^^
input: |
+meta smth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
# SOFTWARE.
---
line: 4
message: |-
[4:-1] error: Invalid program declaration:
[] > inner
^^^^^^^^^^^^
input: |
# No comments.
[] > test /int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
# SOFTWARE.
---
line: 3
message: |-
[3:-1] error: Invalid program declaration:
EOF
^^^
input: |
1.add 1 > x
(1.add 1) > y
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
# SOFTWARE.
---
line: 3
# @todo #3706:30min Unreadable error message if program declaration is invalid.
# Improve error message for the case when a program declaration is invalid.
# The error message should be more informative and should point to the exact
# place in the input where the error occurred. Moreover it should be clear
# what to do to fix the error. 'simple-application-named.yaml' has the same issue.
message: |-
[3:-1] error: Invalid program declaration:
EOF
^^^
input: |
1.add 1 > x
(1.add 1)
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
# SOFTWARE.
---
line: 2
message: |-
[2:0] error: Invalid program declaration:
.z
^
input: |
x y
.z
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
# SOFTWARE.
---
line: 2
message: |-
[2:0] error: Invalid program declaration:
.z
^
input: |
x.y
.z

0 comments on commit 5f9a018

Please sign in to comment.