Skip to content

Commit

Permalink
feat(objectionary#3744): check all parsing messages in 'eo-types'
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Jan 15, 2025
1 parent 39b298a commit b496bb1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
20 changes: 19 additions & 1 deletion eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void syntaxError(
);
}
final List<String> msgs = new ArrayList<>(0);
if (error instanceof NoViableAltException || error instanceof InputMismatchException) {
if (error instanceof NoViableAltException) {
final Token token = (Token) symbol;
final Parser parser = (Parser) recognizer;
final String rule = parser.getRuleInvocationStack().get(0);
Expand All @@ -114,6 +114,24 @@ public void syntaxError(
Math.max(token.getStopIndex() - token.getStartIndex(), 1)
).formatted()
);
} else if (error instanceof InputMismatchException) {
final Token token = (Token) symbol;
final Parser parser = (Parser) recognizer;
final String rule = parser.getRuleInvocationStack().get(0);
final String detailed;
if (parser.getRuleNames()[EoParser.RULE_program].equals(rule)) {
detailed = "Unexpected part of the program";
} else {
detailed = msg;
}
msgs.add(new MsgLocated(line, position, detailed).formatted());
msgs.add(
new MsgUnderlined(
this.lines.line(line),
position,
Math.max(token.getStopIndex() - token.getStartIndex(), 1)
).formatted()
);
} else {
msgs.add(new MsgLocated(line, position, msg).formatted());
msgs.add(this.lines.line(line));
Expand Down
8 changes: 4 additions & 4 deletions eo-parser/src/test/java/org/eolang/parser/EoSyntaxTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,10 @@ void checksTypoPacks(final String yaml) {
if (story.map().containsKey(msg)) {
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(story.after()).toString(),
story.after()
.xpath("/program/errors/error[1]/text()")
.get(0)
.replaceAll("\r", ""),
String.join(
"\n",
story.after().xpath("/program/errors/error/text()")
).replaceAll("\r", ""),
Matchers.equalTo(story.map().get(msg).toString())
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ message: |-
[2:0] error: 'Atom must have a type'
[] > a [] > b [] > c [] > d hello world
^^^^^^^
[2:7] error: 'mismatched input '[' expecting '/''
[] > a [] > b [] > c [] > d hello world
^
input: |
# No comments
[] > a [] > b [] > c [] > d hello world
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@ line: 5
# @todo #3706:30min The error message doesn't highlight the exact position of the
# comment. The error message should be updated to point to the exact position
# of the comment.
message: |
message: |-
[5:12] error: 'Invalid object declaration'
sprintwf
[5:12] error: 'Invalid objects declaration that may be used inside abstract object'
sprintwf
[4:-1] error: 'Unexpected part of the program'
# a comment here is prohibited
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
input: |
# No comments
[args] > app
Expand Down

0 comments on commit b496bb1

Please sign in to comment.