From 475e929436e181169088c96fcf21aa00ca693a75 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Wed, 15 Jan 2025 16:04:49 +0300 Subject: [PATCH 01/14] feat(#3744): fix the Eo grammar bug --- eo-parser/src/main/antlr4/org/eolang/parser/Eo.g4 | 2 +- .../main/java/org/eolang/parser/XeEoListener.java | 15 +++++++++++---- .../test/java/org/eolang/parser/EoSyntaxTest.java | 4 ++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/eo-parser/src/main/antlr4/org/eolang/parser/Eo.g4 b/eo-parser/src/main/antlr4/org/eolang/parser/Eo.g4 index 5d4199b4ac..e2414119e3 100644 --- a/eo-parser/src/main/antlr4/org/eolang/parser/Eo.g4 +++ b/eo-parser/src/main/antlr4/org/eolang/parser/Eo.g4 @@ -47,7 +47,7 @@ metas // Objects // Ends on the next line objects - : (object EOL?)* object + : (object EOL?)+ ; comment diff --git a/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java b/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java index 8e9a7369da..c267cf62da 100644 --- a/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java +++ b/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java @@ -28,8 +28,10 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.Optional; import java.util.function.Supplier; import java.util.stream.Collectors; +import javax.swing.text.html.Option; import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.tree.ErrorNode; @@ -280,11 +282,16 @@ public void exitJustNamed(final EoParser.JustNamedContext ctx) { } @Override - @SuppressWarnings("PMD.ConfusingTernary") public void enterAtom(final EoParser.AtomContext ctx) { - this.startObject(ctx) - .prop("atom", ctx.type().typeFqn().getText()) - .leave(); + final EoParser.TypeFqnContext fqn = ctx.type().typeFqn(); + if (fqn == null) { + this.errors.add(XeEoListener.error(ctx, "Atom must have a type")); + this.startObject(ctx).leave(); + } else { + this.startObject(ctx) + .prop("atom", fqn.getText()) + .leave(); + } } @Override diff --git a/eo-parser/src/test/java/org/eolang/parser/EoSyntaxTest.java b/eo-parser/src/test/java/org/eolang/parser/EoSyntaxTest.java index 7d082ca64e..5df6d00e83 100644 --- a/eo-parser/src/test/java/org/eolang/parser/EoSyntaxTest.java +++ b/eo-parser/src/test/java/org/eolang/parser/EoSyntaxTest.java @@ -89,7 +89,7 @@ void printsProperListingEvenWhenSyntaxIsBroken() throws Exception { "[] > x-н, 1\n" ); MatcherAssert.assertThat( - EoIndentLexerTest.TO_ADD_MESSAGE, + "EO syntax is broken, but listing should be printed", XhtmlMatchers.xhtml( new String( new EoSyntax( @@ -100,7 +100,7 @@ void printsProperListingEvenWhenSyntaxIsBroken() throws Exception { ) ), XhtmlMatchers.hasXPaths( - "/program/errors[count(error)=2]", + "/program/errors[count(error)=3]", String.format("/program[listing='%s']", src) ) ); From fe900ab65040b6700c3cd66d450905b8503fdd50 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Wed, 15 Jan 2025 16:09:14 +0300 Subject: [PATCH 02/14] feat(#3744): add more descriptive message for 'slave' object --- eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java | 2 ++ .../resources/org/eolang/parser/eo-typos/binding-with-rho.yaml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java b/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java index cfe8c78ac9..727cd9c31d 100644 --- a/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java +++ b/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java @@ -99,6 +99,8 @@ public void syntaxError( detailed = "Invalid meta declaration"; } else if (names[EoParser.RULE_program].equals(rule)) { detailed = "Invalid program declaration"; + } else if (names[EoParser.RULE_slave].equals(rule)) { + detailed = "Invalid objects declaration that may be used inside abstract object"; } else { detailed = "no viable alternative at input"; } diff --git a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/binding-with-rho.yaml b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/binding-with-rho.yaml index 061fe04ce3..6785e4b727 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/binding-with-rho.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/binding-with-rho.yaml @@ -22,7 +22,7 @@ --- line: 2 message: >- - [2:4] error: 'Invalid object declaration' + [2:4] error: 'Invalid objects declaration that may be used inside abstract object' y:^ ^ input: | From 8eef7e85abb3b76c2b77ddd4e81cea85dc544e16 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Wed, 15 Jan 2025 16:12:07 +0300 Subject: [PATCH 03/14] feat(#3744): fix the message for 'broken-head.yaml' check --- .../resources/org/eolang/parser/eo-typos/broken-head.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/broken-head.yaml b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/broken-head.yaml index a5a3a8c1d1..18e4ad1931 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/broken-head.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/broken-head.yaml @@ -22,9 +22,9 @@ --- line: 2 message: |- - [2:7] error: 'Invalid object declaration' + [2:0] error: 'Atom must have a type' [] > a [] > b [] > c [] > d hello world - ^ + ^^^^^^^ input: | # No comments [] > a [] > b [] > c [] > d hello world From a8ae7c476766121c9356fa21803f1da8fe482cc2 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Wed, 15 Jan 2025 16:14:03 +0300 Subject: [PATCH 04/14] feat(#3744): fix the message for 'double-empty-lines.yaml' check --- .../org/eolang/parser/eo-typos/double-empty-lines.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/double-empty-lines.yaml b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/double-empty-lines.yaml index c688e9ab33..c8a16f011b 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/double-empty-lines.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/double-empty-lines.yaml @@ -26,7 +26,7 @@ line: 4 # The error message should be more informative and should highlight the exact location # of the error. message: | - [4:0] error: 'extraneous input '\n' expecting {COMMENTARY, 'Q', 'QQ', '*', '$', '[', '(', '@', '^', BYTES, STRING, INT, FLOAT, HEX, NAME, TEXT}' + [4:0] error: 'Invalid program declaration' input: | # No comments. From 39b298aae4f201bd99dd43c8aed3f3f2b9100d13 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Wed, 15 Jan 2025 16:23:55 +0300 Subject: [PATCH 05/14] feat(#3744): fix all the unit tests --- eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java | 4 +++- .../org/eolang/parser/eo-typos/double-empty-lines.yaml | 2 +- .../org/eolang/parser/eo-typos/empty-line-between-metas.yaml | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java b/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java index 727cd9c31d..18e52dc2aa 100644 --- a/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java +++ b/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java @@ -94,13 +94,15 @@ public void syntaxError( final String[] names = parser.getRuleNames(); final String detailed; if (names[EoParser.RULE_objects].equals(rule)) { - detailed = "Invalid object declaration"; + detailed = "Invalid object list 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 if (names[EoParser.RULE_slave].equals(rule)) { detailed = "Invalid objects declaration that may be used inside abstract object"; + } else if (names[EoParser.RULE_object].equals(rule)) { + detailed = "Invalid object declaration"; } else { detailed = "no viable alternative at input"; } diff --git a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/double-empty-lines.yaml b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/double-empty-lines.yaml index c8a16f011b..4622b95f40 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/double-empty-lines.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/double-empty-lines.yaml @@ -25,7 +25,7 @@ line: 4 # Cryptic error message is returned when there are two empty lines between metas. # The error message should be more informative and should highlight the exact location # of the error. -message: | +message: |+ [4:0] error: 'Invalid program declaration' input: | diff --git a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/empty-line-between-metas.yaml b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/empty-line-between-metas.yaml index 5bc1f8ac67..e0d3f9937f 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/empty-line-between-metas.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/empty-line-between-metas.yaml @@ -22,7 +22,7 @@ --- line: 3 message: |- - [3:0] error: 'Invalid object declaration' + [3:0] error: 'Invalid object list declaration' +meta other ^^^^^^^^^^ input: | From b496bb1b7784b9055f0da989ee7158ea0e2778d1 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Wed, 15 Jan 2025 16:49:40 +0300 Subject: [PATCH 06/14] feat(#3744): check all parsing messages in 'eo-types' --- .../org/eolang/parser/EoParserErrors.java | 20 ++++++++++++++++++- .../java/org/eolang/parser/EoSyntaxTest.java | 8 ++++---- .../eolang/parser/eo-typos/broken-head.yaml | 4 ++++ .../parser/eo-typos/comment-in-method.yaml | 10 +++++++++- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java b/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java index 18e52dc2aa..560c6b221f 100644 --- a/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java +++ b/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java @@ -87,7 +87,7 @@ public void syntaxError( ); } final List 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); @@ -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)); diff --git a/eo-parser/src/test/java/org/eolang/parser/EoSyntaxTest.java b/eo-parser/src/test/java/org/eolang/parser/EoSyntaxTest.java index 5df6d00e83..1a6e6b8f18 100644 --- a/eo-parser/src/test/java/org/eolang/parser/EoSyntaxTest.java +++ b/eo-parser/src/test/java/org/eolang/parser/EoSyntaxTest.java @@ -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()) ); } diff --git a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/broken-head.yaml b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/broken-head.yaml index 18e4ad1931..6dff838238 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/broken-head.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/broken-head.yaml @@ -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 diff --git a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/comment-in-method.yaml b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/comment-in-method.yaml index df49acf048..6918f81b27 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/comment-in-method.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/comment-in-method.yaml @@ -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 From 3bfbc8087fc6c73139d536004be6c5595147649f Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Wed, 15 Jan 2025 16:53:54 +0300 Subject: [PATCH 07/14] feat(#3744): fix several parsing error messages --- .../org/eolang/parser/eo-typos/binding-with-rho.yaml | 7 +++++-- .../resources/org/eolang/parser/eo-typos/broken-head.yaml | 1 - .../org/eolang/parser/eo-typos/double-empty-lines.yaml | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/binding-with-rho.yaml b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/binding-with-rho.yaml index 6785e4b727..f099d662da 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/binding-with-rho.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/binding-with-rho.yaml @@ -21,10 +21,13 @@ # SOFTWARE. --- line: 2 -message: >- +message: |- [2:4] error: 'Invalid objects declaration that may be used inside abstract object' y:^ ^ + [3:-1] error: 'Unexpected part of the program' + EOF + ^^^ input: | x - y:^ + y:^ \ No newline at end of file diff --git a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/broken-head.yaml b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/broken-head.yaml index 6dff838238..3807b745fc 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/broken-head.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/broken-head.yaml @@ -25,7 +25,6 @@ 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 ^ diff --git a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/double-empty-lines.yaml b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/double-empty-lines.yaml index 4622b95f40..a20678800c 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/double-empty-lines.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/double-empty-lines.yaml @@ -26,7 +26,7 @@ line: 4 # The error message should be more informative and should highlight the exact location # of the error. message: |+ - [4:0] error: 'Invalid program declaration' + [4:0] error: 'Unexpected part of the program' input: | # No comments. From 54a76502f517e71f1794e48ac7ac9472b5001466 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Wed, 15 Jan 2025 16:59:27 +0300 Subject: [PATCH 08/14] feat(#3744): fix error message in 'empty-line-between-metas.yaml' check --- .../src/main/java/org/eolang/parser/EoParserErrors.java | 5 ++++- .../org/eolang/parser/eo-typos/empty-line-between-metas.yaml | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java b/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java index 560c6b221f..5a9f4ecf80 100644 --- a/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java +++ b/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java @@ -119,8 +119,11 @@ public void syntaxError( final Parser parser = (Parser) recognizer; final String rule = parser.getRuleInvocationStack().get(0); final String detailed; - if (parser.getRuleNames()[EoParser.RULE_program].equals(rule)) { + final String[] names = parser.getRuleNames(); + if (names[EoParser.RULE_program].equals(rule)) { detailed = "Unexpected part of the program"; + } else if (names[EoParser.RULE_objects].equals(rule)) { + detailed = "We expected a list of objects here, but found something else"; } else { detailed = msg; } diff --git a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/empty-line-between-metas.yaml b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/empty-line-between-metas.yaml index e0d3f9937f..06b0a4a3ea 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/empty-line-between-metas.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/empty-line-between-metas.yaml @@ -22,7 +22,7 @@ --- line: 3 message: |- - [3:0] error: 'Invalid object list declaration' + [3:0] error: 'We expected a list of objects here, but found something else' +meta other ^^^^^^^^^^ input: | From d0c426988458e830d4410b42bd7102d030136060 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Wed, 15 Jan 2025 17:25:08 +0300 Subject: [PATCH 09/14] feat(#3744): fix most of the unit tests --- .../main/java/org/eolang/parser/EoParserErrors.java | 4 ++-- eo-parser/src/main/java/org/eolang/parser/Lines.java | 2 +- .../org/eolang/parser/eo-typos/binding-with-rho.yaml | 11 +++++------ .../org/eolang/parser/eo-typos/comment-in-method.yaml | 2 +- .../eolang/parser/eo-typos/double-empty-lines.yaml | 2 +- .../parser/eo-typos/empty-line-between-metas.yaml | 2 +- .../org/eolang/parser/eo-typos/not-empty-atoms.yaml | 2 +- .../simple-application-named.yaml | 7 +++---- .../redundant-parentheses/simple-application.yaml | 7 +++---- .../org/eolang/parser/eo-typos/two-spaces.yaml | 6 ++++++ .../parser/eo-typos/vmethod-after-happlication.yaml | 2 +- .../eolang/parser/eo-typos/vmethod-after-hmethod.yaml | 2 +- 12 files changed, 26 insertions(+), 23 deletions(-) diff --git a/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java b/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java index 5a9f4ecf80..0d2f21bb06 100644 --- a/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java +++ b/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java @@ -121,9 +121,9 @@ public void syntaxError( final String detailed; final String[] names = parser.getRuleNames(); if (names[EoParser.RULE_program].equals(rule)) { - detailed = "Unexpected part of the program"; + detailed = "We expected the program to end here but encountered something unexpected"; } else if (names[EoParser.RULE_objects].equals(rule)) { - detailed = "We expected a list of objects here, but found something else"; + detailed = "We expected a list of objects here but encountered something unexpected"; } else { detailed = msg; } diff --git a/eo-parser/src/main/java/org/eolang/parser/Lines.java b/eo-parser/src/main/java/org/eolang/parser/Lines.java index 8919b49f53..3f607f41db 100644 --- a/eo-parser/src/main/java/org/eolang/parser/Lines.java +++ b/eo-parser/src/main/java/org/eolang/parser/Lines.java @@ -61,6 +61,6 @@ String line(final int number) { .map(UncheckedText::new) .map(UncheckedText::asString); } - return result.orElse("EOF"); + return result.orElse(""); } } diff --git a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/binding-with-rho.yaml b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/binding-with-rho.yaml index f099d662da..970c35027c 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/binding-with-rho.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/binding-with-rho.yaml @@ -21,13 +21,12 @@ # SOFTWARE. --- line: 2 -message: |- +message: |+ [2:4] error: 'Invalid objects declaration that may be used inside abstract object' y:^ ^ - [3:-1] error: 'Unexpected part of the program' - EOF - ^^^ -input: | + [3:-1] error: 'We expected the program to end here but encountered something unexpected' + +input: |- x - y:^ \ No newline at end of file + y:^ diff --git a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/comment-in-method.yaml b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/comment-in-method.yaml index 6918f81b27..16af6a44eb 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/comment-in-method.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/comment-in-method.yaml @@ -31,7 +31,7 @@ message: |- [5:12] error: 'Invalid objects declaration that may be used inside abstract object' sprintwf - [4:-1] error: 'Unexpected part of the program' + [4:-1] error: 'We expected the program to end here but encountered something unexpected' # a comment here is prohibited ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/double-empty-lines.yaml b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/double-empty-lines.yaml index a20678800c..8c08b92ffb 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/double-empty-lines.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/double-empty-lines.yaml @@ -26,7 +26,7 @@ line: 4 # The error message should be more informative and should highlight the exact location # of the error. message: |+ - [4:0] error: 'Unexpected part of the program' + [4:0] error: 'We expected the program to end here but encountered something unexpected' input: | # No comments. diff --git a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/empty-line-between-metas.yaml b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/empty-line-between-metas.yaml index 06b0a4a3ea..8f070f55c6 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/empty-line-between-metas.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/empty-line-between-metas.yaml @@ -22,7 +22,7 @@ --- line: 3 message: |- - [3:0] error: 'We expected a list of objects here, but found something else' + [3:0] error: 'We expected a list of objects here but encountered something unexpected' +meta other ^^^^^^^^^^ input: | diff --git a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/not-empty-atoms.yaml b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/not-empty-atoms.yaml index c7d006ccbd..2affbda7a9 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/not-empty-atoms.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/not-empty-atoms.yaml @@ -22,7 +22,7 @@ --- line: 4 message: |- - [4:-1] error: 'Invalid program declaration' + [4:-1] error: 'We expected the program to end here but encountered something unexpected' [] > inner ^^^^^^^^^^^^ input: | diff --git a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/redundant-parentheses/simple-application-named.yaml b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/redundant-parentheses/simple-application-named.yaml index 16632d4cbb..f18ed6dd5d 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/redundant-parentheses/simple-application-named.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/redundant-parentheses/simple-application-named.yaml @@ -21,10 +21,9 @@ # SOFTWARE. --- line: 3 -message: |- - [3:-1] error: 'Invalid program declaration' - EOF - ^^^ +message: |+ + [3:-1] error: 'We expected the program to end here but encountered something unexpected' + input: | 1.add 1 > x (1.add 1) > y diff --git a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/redundant-parentheses/simple-application.yaml b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/redundant-parentheses/simple-application.yaml index df20ec1a2d..f07a3f6a26 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/redundant-parentheses/simple-application.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/redundant-parentheses/simple-application.yaml @@ -26,10 +26,9 @@ line: 3 # 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 - ^^^ +message: |+ + [3:-1] error: 'We expected the program to end here but encountered something unexpected' + input: | 1.add 1 > x (1.add 1) diff --git a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/two-spaces.yaml b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/two-spaces.yaml index 3348c3f1c4..e8edfaf60b 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/two-spaces.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/two-spaces.yaml @@ -25,6 +25,12 @@ message: >- [5:2] error: 'Invalid object declaration' * ^ + [5:2] error: 'Invalid objects declaration that may be used inside abstract object' + * + ^ + [5:-1] error: 'We expected the program to end here but encountered something unexpected' + * + ^^^^ input: | # This is a code snippet from the following issue: # https://github.com/objectionary/eo/issues/3332 diff --git a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/vmethod-after-happlication.yaml b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/vmethod-after-happlication.yaml index 810d04e1b4..9c9a6e215a 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/vmethod-after-happlication.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/vmethod-after-happlication.yaml @@ -22,7 +22,7 @@ --- line: 2 message: |- - [2:0] error: 'Invalid program declaration' + [2:0] error: 'We expected the program to end here but encountered something unexpected' .z ^ input: | diff --git a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/vmethod-after-hmethod.yaml b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/vmethod-after-hmethod.yaml index 19014044f9..3e92fe0c4c 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/vmethod-after-hmethod.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/vmethod-after-hmethod.yaml @@ -22,7 +22,7 @@ --- line: 2 message: |- - [2:0] error: 'Invalid program declaration' + [2:0] error: 'We expected the program to end here but encountered something unexpected' .z ^ input: | From c4c66adddce73f970c177c70f77fcdac98f81867 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Wed, 15 Jan 2025 17:27:51 +0300 Subject: [PATCH 10/14] feat(#3744): add one more puzzle --- .../resources/org/eolang/parser/eo-typos/two-spaces.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/two-spaces.yaml b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/two-spaces.yaml index e8edfaf60b..686b813e0a 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/two-spaces.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/two-spaces.yaml @@ -21,7 +21,13 @@ # SOFTWARE. --- line: 5 +# @todo #3744:60min Error Message Duplicates. +# As you can see, we have multiple error messages that are the +# same. We should remove duplicates and keep only meaningful error messages. message: >- + [5:2] error: 'Invalid object declaration' + * + ^ [5:2] error: 'Invalid object declaration' * ^ From 348d5b5a5f4534c47d92c7a4726aae0ec9af34da Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Wed, 15 Jan 2025 17:32:53 +0300 Subject: [PATCH 11/14] feat(#3744): fix all the code offences --- .../java/org/eolang/parser/EoParserErrors.java | 14 +++++++++++--- .../main/java/org/eolang/parser/XeEoListener.java | 4 +--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java b/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java index 0d2f21bb06..593a346681 100644 --- a/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java +++ b/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java @@ -69,8 +69,14 @@ private EoParserErrors(final List errors, final Lines lines) { this.lines = lines; } - // @checkstyle ParameterNumberCheck (10 lines) + // @checkstyle ParameterNumberCheck (20 lines) + // @checkstyle CyclomaticComplexityCheck (100 lines) + // @todo #3744:30min Simplify {@link EoParserErrors#syntaxError} method. + // The method is too complex and has a high cognitive complexity. We need to simplify it. + // Don't forget to remove the @checkstyle CyclomaticComplexityCheck annotation and + // the @SuppressWarnings("PMD.CognitiveComplexity") annotation. @Override + @SuppressWarnings("PMD.CognitiveComplexity") public void syntaxError( final Recognizer recognizer, final Object symbol, @@ -121,9 +127,11 @@ public void syntaxError( final String detailed; final String[] names = parser.getRuleNames(); if (names[EoParser.RULE_program].equals(rule)) { - detailed = "We expected the program to end here but encountered something unexpected"; + detailed = + "We expected the program to end here but encountered something unexpected"; } else if (names[EoParser.RULE_objects].equals(rule)) { - detailed = "We expected a list of objects here but encountered something unexpected"; + detailed = + "We expected a list of objects here but encountered something unexpected"; } else { detailed = msg; } diff --git a/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java b/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java index c267cf62da..2eecc3c489 100644 --- a/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java +++ b/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java @@ -28,10 +28,8 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.Optional; import java.util.function.Supplier; import java.util.stream.Collectors; -import javax.swing.text.html.Option; import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.tree.ErrorNode; @@ -1263,7 +1261,7 @@ private static String trimMargin(final String text, final int indent) { * Create parsing exception from given context. * @param ctx Context * @param msg Error message - * @return Parsing exception from current context + * @return Parsing exception from the current context */ private static ParsingException error(final ParserRuleContext ctx, final String msg) { return new ParsingException( From bf574579679cc3d49338f6cdcfdc775e8044afad Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Wed, 15 Jan 2025 17:33:21 +0300 Subject: [PATCH 12/14] feat(#3744): remove outdated puzzle --- .../org/eolang/parser/eo-typos/comment-in-method.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/comment-in-method.yaml b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/comment-in-method.yaml index 16af6a44eb..64dee51605 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/comment-in-method.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/comment-in-method.yaml @@ -21,9 +21,6 @@ # SOFTWARE. --- 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: |- [5:12] error: 'Invalid object declaration' sprintwf From 44c468afb9d8b6e8ef52be98f7b933155c6805d6 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Wed, 15 Jan 2025 17:53:47 +0300 Subject: [PATCH 13/14] feat(#3744): fix some unit tests in submodules --- .../src/test/java/org/eolang/maven/LintMojoTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/LintMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/LintMojoTest.java index 457a72dbcb..0272a34adf 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/LintMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/LintMojoTest.java @@ -146,7 +146,7 @@ void detectsCriticalErrorsSuccessfully(@Mktmp final Path temp) throws IOExceptio new XMLDocument( maven.result().get("target/2-shake/foo/x/main.xmir") ).nodes("//errors/error[@severity='critical']"), - Matchers.hasSize(1) + Matchers.hasSize(3) ); } From 8f0d2fe39582038c9ee0b715cdfb7cd2c5c1bdc4 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Wed, 15 Jan 2025 18:02:44 +0300 Subject: [PATCH 14/14] feat(#3744): remove trailing spaces --- .../org/eolang/parser/eo-typos/comment-in-method.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/comment-in-method.yaml b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/comment-in-method.yaml index 64dee51605..a62a2a7915 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/eo-typos/comment-in-method.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/eo-typos/comment-in-method.yaml @@ -24,10 +24,10 @@ line: 5 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: 'We expected the program to end here but encountered something unexpected' # a comment here is prohibited ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^