Skip to content

Commit

Permalink
feat(objectionary#3744): fix the Eo grammar bug
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Jan 15, 2025
1 parent 669ef41 commit 475e929
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
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 @@ -47,7 +47,7 @@ metas
// Objects
// Ends on the next line
objects
: (object EOL?)* object
: (object EOL?)+
;

comment
Expand Down
15 changes: 11 additions & 4 deletions eo-parser/src/main/java/org/eolang/parser/XeEoListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import javax.swing.text.html.Option;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.tree.ErrorNode;
Expand Down Expand Up @@ -280,11 +282,16 @@ public void exitJustNamed(final EoParser.JustNamedContext ctx) {
}

@Override
@SuppressWarnings("PMD.ConfusingTernary")
public void enterAtom(final EoParser.AtomContext ctx) {
this.startObject(ctx)
.prop("atom", ctx.type().typeFqn().getText())
.leave();
final EoParser.TypeFqnContext fqn = ctx.type().typeFqn();
if (fqn == null) {
this.errors.add(XeEoListener.error(ctx, "Atom must have a type"));
this.startObject(ctx).leave();
} else {
this.startObject(ctx)
.prop("atom", fqn.getText())
.leave();
}
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions eo-parser/src/test/java/org/eolang/parser/EoSyntaxTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void printsProperListingEvenWhenSyntaxIsBroken() throws Exception {
"[] > x-н, 1\n"
);
MatcherAssert.assertThat(
EoIndentLexerTest.TO_ADD_MESSAGE,
"EO syntax is broken, but listing should be printed",
XhtmlMatchers.xhtml(
new String(
new EoSyntax(
Expand All @@ -100,7 +100,7 @@ void printsProperListingEvenWhenSyntaxIsBroken() throws Exception {
)
),
XhtmlMatchers.hasXPaths(
"/program/errors[count(error)=2]",
"/program/errors[count(error)=3]",
String.format("/program[listing='%s']", src)
)
);
Expand Down

0 comments on commit 475e929

Please sign in to comment.