Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2231 Broken head in syntax #2234

Merged
merged 11 commits into from
Jul 14, 2023
24 changes: 16 additions & 8 deletions eo-parser/src/main/antlr4/org/eolang/parser/Program.g4
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ objects
object
:
(
abstraction
(
abstraction
type?
)
|
application
)
Expand All @@ -52,10 +55,14 @@ abstraction
:
(COMMENT EOL)*
attributes
(
(suffix (SPACE SLASH (NAME | QUESTION))?)
| htail
)?
;

type
:
suffix
SPACE
SLASH
(NAME | QUESTION)?
;

attributes
Expand Down Expand Up @@ -133,6 +140,9 @@ application
head
version
|
abstraction
htail?
|
head
htail?
|
Expand All @@ -154,7 +164,6 @@ application
|
application
suffix
htail?
;

htail
Expand All @@ -180,6 +189,7 @@ htail
|
SPACE
abstraction
suffix?
)+
;

Expand Down Expand Up @@ -215,8 +225,6 @@ head
DOT
|
data
|
abstraction
)
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class RedundantParentheses implements Predicate<String> {
/**
* Pattern for string literals.
*/
private static final Pattern PATTERN = Pattern.compile("(?ms)\"\"\".*?\"\"\"|\".*?\"");
private static final Pattern PATTERN = Pattern.compile("(?ms)#.*?\\n|\"\"\".*?\"\"\"|\".*?\"");

/**
* The callback that will be called in case if redundant parentheses is found.
Expand Down
15 changes: 13 additions & 2 deletions eo-parser/src/main/java/org/eolang/parser/XeListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,29 @@ public void enterAbstraction(final ProgramParser.AbstractionContext ctx) {
ctx.getStart().getCharPositionInLine()
);
this.objects.prop("abstract", "");
this.objects.leave();
}

@Override
public void exitAbstraction(final ProgramParser.AbstractionContext ctx) {
// Nothing here
}

@Override
public void enterType(final ProgramParser.TypeContext ctx) {
if (ctx.SLASH() != null) {
this.objects.enter();
if (ctx.QUESTION() == null) {
this.objects.prop("atom", ctx.NAME());
} else {
this.objects.prop("atom", "?");
}
this.objects.leave();
}
this.objects.leave();
}

@Override
public void exitAbstraction(final ProgramParser.AbstractionContext ctx) {
public void exitType(final ProgramParser.TypeContext ctx) {
// Nothing here
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ static Stream<Arguments> testCases() {
Arguments.of("[] > foo\n \"Hello\".<.eq (\"Hello\".<)\n", true),
Arguments.of("[] > foo\n \"\"\"\n(-_-)\n\"\"\" > x", true),
Arguments.of("[] > foo\n add (-4) (-5)", true),
Arguments.of("# Comment().\n[] > obj\n", true),
Arguments.of("[] > foo\n (1.add (a.add 5) (4)) > x", false),
Arguments.of("[] > foo\n (1.add (a.add 5) 4) > x", false),
Arguments.of("[] > foo\n (1.add (a.add 5) 4)", false),
Expand Down
2 changes: 1 addition & 1 deletion eo-parser/src/test/java/org/eolang/parser/SyntaxTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void printsProperListingEvenWhenSyntaxIsBroken() throws Exception {
new String(baos.toByteArray(), StandardCharsets.UTF_8)
),
XhtmlMatchers.hasXPaths(
"/program/errors[count(error)=1]",
"/program/errors[count(error)=2]",
String.format("/program[listing='%s']", src)
)
);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# The syntax below is not supported, but it passes the test and
# no typos are detected. We should fix it. Most probably EOL-s
# are not detected at the end of objects correctly.
skip: true
line: 1
eo: |
[] > a [] > b [] > c [] > d hello world
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
line: 2
eo: |
[x] > first
a > x (b > x)
Loading