Skip to content

Commit

Permalink
fix(objectionary#3629): listener errors
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon committed Dec 10, 2024
1 parent cd7587e commit 38b29a7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/mvn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ jobs:
echo multiplexing = false >> %USERPROFILE%\.cargo\config.toml
shell: cmd
- run: cargo --version
- run: mvn clean install -Pqulice --errors --batch-mode
- run: mvn clean install --errors --batch-mode
2 changes: 1 addition & 1 deletion eo-parser/src/main/antlr4/org/eolang/parser/Eo.g4
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ version
;

// Binding
as : COLON (NAME | INT_POSITIVE)
as : COLON (NAME | INT)
;

// Data
Expand Down
46 changes: 26 additions & 20 deletions eo-parser/src/main/java/org/eolang/parser/XeEoListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@

import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import org.antlr.v4.runtime.ParserRuleContext;
Expand Down Expand Up @@ -55,11 +57,6 @@
"PMD.GodClass"
})
public final class XeEoListener implements EoListener, Iterable<Directive> {
/**
* Meta for testing.
*/
private static final String TESTS_META = "tests";

/**
* The name of it.
*/
Expand All @@ -81,9 +78,9 @@ public final class XeEoListener implements EoListener, Iterable<Directive> {
private final long start;

/**
* If metas has "+tests" meta.
* Errors map.
*/
private boolean tests;
private final Map<ParserRuleContext, String> errors;

/**
* Ctor.
Expand All @@ -93,6 +90,7 @@ public final class XeEoListener implements EoListener, Iterable<Directive> {
public XeEoListener(final String name) {
this.name = name;
this.dirs = new Directives();
this.errors = new HashMap<>(0);
this.objects = new Objects.ObjXembly();
this.start = System.nanoTime();
}
Expand All @@ -107,8 +105,20 @@ public void enterProgram(final EoParser.ProgramContext ctx) {

@Override
public void exitProgram(final EoParser.ProgramContext ctx) {
this.dirs.xpath("/program").strict(1);
if (!this.errors.isEmpty()) {
this.dirs.addIf("errors").strict(1);
for (final Map.Entry<ParserRuleContext, String> error : this.errors.entrySet()) {
this.dirs
.add("error")
.attr("check", "eo-parser")
.attr("line", error.getKey().getStart().getLine())
.attr("severity", "critical")
.set(error.getValue());
}
this.dirs.up().up();
}
this.dirs
.xpath("/program")
.attr("ms", (System.nanoTime() - this.start) / (1000L * 1000L))
.up();
}
Expand Down Expand Up @@ -147,9 +157,6 @@ public void enterMetas(final EoParser.MetasContext ctx) {
for (final TerminalNode node : ctx.META()) {
final String[] pair = node.getText().split(" ", 2);
final String head = pair[0].substring(1);
if (XeEoListener.TESTS_META.equals(head)) {
this.tests = true;
}
this.dirs.add("meta")
.attr("line", node.getSymbol().getLine())
.add("head").set(head).up()
Expand Down Expand Up @@ -1143,7 +1150,11 @@ public void enterAs(final EoParser.AsContext ctx) {
if (ctx.NAME() != null) {
has = ctx.NAME().getText();
} else {
has = String.format("α%d", Integer.parseInt(ctx.INT_POSITIVE().getText()));
final int index = Integer.parseInt(ctx.INT().getText());
if (index < 0) {
this.errors.put(ctx, "Object binding can't be negative");
}
has = String.format("α%d", index);
}
this.objects.prop("as", has);
}
Expand Down Expand Up @@ -1194,14 +1205,9 @@ public void enterData(final EoParser.DataContext ctx) {
).getBytes(StandardCharsets.UTF_8)
);
} else {
throw new ParsingException(
String.format(
"Unknown data type at line #%d",
ctx.getStart().getLine()
),
new IllegalArgumentException(),
ctx.getStart().getLine()
);
base = "unknown";
data = ctx::getText;
this.errors.put(ctx, String.format("Unknown data type: %s", ctx.getText()));
}
this.objects.prop("base", base).data(data.get());
}
Expand Down

0 comments on commit 38b29a7

Please sign in to comment.