Skip to content

Commit

Permalink
Merge pull request #3633 from maxonfjvipon/fix/#3629/broken-as-binding
Browse files Browse the repository at this point in the history
fix(#3629): fixed broken `@as` binding
  • Loading branch information
yegor256 authored Dec 11, 2024
2 parents 4003356 + dfab3a6 commit 6aa9ba2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 21 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
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("α%s", ctx.INT().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
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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.
---
line: 4
input: |
# No comments
[] > foo
bar
42:-1

0 comments on commit 6aa9ba2

Please sign in to comment.