Skip to content

Commit

Permalink
bug(#3619): merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon committed Dec 26, 2024
1 parent d878d64 commit 12f0d08
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions eo-parser/src/main/java/org/eolang/parser/XeEoListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,11 @@ public void enterCompactArray(final EoParser.CompactArrayContext ctx) {
|| num.length() > 1 && num.charAt(0) == '0'
|| Integer.parseInt(num) < 0
) {
this.errors.put(
ctx,
"Index after '*' must be a positive integer without leading zero or arithmetic signs"
this.errors.add(
XeEoListener.error(
ctx,
"Index after '*' must be a positive integer without leading zero or arithmetic signs"
)
);
}
final int number = Integer.parseInt(num);
Expand Down Expand Up @@ -1084,21 +1086,7 @@ public void enterAs(final EoParser.AsContext ctx) {
} else {
final int index = Integer.parseInt(ctx.INT().getText());
if (index < 0) {
this.errors.add(
new ParsingException(
ctx.getStart().getLine(),
new MsgLocated(
ctx.getStart().getLine(),
ctx.getStart().getCharPositionInLine(),
"Object binding can't be negative"
).formatted(),
new MsgUnderlined(
XeEoListener.line(ctx),
ctx.getStart().getCharPositionInLine(),
ctx.getText().length()
).formatted()
)
);
this.errors.add(XeEoListener.error(ctx, "Object binding can't be negative"));
}
has = String.format("α%d", index);
}
Expand Down Expand Up @@ -1252,6 +1240,28 @@ private static String trimMargin(final String text, final int indent) {
return res.toString();
}

/**
* Create parsing exception from given context.
* @param ctx Context
* @param msg Error message
* @return Parsing exception from current context
*/
private static ParsingException error(final ParserRuleContext ctx, final String msg) {
return new ParsingException(
ctx.getStart().getLine(),
new MsgLocated(
ctx.getStart().getLine(),
ctx.getStart().getCharPositionInLine(),
msg
).formatted(),
new MsgUnderlined(
XeEoListener.line(ctx),
ctx.getStart().getCharPositionInLine(),
ctx.getText().length()
).formatted()
);
}

/**
* Get line from context.
* @param ctx Context
Expand Down

0 comments on commit 12f0d08

Please sign in to comment.