Skip to content

Commit

Permalink
feat(objectionary#3756): use message classes in the production code
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Dec 25, 2024
1 parent e399d30 commit 4e5f1f5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions eo-parser/src/main/java/org/eolang/parser/GeneralErrors.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
);
}
Expand Down
25 changes: 13 additions & 12 deletions eo-parser/src/main/java/org/eolang/parser/ParsingException.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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<String> 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;
}
Expand All @@ -81,5 +83,4 @@ public final class ParsingException extends RuntimeException {
public int line() {
return this.place;
}

}
5 changes: 2 additions & 3 deletions eo-parser/src/main/java/org/eolang/parser/XePhiListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4e5f1f5

Please sign in to comment.