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 2e31882dec..16f3c8b369 100644 --- a/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java +++ b/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java @@ -26,7 +26,6 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.Objects; import org.antlr.v4.runtime.BaseErrorListener; import org.antlr.v4.runtime.InputMismatchException; import org.antlr.v4.runtime.NoViableAltException; @@ -111,13 +110,11 @@ public void syntaxError( Math.max(token.getStopIndex() - token.getStartIndex(), 1) ).formatted() ); - } else if (Objects.isNull(error)) { - msgs.add(new LocationMessage(line, position, msg).formatted()); } else { msgs.add(new LocationMessage(line, position, msg).formatted()); msgs.add(this.lines.line(line)); } - this.errors.add(new ParsingException(msg, error, line)); + this.errors.add(new ParsingException(error, line, msgs)); } @Override diff --git a/eo-parser/src/main/java/org/eolang/parser/GeneralErrors.java b/eo-parser/src/main/java/org/eolang/parser/GeneralErrors.java index 8c765869c7..b372e8762a 100644 --- a/eo-parser/src/main/java/org/eolang/parser/GeneralErrors.java +++ b/eo-parser/src/main/java/org/eolang/parser/GeneralErrors.java @@ -87,12 +87,10 @@ public void syntaxError( ) { this.errors.add( new ParsingException( - String.format( - "[%d:%d] %s: \"%s\"", - line, position, msg, this.lines.line(line) - ), error, - line + line, + new LocationMessage(line, position, msg).formatted(), + this.lines.line(line) ) ); } diff --git a/eo-parser/src/main/java/org/eolang/parser/ParsingException.java b/eo-parser/src/main/java/org/eolang/parser/ParsingException.java index b69621ca5a..0182070258 100644 --- a/eo-parser/src/main/java/org/eolang/parser/ParsingException.java +++ b/eo-parser/src/main/java/org/eolang/parser/ParsingException.java @@ -44,32 +44,34 @@ public final class ParsingException extends RuntimeException { /** * Ctor. - * @param msgs Messages - * @param cause The cause + * @param cause Cause of failure * @param line The place - * @since 0.1 + * @param msgs Messages */ - ParsingException(final List msgs, final Exception cause, final int line) { - this(String.join("\n", msgs), cause, line); + ParsingException(final Exception cause, final int line, final String... msgs) { + this(cause, line, List.of(msgs)); } - /** * Ctor. - * @param msg Message + * + * @param cause The cause * @param line The place + * @param msgs Messages + * @since 0.1 */ - ParsingException(final String msg, final int line) { - this(msg, null, line); + ParsingException(final Exception cause, final int line, final List msgs) { + this(cause, line, String.join("\n", msgs)); } /** * Ctor. - * @param msg Message + * * @param cause Cause of failure * @param line The place + * @param msg Message */ - ParsingException(final String msg, final Exception cause, final int line) { + ParsingException(final Exception cause, final int line, final String msg) { super(msg, cause); this.place = line; } @@ -81,5 +83,4 @@ public final class ParsingException extends RuntimeException { public int line() { return this.place; } - } diff --git a/eo-parser/src/main/java/org/eolang/parser/XePhiListener.java b/eo-parser/src/main/java/org/eolang/parser/XePhiListener.java index 4ed05bc80e..edad339442 100644 --- a/eo-parser/src/main/java/org/eolang/parser/XePhiListener.java +++ b/eo-parser/src/main/java/org/eolang/parser/XePhiListener.java @@ -298,9 +298,8 @@ public void enterDeltaBinding(final PhiParser.DeltaBindingContext ctx) { && !"bytes".equals(this.attributes.peek()) ) { throw new ParsingException( - "It's impossible to represent Δ ⤍ ∅ binding in EO", - new IllegalStateException(), - ctx.getStart().getLine() + new IllegalStateException(), ctx.getStart().getLine(), + "It's impossible to represent Δ ⤍ ∅ binding in EO" ); } } else {