Skip to content

Commit 95451ff

Browse files
authored
Merge pull request #4412 from h1alexbel/4386
bug(#4386): auto named formation with `\phi` object inside
2 parents b4ac96d + 822bcde commit 95451ff

File tree

5 files changed

+124
-3
lines changed

5 files changed

+124
-3
lines changed

eo-parser/src/main/antlr4/org/eolang/parser/Eo.g4

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void: NAME
128128
// - vertical
129129
// Ends on the next line
130130
application
131-
: happlicationExtended onameOrTname EOL
131+
: happlicationExtendedOrAphi onameOrTname EOL
132132
| vapplication
133133
;
134134

@@ -156,6 +156,20 @@ happlicationExtended
156156
| happlicationReversed
157157
;
158158

159+
// Application with auto-Phi formation
160+
onlyAphi
161+
: happlicationHeadExtended happlicationTail aphi?
162+
;
163+
164+
happlicationExtendedOrAphi
165+
: happlicationExtended | onlyAphi
166+
;
167+
168+
// Auto-Phi formation
169+
aphi
170+
: SPACE ARROW ARROW SPACE voids
171+
;
172+
159173
// Reversed horizontal application
160174
happlicationReversed
161175
: happlicationReversedHead happlicationTail?
@@ -269,7 +283,7 @@ vapplicationArgBound
269283
// Vertical application arguments with bindings
270284
// Ends on the current line
271285
vapplicationArgBoundCurrent
272-
: LB happlicationExtended RB as oname? // horizontal application
286+
: LB happlicationExtendedOrAphi RB as oname? // horizontal application
273287
| commentOptional LB hanonym RB as fname? // horizontal anonym object
274288
| (just | method) as oname? // just an object reference | method
275289
;
@@ -292,7 +306,7 @@ vapplicationArgUnbound
292306
// Vertical application arguments without bindings
293307
// Ends on the current line
294308
vapplicationArgUnboundCurrent
295-
: happlicationExtended oname? // horizontal application
309+
: happlicationExtendedOrAphi oname? // horizontal application
296310
| commentOptional hanonym fname? // horizontal anonym object
297311
| (just | method) oname? // just an object reference or method
298312
;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
3+
* SPDX-License-Identifier: MIT
4+
*/
5+
package org.eolang.parser;
6+
7+
import org.antlr.v4.runtime.ParserRuleContext;
8+
import org.cactoos.Text;
9+
10+
/**
11+
* Auto name for abstract object.
12+
* @since 0.57.4
13+
*/
14+
final class AutoName implements Text {
15+
16+
/**
17+
* The line number.
18+
*/
19+
private final int line;
20+
21+
/**
22+
* The Position in line.
23+
*/
24+
private final int position;
25+
26+
AutoName(final ParserRuleContext context) {
27+
this(context.getStart().getLine(), context.getStart().getCharPositionInLine());
28+
}
29+
30+
AutoName(final int lne, final int pos) {
31+
this.line = lne;
32+
this.position = pos;
33+
}
34+
35+
@Override
36+
public String asString() {
37+
return String.format("a\uD83C\uDF35%d%d", this.line, this.position);
38+
}
39+
}

eo-parser/src/main/java/org/eolang/parser/XeEoListener.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,42 @@ public void exitHapplicationExtended(final EoParser.HapplicationExtendedContext
371371
// Nothing here
372372
}
373373

374+
@Override
375+
public void enterOnlyAphi(final EoParser.OnlyAphiContext ctx) {
376+
this.startAbstract(ctx)
377+
.enter().prop("name", new AutoName(ctx).asString())
378+
.start(ctx)
379+
.prop(
380+
"base", String.format("$.%s", ctx.happlicationHeadExtended().getText())
381+
)
382+
.prop("name", "@");
383+
}
384+
385+
@Override
386+
public void exitOnlyAphi(final EoParser.OnlyAphiContext ctx) {
387+
// Nothing here
388+
}
389+
390+
@Override
391+
public void enterHapplicationExtendedOrAphi(final EoParser.HapplicationExtendedOrAphiContext ctx) {
392+
// Nothing here
393+
}
394+
395+
@Override
396+
public void exitHapplicationExtendedOrAphi(final EoParser.HapplicationExtendedOrAphiContext ctx) {
397+
// Nothing here
398+
}
399+
400+
@Override
401+
public void enterAphi(final EoParser.AphiContext ctx) {
402+
// Nothing here
403+
}
404+
405+
@Override
406+
public void exitAphi(final EoParser.AphiContext ctx) {
407+
// Nothing here
408+
}
409+
374410
@Override
375411
public void enterHapplicationReversed(final EoParser.HapplicationReversedContext ctx) {
376412
// Nothing here
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
2+
# SPDX-License-Identifier: MIT
3+
---
4+
# yamllint disable rule:line-length
5+
sheets: []
6+
asserts:
7+
- /object[not(errors)]
8+
- //o[not(@base) and @name='a🌵78' and o[@name='@']]
9+
- //o[not(@base) and @name='a🌵88' and o[@name='@']]
10+
input: |
11+
# No comments.
12+
[n] > app
13+
malloc.of > @
14+
8
15+
[m]
16+
while > @
17+
m.get.eq 42 >> [i]
18+
m.put 42 >> [i]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
2+
# SPDX-License-Identifier: MIT
3+
---
4+
# yamllint disable rule:line-length
5+
line: 4
6+
message: |-
7+
[4:19] error: 'Invalid object declaration'
8+
5.plus 5 >> [] +> test
9+
^
10+
input: |-
11+
# No comments.
12+
[] > x
13+
start > @
14+
5.plus 5 >> [] +> test

0 commit comments

Comments
 (0)