diff --git a/eo-parser/src/main/java/org/eolang/parser/DrErrors.java b/eo-parser/src/main/java/org/eolang/parser/DrErrors.java index f1d35741da..0835bb4c26 100644 --- a/eo-parser/src/main/java/org/eolang/parser/DrErrors.java +++ b/eo-parser/src/main/java/org/eolang/parser/DrErrors.java @@ -37,13 +37,13 @@ final class DrErrors implements Iterable { /** * Errors accumulated. */ - private final Errors errors; + private final Iterable errors; /** * Ctor. * @param errors The errors. */ - DrErrors(final Errors errors) { + DrErrors(final Iterable errors) { this.errors = errors; } @@ -61,7 +61,7 @@ public Iterator iterator() { .attr("line", error.line()) .attr("severity", "critical") .set(error.getMessage()), - this.errors.all() + this.errors ) ).iterator(); } 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 e233982411..aa9dc9d463 100644 --- a/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java +++ b/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java @@ -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; @@ -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 { /** * Errors accumulated. @@ -70,16 +70,6 @@ private EoParserErrors(final List errors, final Lines lines) { this.lines = lines; } - @Override - public List all() { - return Collections.unmodifiableList(this.errors); - } - - @Override - public int size() { - return this.errors.size(); - } - // @checkstyle ParameterNumberCheck (10 lines) @Override public void syntaxError( @@ -151,4 +141,9 @@ public void syntaxError( ); } } + + @Override + public Iterator iterator() { + return this.errors.iterator(); + } } diff --git a/eo-parser/src/main/java/org/eolang/parser/EoSyntax.java b/eo-parser/src/main/java/org/eolang/parser/EoSyntax.java index 35e161a4b9..7b3be07cdd 100644 --- a/eo-parser/src/main/java/org/eolang/parser/EoSyntax.java +++ b/eo-parser/src/main/java/org/eolang/parser/EoSyntax.java @@ -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; @@ -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", @@ -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; diff --git a/eo-parser/src/main/java/org/eolang/parser/Errors.java b/eo-parser/src/main/java/org/eolang/parser/Errors.java deleted file mode 100644 index 645951fb71..0000000000 --- a/eo-parser/src/main/java/org/eolang/parser/Errors.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2016-2024 Objectionary.com - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package org.eolang.parser; - -import java.util.List; - -/** - * All parsing errors. - * @since 0.50 - */ -interface Errors { - - /** - * All errors as a list of exceptions. - * @return The list of exceptions. - */ - List all(); - - /** - * The number of errors. - * @return The number of errors - */ - int size(); - -} 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 1bb8cc0909..8c765869c7 100644 --- a/eo-parser/src/main/java/org/eolang/parser/GeneralErrors.java +++ b/eo-parser/src/main/java/org/eolang/parser/GeneralErrors.java @@ -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; @@ -37,7 +37,7 @@ * * @since 0.30.0 */ -final class GeneralErrors extends BaseErrorListener implements Errors { +final class GeneralErrors extends BaseErrorListener implements Iterable { /** * Errors accumulated. @@ -98,12 +98,7 @@ public void syntaxError( } @Override - public List all() { - return Collections.unmodifiableList(this.errors); - } - - @Override - public int size() { - return this.errors.size(); + public Iterator iterator() { + return this.errors.iterator(); } } diff --git a/eo-parser/src/main/java/org/eolang/parser/PhiSyntax.java b/eo-parser/src/main/java/org/eolang/parser/PhiSyntax.java index dfd6ffede3..37d6a8f275 100644 --- a/eo-parser/src/main/java/org/eolang/parser/PhiSyntax.java +++ b/eo-parser/src/main/java/org/eolang/parser/PhiSyntax.java @@ -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; @@ -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;