Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#3742): Split ParsingErrors on Two Separate Classes #3751

Merged
merged 11 commits into from
Dec 25, 2024
Prev Previous commit
Next Next commit
feat(#3742): add Error interface to conform the review suggestions
  • Loading branch information
volodya-lombrozo committed Dec 25, 2024
commit fbbaa29e8b8c67eb40ea9862e3ea67a19dd578c1
7 changes: 3 additions & 4 deletions eo-parser/src/main/java/org/eolang/parser/DrErrors.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
package org.eolang.parser;

import java.util.Iterator;
import java.util.List;
import org.cactoos.iterable.Mapped;
import org.xembly.Directive;
import org.xembly.Directives;
Expand All @@ -38,13 +37,13 @@ final class DrErrors implements Iterable<Directive> {
/**
* Errors accumulated.
*/
private final List<ParsingException> errors;
private final Errors errors;

/**
* Ctor.
* @param errors The errors.
*/
DrErrors(final List<ParsingException> errors) {
DrErrors(final Errors errors) {
this.errors = errors;
yegor256 marked this conversation as resolved.
Show resolved Hide resolved
}

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

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import org.antlr.v4.runtime.BaseErrorListener;
Expand All @@ -34,13 +35,12 @@
import org.antlr.v4.runtime.Recognizer;
import org.antlr.v4.runtime.Token;
import org.cactoos.Text;
import org.xembly.Directive;

/**
* Accumulates all parsing errors related to EO parser.
* @since 0.50
*/
final class EoParserErrors extends BaseErrorListener {
final class EoParserErrors extends BaseErrorListener implements Errors {

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

/**
* The number of errors.
* @return The number of errors.
*/
public int size() {
return this.errors.size();
@Override
public List<ParsingException> all() {
return Collections.unmodifiableList(this.errors);
}

/**
* All errors accumulated as directives.
* @return The errors.
*/
public Iterable<Directive> directives() {
return new DrErrors(this.errors);
@Override
public int size() {
return this.errors.size();
}

// @checkstyle ParameterNumberCheck (10 lines)
Expand Down
2 changes: 1 addition & 1 deletion eo-parser/src/main/java/org/eolang/parser/EoSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public XML parsed() throws IOException {
final XML dom = Syntax.CANONICAL.pass(
new XMLDocument(
new Xembler(
new Directives(xel).append(spy.directives()).append(eospy.directives())
new Directives(xel).append(new DrErrors(spy)).append(new DrErrors(eospy))
).domQuietly()
)
);
Expand Down
46 changes: 46 additions & 0 deletions eo-parser/src/main/java/org/eolang/parser/Errors.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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<ParsingException> all();

/**
* The number of errors.
* @return The number of errors
*/
int size();

}
22 changes: 8 additions & 14 deletions eo-parser/src/main/java/org/eolang/parser/GeneralErrors.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@
package org.eolang.parser;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.antlr.v4.runtime.BaseErrorListener;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Recognizer;
import org.cactoos.Text;
import org.cactoos.list.ListOf;
import org.xembly.Directive;

/**
* Accumulates all parsing errors.
*
* @since 0.30.0
*/
final class GeneralErrors extends BaseErrorListener {
final class GeneralErrors extends BaseErrorListener implements Errors {

/**
* Errors accumulated.
Expand Down Expand Up @@ -97,19 +97,13 @@ public void syntaxError(
);
}

/**
* How many errors?
* @return Count of errors accumulated
*/
public int size() {
return this.errors.size();
@Override
public List<ParsingException> all() {
return Collections.unmodifiableList(this.errors);
}

/**
* All errors accumulated as directives.
* @return The errors
*/
public Iterable<Directive> directives() {
return new DrErrors(this.errors);
@Override
public int size() {
return this.errors.size();
}
}
2 changes: 1 addition & 1 deletion eo-parser/src/main/java/org/eolang/parser/PhiSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public XML parsed() throws IOException {
final XML dom = Syntax.CANONICAL.pass(
new XMLDocument(
new Xembler(
new Directives(xel).append(spy.directives()).append(this.extra)
new Directives(xel).append(new DrErrors(spy)).append(this.extra)
).domQuietly()
)
);
Expand Down
Loading