diff --git a/eo-parser/src/main/java/org/eolang/parser/DrEoParserErrors.java b/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java similarity index 93% rename from eo-parser/src/main/java/org/eolang/parser/DrEoParserErrors.java rename to eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java index fc9cc2a206..6947bdd204 100644 --- a/eo-parser/src/main/java/org/eolang/parser/DrEoParserErrors.java +++ b/eo-parser/src/main/java/org/eolang/parser/EoParserErrors.java @@ -24,7 +24,6 @@ package org.eolang.parser; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.Objects; import org.antlr.v4.runtime.BaseErrorListener; @@ -41,7 +40,7 @@ * Accumulates all parsing errors related to EO parser. * @since 0.50 */ -final class DrEoParserErrors extends BaseErrorListener implements Iterable { +final class EoParserErrors extends BaseErrorListener { /** * Errors accumulated. @@ -57,7 +56,7 @@ final class DrEoParserErrors extends BaseErrorListener implements Iterable src) { + EoParserErrors(final List src) { this(new ArrayList<>(0), new Lines(src)); } @@ -66,7 +65,7 @@ final class DrEoParserErrors extends BaseErrorListener implements Iterable errors, final Lines lines) { + private EoParserErrors(final List errors, final Lines lines) { this.errors = errors; this.lines = lines; } @@ -79,9 +78,12 @@ public int size() { return this.errors.size(); } - @Override - public Iterator iterator() { - return new DrErrors(this.errors).iterator(); + /** + * All errors accumulated as directives. + * @return The errors. + */ + public Iterable directives() { + return new DrErrors(this.errors); } // @checkstyle ParameterNumberCheck (10 lines) 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 b56dcca36b..e9b81129d4 100644 --- a/eo-parser/src/main/java/org/eolang/parser/EoSyntax.java +++ b/eo-parser/src/main/java/org/eolang/parser/EoSyntax.java @@ -105,7 +105,7 @@ public EoSyntax(final String nme, final Input ipt) { */ public XML parsed() throws IOException { final List lines = this.lines(); - final DrParsingErrors spy = new DrParsingErrors(lines); + final GeneralErrors spy = new GeneralErrors(lines); final EoLexer lexer = new EoIndentLexer(this.normalize()); lexer.removeErrorListeners(); lexer.addErrorListener(spy); @@ -113,14 +113,14 @@ public XML parsed() throws IOException { new CommonTokenStream(lexer) ); parser.removeErrorListeners(); - final DrEoParserErrors eospy = new DrEoParserErrors(lines); + final EoParserErrors eospy = new EoParserErrors(lines); parser.addErrorListener(eospy); final XeEoListener xel = new XeEoListener(this.name); new ParseTreeWalker().walk(xel, parser.program()); final XML dom = Syntax.CANONICAL.pass( new XMLDocument( new Xembler( - new Directives(xel).append(spy).append(eospy) + new Directives(xel).append(spy.directives()).append(eospy.directives()) ).domQuietly() ) ); diff --git a/eo-parser/src/main/java/org/eolang/parser/DrParsingErrors.java b/eo-parser/src/main/java/org/eolang/parser/GeneralErrors.java similarity index 87% rename from eo-parser/src/main/java/org/eolang/parser/DrParsingErrors.java rename to eo-parser/src/main/java/org/eolang/parser/GeneralErrors.java index e7fce89da3..ed1e383243 100644 --- a/eo-parser/src/main/java/org/eolang/parser/DrParsingErrors.java +++ b/eo-parser/src/main/java/org/eolang/parser/GeneralErrors.java @@ -24,7 +24,6 @@ package org.eolang.parser; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import org.antlr.v4.runtime.BaseErrorListener; import org.antlr.v4.runtime.RecognitionException; @@ -38,7 +37,7 @@ * * @since 0.30.0 */ -final class DrParsingErrors extends BaseErrorListener implements Iterable { +final class GeneralErrors extends BaseErrorListener { /** * Errors accumulated. @@ -54,7 +53,7 @@ final class DrParsingErrors extends BaseErrorListener implements Iterable(lines)); } @@ -62,7 +61,7 @@ final class DrParsingErrors extends BaseErrorListener implements Iterable src) { + GeneralErrors(final List src) { this(new ArrayList<>(0), new Lines(src)); } @@ -71,7 +70,7 @@ final class DrParsingErrors extends BaseErrorListener implements Iterable errors, final Lines lines) { + private GeneralErrors(final List errors, final Lines lines) { this.errors = errors; this.lines = lines; } @@ -98,11 +97,6 @@ public void syntaxError( ); } - @Override - public Iterator iterator() { - return new DrErrors(this.errors).iterator(); - } - /** * How many errors? * @return Count of errors accumulated @@ -110,4 +104,12 @@ public Iterator iterator() { public int size() { return this.errors.size(); } + + /** + * All errors accumulated as directives. + * @return The errors + */ + public Iterable directives() { + return new DrErrors(this.errors); + } } 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 0ec73009d5..e5f7ff98cf 100644 --- a/eo-parser/src/main/java/org/eolang/parser/PhiSyntax.java +++ b/eo-parser/src/main/java/org/eolang/parser/PhiSyntax.java @@ -91,7 +91,7 @@ public PhiSyntax( @Override public XML parsed() throws IOException { final XePhiListener xel = new XePhiListener(this.name); - final DrParsingErrors spy = new DrParsingErrors(this.input); + final GeneralErrors spy = new GeneralErrors(this.input); final PhiLexer lexer = new PhiLexer( CharStreams.fromStream( new InputStreamOf(this.input) diff --git a/eo-parser/src/main/java/org/eolang/parser/UnderlinedMessage.java b/eo-parser/src/main/java/org/eolang/parser/UnderlinedMessage.java index 08ddf2b511..a6f3a3ce2b 100644 --- a/eo-parser/src/main/java/org/eolang/parser/UnderlinedMessage.java +++ b/eo-parser/src/main/java/org/eolang/parser/UnderlinedMessage.java @@ -41,7 +41,7 @@ *

* @since 0.50 * @todo #3332:30min Add more decorators for the error message. - * For example, {@link DrParsingErrors} currently contains logic related to the message formatting. + * For example, {@link GeneralErrors} currently contains logic related to the message formatting. * It's better to create a separate class for this purpose. */ final class UnderlinedMessage { diff --git a/eo-parser/src/test/java/org/eolang/parser/UnderlinedMessageTest.java b/eo-parser/src/test/java/org/eolang/parser/UnderlinedMessageTest.java index a6c2a6da46..f7b2215c3d 100644 --- a/eo-parser/src/test/java/org/eolang/parser/UnderlinedMessageTest.java +++ b/eo-parser/src/test/java/org/eolang/parser/UnderlinedMessageTest.java @@ -24,7 +24,6 @@ package org.eolang.parser; import java.util.stream.Stream; -import org.eolang.parser.errors.UnderlinedMessage; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.jupiter.params.ParameterizedTest;