-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#3742): create a separate package for errors
- Loading branch information
1 parent
78f13fd
commit 9b44b6b
Showing
8 changed files
with
106 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
eo-parser/src/main/java/org/eolang/parser/errors/EoParserErrors.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.eolang.parser.errors; | ||
|
||
import java.util.Iterator; | ||
import org.antlr.v4.runtime.BaseErrorListener; | ||
import org.xembly.Directive; | ||
|
||
public final class EoParserErrors extends BaseErrorListener implements Iterable<Directive> { | ||
@Override | ||
public Iterator<Directive> iterator() { | ||
return null; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
eo-parser/src/main/java/org/eolang/parser/errors/ErrorDirectives.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.eolang.parser.errors; | ||
|
||
import java.util.Iterator; | ||
import java.util.List; | ||
import org.cactoos.iterable.Mapped; | ||
import org.eolang.parser.ParsingException; | ||
import org.xembly.Directive; | ||
import org.xembly.Directives; | ||
|
||
public final class ErrorDirectives implements Iterable<Directive> { | ||
|
||
/** | ||
* Errors accumulated. | ||
*/ | ||
private final List<ParsingException> errors; | ||
|
||
/** | ||
* Ctor. | ||
* @param errors The errors. | ||
*/ | ||
public ErrorDirectives(final List<ParsingException> errors) { | ||
this.errors = errors; | ||
} | ||
|
||
@Override | ||
public Iterator<Directive> iterator() { | ||
return new org.cactoos.iterable.Joined<>( | ||
new Mapped<Iterable<Directive>>( | ||
error -> new Directives() | ||
.xpath("/program") | ||
.strict(1) | ||
.addIf("errors") | ||
.strict(1) | ||
.add("error") | ||
.attr("check", "eo-parser") | ||
.attr("line", error.line()) | ||
.attr("severity", "critical") | ||
.set(error.getMessage()), | ||
this.errors | ||
) | ||
).iterator(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
eo-parser/src/main/java/org/eolang/parser/errors/Lines.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.eolang.parser.errors; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import org.cactoos.Text; | ||
import org.cactoos.text.UncheckedText; | ||
|
||
final class Lines { | ||
|
||
/** | ||
* The source. | ||
*/ | ||
private final List<Text> lines; | ||
|
||
Lines(final List<Text> lines) { | ||
this.lines = lines; | ||
} | ||
|
||
/** | ||
* Get the line by number. | ||
* @param number The line number. | ||
* @return The line. | ||
*/ | ||
Optional<String> line(final int number) { | ||
final Optional<String> result; | ||
if (number < 1 || number > this.lines.size()) { | ||
result = Optional.empty(); | ||
} else { | ||
result = Optional.ofNullable(this.lines.get(number - 1)) | ||
.map(UncheckedText::new) | ||
.map(UncheckedText::asString); | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters