Skip to content

Commit

Permalink
feat(#3742): remove Errors abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Dec 25, 2024
1 parent fbbaa29 commit d4764a6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 74 deletions.
6 changes: 3 additions & 3 deletions eo-parser/src/main/java/org/eolang/parser/DrErrors.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ final class DrErrors implements Iterable<Directive> {
/**
* Errors accumulated.
*/
private final Errors errors;
private final Iterable<ParsingException> errors;

/**
* Ctor.
* @param errors The errors.
*/
DrErrors(final Errors errors) {
DrErrors(final Iterable<ParsingException> errors) {
this.errors = errors;
}

Expand All @@ -61,7 +61,7 @@ public Iterator<Directive> iterator() {
.attr("line", error.line())
.attr("severity", "critical")
.set(error.getMessage()),
this.errors.all()
this.errors
)
).iterator();
}
Expand Down
19 changes: 7 additions & 12 deletions eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
package org.eolang.parser;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import org.antlr.v4.runtime.BaseErrorListener;
Expand All @@ -40,7 +40,7 @@
* Accumulates all parsing errors related to EO parser.
* @since 0.50
*/
final class EoParserErrors extends BaseErrorListener implements Errors {
final class EoParserErrors extends BaseErrorListener implements Iterable<ParsingException> {

/**
* Errors accumulated.
Expand Down Expand Up @@ -70,16 +70,6 @@ private EoParserErrors(final List<ParsingException> errors, final Lines lines) {
this.lines = lines;
}

@Override
public List<ParsingException> all() {
return Collections.unmodifiableList(this.errors);
}

@Override
public int size() {
return this.errors.size();
}

// @checkstyle ParameterNumberCheck (10 lines)
@Override
public void syntaxError(
Expand Down Expand Up @@ -151,4 +141,9 @@ public void syntaxError(
);
}
}

@Override
public Iterator<ParsingException> iterator() {
return this.errors.iterator();
}
}
8 changes: 6 additions & 2 deletions eo-parser/src/main/java/org/eolang/parser/EoSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import org.cactoos.Text;
import org.cactoos.io.InputOf;
import org.cactoos.list.ListOf;
import org.cactoos.scalar.LengthOf;
import org.cactoos.scalar.Unchecked;
import org.cactoos.text.FormattedText;
import org.cactoos.text.Joined;
import org.cactoos.text.Split;
Expand Down Expand Up @@ -124,7 +126,9 @@ public XML parsed() throws IOException {
).domQuietly()
)
);
if (spy.size() + eospy.size() == 0) {
final long errors = new Unchecked<>(new LengthOf(spy)).value()
+ new Unchecked<>(new LengthOf(eospy)).value();
if (errors == 0) {
Logger.debug(
this,
"The %s program of %d EO lines compiled, no errors",
Expand All @@ -133,7 +137,7 @@ public XML parsed() throws IOException {
} else {
Logger.debug(
this, "The %s program of %d EO lines compiled with %d error(s)",
this.name, lines.size(), spy.size() + eospy.size()
this.name, lines.size(), errors
);
}
return dom;
Expand Down
46 changes: 0 additions & 46 deletions eo-parser/src/main/java/org/eolang/parser/Errors.java

This file was deleted.

13 changes: 4 additions & 9 deletions eo-parser/src/main/java/org/eolang/parser/GeneralErrors.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
package org.eolang.parser;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.antlr.v4.runtime.BaseErrorListener;
import org.antlr.v4.runtime.RecognitionException;
Expand All @@ -37,7 +37,7 @@
*
* @since 0.30.0
*/
final class GeneralErrors extends BaseErrorListener implements Errors {
final class GeneralErrors extends BaseErrorListener implements Iterable<ParsingException> {

/**
* Errors accumulated.
Expand Down Expand Up @@ -98,12 +98,7 @@ public void syntaxError(
}

@Override
public List<ParsingException> all() {
return Collections.unmodifiableList(this.errors);
}

@Override
public int size() {
return this.errors.size();
public Iterator<ParsingException> iterator() {
return this.errors.iterator();
}
}
7 changes: 5 additions & 2 deletions eo-parser/src/main/java/org/eolang/parser/PhiSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import org.antlr.v4.runtime.tree.ParseTreeWalker;
import org.cactoos.Text;
import org.cactoos.io.InputStreamOf;
import org.cactoos.scalar.LengthOf;
import org.cactoos.scalar.Unchecked;
import org.xembly.Directive;
import org.xembly.Directives;
import org.xembly.Xembler;
Expand Down Expand Up @@ -111,12 +113,13 @@ public XML parsed() throws IOException {
).domQuietly()
)
);
if (spy.size() == 0) {
final long errors = new Unchecked<>(new LengthOf(spy)).value();
if (errors == 0) {
Logger.debug(this, "Input of PHI calculus compiled, no errors");
} else {
Logger.debug(
this, "Input of PHI calculus failed to compile (%d errors)",
spy.size()
errors
);
}
return dom;
Expand Down

0 comments on commit d4764a6

Please sign in to comment.