diff --git a/eo-parser/src/main/antlr4/org/eolang/parser/Eo.g4 b/eo-parser/src/main/antlr4/org/eolang/parser/Eo.g4 index 25e06e9108..5e599d23c7 100644 --- a/eo-parser/src/main/antlr4/org/eolang/parser/Eo.g4 +++ b/eo-parser/src/main/antlr4/org/eolang/parser/Eo.g4 @@ -94,12 +94,14 @@ application // must be horizontal only happlication : happlicationHead happlicationTail + | reversed happlicationTailReversed ; // Extended horizontal application // The head can contain elements in horizontal or vertical notations happlicationExtended : happlicationHeadExtended happlicationTailExtended + | reversed happlicationTailReversedExtended ; // Head of horizontal application @@ -121,7 +123,6 @@ happlicationHeadExtended applicable : STAR | (NAME | AT) COPY? - | reversed ; // Horizontal application tail @@ -130,6 +131,14 @@ happlicationTail | (SPACE happlicationArg)+ ; +happlicationTailReversed + : SPACE happlicationTailReversedFirst happlicationTail? + ; + +happlicationTailReversedFirst + : happlicationArg + ; + // Argument of horizontal application // Does not contain elements in vertical notation happlicationArg @@ -146,6 +155,14 @@ happlicationTailExtended | (SPACE happlicationArgExtended)+ ; +happlicationTailReversedExtended + : SPACE happlicationTailReversedExtendedFirst happlicationTailExtended? + ; + +happlicationTailReversedExtendedFirst + : happlicationArgExtended + ; + // Extended argument of horizontal application // Can contain elements in vertical notation happlicationArgExtended @@ -158,6 +175,7 @@ happlicationArgExtended // Vertical application vapplication : vapplicationHeadNamed vapplicationArgs + | reversed oname? vapplicationArgsReversed ; // Vertical application head @@ -183,6 +201,14 @@ vapplicationArgs UNTAB ; +vapplicationArgsReversed + : EOL + TAB + vapplicationArgUnbinded + ((EOL vapplicationArg?) | EOP) + UNTAB + ; + vapplicationArg : (vapplicationArgBinded (EOL | EOP))+ | (vapplicationArgUnbinded (EOL | EOP))+ @@ -194,6 +220,7 @@ vapplicationArgBinded | vapplicationArgHanonymBinded // horizontal anonym object | vapplicationArgHapplicationBinded // horizontal application | vapplicationHeadAs oname? vapplicationArgs // vertical application + | reversed as oname? vapplicationArgsReversed // reversed vertical application | just as oname? // Just an object reference with binding | methodAs oname? // Method with binding ; @@ -204,6 +231,7 @@ vapplicationArgUnbinded | vapplicationArgHanonymUnbinded // horizontal anonym object | vapplicationArgHapplicationUnbinded // horizontal application | vapplicationHeadNamed vapplicationArgs // vertical application + | reversed oname? vapplicationArgsReversed // reversed verical application | justNamed // Just an object reference | methodNamed // Method ; @@ -219,7 +247,7 @@ vapplicationArgHapplicationUnbinded // Vertical application head with binding vapplicationHeadAs - : (applicable | hmethodExtended | hmethodExtendedVersioned | versioned) as + : (applicable | hmethodOptional | versioned) as ; // Vertical anonym object as argument of vertical application @@ -284,7 +312,7 @@ methodNamed // Method with bindning methodAs - : (hmethodExtended | hmethodExtendedVersioned) as + : hmethodOptional as ; // Horizontal method @@ -294,6 +322,11 @@ hmethod : hmethodHead methodTail+ ; +hmethodOptional + : hmethodExtended + | hmethodExtendedVersioned + ; + // Extended horizontal method // The head can contain elements in vertical notation hmethodExtended @@ -346,18 +379,39 @@ vmethodVersioned // Head of vertical method can be: // 1. vertical method // 2. horizontal method -// 3. vertical application. Here, vertical application is split into 2 parts because -// vapplicationHead contains vmethod which leads to left recursion error. +// 3. vertical application // 4. horizontal application. The same logic as with a vertical application // 5. just an object reference vmethodHead - : vmethodHead (vmethodTail | vmethodTailVersioned) oname? // vmethod - | (hmethodExtended | hmethodExtendedVersioned) oname? // hmethod extended - | vmethodHead (vmethodTail | vmethodTailVersioned) oname? vapplicationArgs oname? // vmethod + vapplication - | (applicable | hmethodExtended | hmethodExtendedVersioned | versioned) oname? vapplicationArgs oname? // vapplication without vmethod in head - | vmethodHead (vmethodTail | vmethodTailVersioned) happlicationTailExtended oname? // vmethod + haplication - | (applicable | hmethodExtended) happlicationTailExtended oname? // happlication without vmethod in head - | justNamed // just + : vmethodHead vmethodTailOptional vmethodHeadApplicationTail + | vmethodHeadHmethodExtended + | vmethodHeadVapplication + | vmethodHeadHapplication + | justNamed + ; + +vmethodTailOptional + : vmethodTail + | vmethodTailVersioned + ; + +vmethodHeadApplicationTail + : oname? vapplicationArgs? + | happlicationTailExtended oname? + ; + +vmethodHeadHmethodExtended + : hmethodOptional oname? + ; + +vmethodHeadVapplication + : (applicable | hmethodOptional | versioned) oname? vapplicationArgs + | reversed oname? vapplicationArgsReversed + ; + +vmethodHeadHapplication + : (applicable | hmethodExtended) happlicationTailExtended oname? + | reversed happlicationTailReversedExtended oname? ; // Tail of vertical method diff --git a/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java b/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java index cd1ad99fc8..f1f2cbc170 100644 --- a/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java +++ b/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java @@ -329,27 +329,25 @@ public void exitHapplicationHeadExtended( @Override @SuppressWarnings("PMD.ConfusingTernary") public void enterApplicable(final EoParser.ApplicableContext ctx) { - if (ctx.reversed() == null) { - this.startObject(ctx); - final String base; - if (ctx.STAR() != null) { - base = "tuple"; - this.objects.prop("star"); - } else if (ctx.NAME() != null) { - base = ctx.NAME().getText(); - } else if (ctx.AT() != null) { - base = "@"; - } else { - base = ""; - } - if (!base.isEmpty()) { - this.objects.prop("base", base); - } - if (ctx.COPY() != null) { - this.objects.prop("copy"); - } - this.objects.leave(); + this.startObject(ctx); + final String base; + if (ctx.STAR() != null) { + base = "tuple"; + this.objects.prop("star"); + } else if (ctx.NAME() != null) { + base = ctx.NAME().getText(); + } else if (ctx.AT() != null) { + base = "@"; + } else { + base = ""; + } + if (!base.isEmpty()) { + this.objects.prop("base", base); + } + if (ctx.COPY() != null) { + this.objects.prop("copy"); } + this.objects.leave(); } @Override @@ -367,6 +365,26 @@ public void exitHapplicationTail(final EoParser.HapplicationTailContext ctx) { this.objects.leave(); } + @Override + public void enterHapplicationTailReversed(final EoParser.HapplicationTailReversedContext ctx) { + // Nothing here + } + + @Override + public void exitHapplicationTailReversed(final EoParser.HapplicationTailReversedContext ctx) { + // Nothing here + } + + @Override + public void enterHapplicationTailReversedFirst(final EoParser.HapplicationTailReversedFirstContext ctx) { + this.objects.enter(); + } + + @Override + public void exitHapplicationTailReversedFirst(final EoParser.HapplicationTailReversedFirstContext ctx) { + this.objects.leave(); + } + @Override public void enterHapplicationArg(final EoParser.HapplicationArgContext ctx) { // Nothing here @@ -391,6 +409,26 @@ public void exitHapplicationTailExtended( this.objects.leave(); } + @Override + public void enterHapplicationTailReversedExtended(final EoParser.HapplicationTailReversedExtendedContext ctx) { + // Nothing here + } + + @Override + public void exitHapplicationTailReversedExtended(final EoParser.HapplicationTailReversedExtendedContext ctx) { + // Nothing here + } + + @Override + public void enterHapplicationTailReversedExtendedFirst(final EoParser.HapplicationTailReversedExtendedFirstContext ctx) { + this.objects.enter(); + } + + @Override + public void exitHapplicationTailReversedExtendedFirst(final EoParser.HapplicationTailReversedExtendedFirstContext ctx) { + this.objects.leave(); + } + @Override public void enterHapplicationArgExtended( final EoParser.HapplicationArgExtendedContext ctx @@ -437,12 +475,22 @@ public void exitVapplicationHeadNamed(final EoParser.VapplicationHeadNamedContex @Override public void enterVapplicationArgs(final EoParser.VapplicationArgsContext ctx) { - this.objects.enter(); + // Nothing here } @Override public void exitVapplicationArgs(final EoParser.VapplicationArgsContext ctx) { - this.objects.leave(); + // Nothing here + } + + @Override + public void enterVapplicationArgsReversed(final EoParser.VapplicationArgsReversedContext ctx) { + // Nothing here + } + + @Override + public void exitVapplicationArgsReversed(final EoParser.VapplicationArgsReversedContext ctx) { + // Nothing here } @Override @@ -457,22 +505,22 @@ public void exitVapplicationArg(final EoParser.VapplicationArgContext ctx) { @Override public void enterVapplicationArgBinded(final EoParser.VapplicationArgBindedContext ctx) { - // Nothing here + this.objects.enter(); } @Override public void exitVapplicationArgBinded(final EoParser.VapplicationArgBindedContext ctx) { - // Nothing here + this.objects.leave(); } @Override public void enterVapplicationArgUnbinded(final EoParser.VapplicationArgUnbindedContext ctx) { - // Nothing here + this.objects.enter(); } @Override public void exitVapplicationArgUnbinded(final EoParser.VapplicationArgUnbindedContext ctx) { - // Nothing here + this.objects.leave(); } @Override @@ -661,6 +709,16 @@ public void exitHmethod(final EoParser.HmethodContext ctx) { // Nothing here } + @Override + public void enterHmethodOptional(final EoParser.HmethodOptionalContext ctx) { + // Nothing here + } + + @Override + public void exitHmethodOptional(final EoParser.HmethodOptionalContext ctx) { + // Nothing here + } + @Override public void enterHmethodExtended(final EoParser.HmethodExtendedContext ctx) { // Nothing here @@ -745,6 +803,56 @@ public void exitVmethodHead(final EoParser.VmethodHeadContext ctx) { // Nothing here } + @Override + public void enterVmethodTailOptional(final EoParser.VmethodTailOptionalContext ctx) { + // Nothing here + } + + @Override + public void exitVmethodTailOptional(final EoParser.VmethodTailOptionalContext ctx) { + // Nothing here + } + + @Override + public void enterVmethodHeadApplicationTail(final EoParser.VmethodHeadApplicationTailContext ctx) { + // Nothing here + } + + @Override + public void exitVmethodHeadApplicationTail(final EoParser.VmethodHeadApplicationTailContext ctx) { + // Nothing here + } + + @Override + public void enterVmethodHeadHmethodExtended(final EoParser.VmethodHeadHmethodExtendedContext ctx) { + // Nothing here + } + + @Override + public void exitVmethodHeadHmethodExtended(final EoParser.VmethodHeadHmethodExtendedContext ctx) { + // Nothing here + } + + @Override + public void enterVmethodHeadVapplication(final EoParser.VmethodHeadVapplicationContext ctx) { + // Nothing here + } + + @Override + public void exitVmethodHeadVapplication(final EoParser.VmethodHeadVapplicationContext ctx) { + // Nothing here + } + + @Override + public void enterVmethodHeadHapplication(final EoParser.VmethodHeadHapplicationContext ctx) { + // Nothing here + } + + @Override + public void exitVmethodHeadHapplication(final EoParser.VmethodHeadHapplicationContext ctx) { + // Nothing here + } + @Override public void enterVmethodTail(final EoParser.VmethodTailContext ctx) { // Nothing here