-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3751 from volodya-lombrozo/3742_errors
feat(#3742): Split `ParsingErrors` on Two Separate Classes
- Loading branch information
Showing
7 changed files
with
280 additions
and
76 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* 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.Iterator; | ||
import org.cactoos.iterable.Mapped; | ||
import org.xembly.Directive; | ||
import org.xembly.Directives; | ||
|
||
/** | ||
* Error directives. | ||
* @since 0.50 | ||
*/ | ||
final class DrErrors implements Iterable<Directive> { | ||
|
||
/** | ||
* Errors accumulated. | ||
*/ | ||
private final Iterable<ParsingException> errors; | ||
|
||
/** | ||
* Ctor. | ||
* @param errors The errors. | ||
*/ | ||
DrErrors(final Iterable<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(); | ||
} | ||
} |
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
104 changes: 104 additions & 0 deletions
104
eo-parser/src/main/java/org/eolang/parser/GeneralErrors.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,104 @@ | ||
/* | ||
* 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.ArrayList; | ||
import java.util.Iterator; | ||
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; | ||
|
||
/** | ||
* Accumulates all parsing errors. | ||
* | ||
* @since 0.30.0 | ||
*/ | ||
final class GeneralErrors extends BaseErrorListener implements Iterable<ParsingException> { | ||
|
||
/** | ||
* Errors accumulated. | ||
*/ | ||
private final List<ParsingException> errors; | ||
|
||
/** | ||
* The source. | ||
*/ | ||
private final Lines lines; | ||
|
||
/** | ||
* Ctor. | ||
* @param lines The source in lines | ||
*/ | ||
GeneralErrors(final Text... lines) { | ||
this(new ListOf<>(lines)); | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* @param src The source in lines | ||
*/ | ||
GeneralErrors(final List<Text> src) { | ||
this(new ArrayList<>(0), new Lines(src)); | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* @param errors Errors accumulated | ||
* @param lines The source in lines | ||
*/ | ||
private GeneralErrors(final List<ParsingException> errors, final Lines lines) { | ||
this.errors = errors; | ||
this.lines = lines; | ||
} | ||
|
||
// @checkstyle ParameterNumberCheck (10 lines) | ||
@Override | ||
public void syntaxError( | ||
final Recognizer<?, ?> recognizer, | ||
final Object symbol, | ||
final int line, | ||
final int position, | ||
final String msg, | ||
final RecognitionException error | ||
) { | ||
this.errors.add( | ||
new ParsingException( | ||
String.format( | ||
"[%d:%d] %s: \"%s\"", | ||
line, position, msg, this.lines.line(line) | ||
), | ||
error, | ||
line | ||
) | ||
); | ||
} | ||
|
||
@Override | ||
public Iterator<ParsingException> iterator() { | ||
return this.errors.iterator(); | ||
} | ||
} |
Oops, something went wrong.
71e3409
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
3706-8f2012b6
disappeared fromeo-parser/src/main/java/org/eolang/parser/ParsingErrors.java
), that's why I closed #3742. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.71e3409
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
3332-fa5220a9
disappeared fromeo-parser/src/main/java/org/eolang/parser/UnderlinedMessage.java
), that's why I closed #3707. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.71e3409
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
3332-6fa7c070
discovered ineo-parser/src/main/java/org/eolang/parser/UnderlinedMessage.java
) and submitted as #3756. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.