From fa0128e40ac8707fe480da5778291e647cc4e48f Mon Sep 17 00:00:00 2001 From: maxonfjvipon Date: Fri, 12 Apr 2024 16:14:35 +0300 Subject: [PATCH 1/5] feat(#1871): grammar + listener --- .../src/main/antlr4/org/eolang/parser/Eo.g4 | 23 ++++++++++-- .../java/org/eolang/parser/XeEoListener.java | 36 +++++++++++++++++-- 2 files changed, 54 insertions(+), 5 deletions(-) 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 1f533e9d0d..f78404f273 100644 --- a/eo-parser/src/main/antlr4/org/eolang/parser/Eo.g4 +++ b/eo-parser/src/main/antlr4/org/eolang/parser/Eo.g4 @@ -265,6 +265,7 @@ vapplicationArgUnbound vapplicationArgUnboundCurrent : vapplicationArgHapplicationUnbound // horizontal application | vapplicationArgHanonymUnbound // horizontal anonym object + | onlyphi // unnamed abstract object with only @-bound attribute | justNamed // just an object reference | methodNamed // method ; @@ -336,6 +337,19 @@ hanonym : attributes hanonymInner+ ; +// Unnamed abstract object with only @-bound attribute +// x.y.z > [i] -> [i] (x.y.z > @) +// x y z > [i] -> [i] (x y z > @) +// [a] (b > c) > [i] -> [i] ([a] (b > c) > @) +// x > [i] -> [i] (x > @) +onlyphi + : (hmethod | happlication | hanonym | just) onlyphiTail + ; + +// Tail of the unnamed abstract object with only @-bound attribute +onlyphiTail: spacedArrow attributes + ; + // Inner object of horizontal anonym object // Does not contan elements in vertical notation hanonymInner @@ -424,11 +438,12 @@ vmethodOptional // 2. vertical application // 3. just an object reference // 4. vertical formation +// 5. unnamed abstract object with only @-bound attribute // Ends on the next line vmethodHead : vmethodHead methodTailOptional vmethodHeadApplicationTail | vmethodHeadVapplication - | justNamed EOL + | (justNamed | onlyphi) EOL | formationNamedOrNameless ; @@ -501,7 +516,11 @@ oname // Suffix suffix - : SPACE ARROW SPACE (PHI | NAME) + : spacedArrow (PHI | NAME) + ; + +spacedArrow + : SPACE ARROW SPACE ; // Simple scope 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 da9b1fab79..89db8cee40 100644 --- a/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java +++ b/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java @@ -828,6 +828,26 @@ public void exitHanonym(final EoParser.HanonymContext ctx) { // Nothing here } + @Override + public void enterOnlyphi(final EoParser.OnlyphiContext ctx) { + this.startAbstract(ctx).enter(); + } + + @Override + public void exitOnlyphi(final EoParser.OnlyphiContext ctx) { + // Nothing here + } + + @Override + public void enterOnlyphiTail(final EoParser.OnlyphiTailContext ctx) { + this.objects.enter().prop("name", "@").leave().leave(); + } + + @Override + public void exitOnlyphiTail(final EoParser.OnlyphiTailContext ctx) { + // Nothing here + } + @Override public void enterHanonymInner(final EoParser.HanonymInnerContext ctx) { this.objects.enter(); @@ -974,12 +994,12 @@ public void exitVmethodHead(final EoParser.VmethodHeadContext ctx) { @Override public void enterMethodTailOptional(final EoParser.MethodTailOptionalContext ctx) { - // Nothing here + // Nothing here } @Override public void exitMethodTailOptional(final EoParser.MethodTailOptionalContext ctx) { - // Nothing here + // Nothing here } @Override @@ -1142,6 +1162,16 @@ public void exitSuffix(final EoParser.SuffixContext ctx) { this.objects.leave(); } + @Override + public void enterSpacedArrow(final EoParser.SpacedArrowContext ctx) { + // Nothing here + } + + @Override + public void exitSpacedArrow(final EoParser.SpacedArrowContext ctx) { + // Nothing here + } + @Override public void enterScope(final EoParser.ScopeContext ctx) { // Nothing here @@ -1314,7 +1344,7 @@ private Objects startObject(final ParserRuleContext ctx) { * Start abstract object. * * @param ctx Context - * @return Xembly objects after creating abstract object + * @return Xembly objects after creating abstract object */ private Objects startAbstract(final ParserRuleContext ctx) { return this.startObject(ctx).prop("abstract").leave(); From 481407b4089e8478f4d0286a0ba08ef804ea3d3d Mon Sep 17 00:00:00 2001 From: maxonfjvipon Date: Fri, 12 Apr 2024 19:08:02 +0300 Subject: [PATCH 2/5] feat(#1871): rewrite some tests to prove that it works --- .../eolang/parser/packs/onlyphi-bound.yaml | 15 ++++++++++++ .../src/test/eo/org/eolang/cage-tests.eo | 3 +-- .../src/test/eo/org/eolang/goto-tests.eo | 3 +-- .../src/test/eo/org/eolang/memory-tests.eo | 20 ++++++---------- .../src/test/eo/org/eolang/try-tests.eo | 24 +++++++------------ .../src/test/eo/org/eolang/while-tests.eo | 4 ++-- 6 files changed, 34 insertions(+), 35 deletions(-) create mode 100644 eo-parser/src/test/resources/org/eolang/parser/packs/onlyphi-bound.yaml diff --git a/eo-parser/src/test/resources/org/eolang/parser/packs/onlyphi-bound.yaml b/eo-parser/src/test/resources/org/eolang/parser/packs/onlyphi-bound.yaml new file mode 100644 index 0000000000..f9aeb7ad58 --- /dev/null +++ b/eo-parser/src/test/resources/org/eolang/parser/packs/onlyphi-bound.yaml @@ -0,0 +1,15 @@ +xsls: [] +tests: + - //o[@base='a']/o[@abstract and not(@name) and o[@name='@' and @base='.b'] and o[not(@base) and @name='i']] + - //o[@base='a']/o[@abstract and not(@name) and o[@name='@' and @base='a' and o[@base='b']]] + - //o[@base='a']/o[@abstract and not(@name) and o[@abstract and @name='@' and o[@base='a' and @name='b']] and o[@name='c']] + - //o[@base='a']/o[@abstract and not(@name) and o[@base='d' and @name='@']] + - //o[@abstract and o[@base='z' and @name='@']]/following-sibling::o[@base='.x' and @method] +eo: | + a > x + a.b > [i] + a b > [] + [o] (a > b) > [c] + d > [] + z > [] + .x diff --git a/eo-runtime/src/test/eo/org/eolang/cage-tests.eo b/eo-runtime/src/test/eo/org/eolang/cage-tests.eo index 8edfb01334..7839ee545a 100644 --- a/eo-runtime/src/test/eo/org/eolang/cage-tests.eo +++ b/eo-runtime/src/test/eo/org/eolang/cage-tests.eo @@ -65,8 +65,7 @@ [] > stores-abstract-object-into-cage new. > c cage - [] - 112 > @ + 112 > [] c.eq 112 > @ # Test. diff --git a/eo-runtime/src/test/eo/org/eolang/goto-tests.eo b/eo-runtime/src/test/eo/org/eolang/goto-tests.eo index 0dc42d5241..8c0c649237 100644 --- a/eo-runtime/src/test/eo/org/eolang/goto-tests.eo +++ b/eo-runtime/src/test/eo/org/eolang/goto-tests.eo @@ -101,7 +101,6 @@ seq > @ * go.to - [g2] - g1.forward 42 > @ + g1.forward 42 > [g2] 7 42 diff --git a/eo-runtime/src/test/eo/org/eolang/memory-tests.eo b/eo-runtime/src/test/eo/org/eolang/memory-tests.eo index 521bea51e6..0c7eb2de40 100644 --- a/eo-runtime/src/test/eo/org/eolang/memory-tests.eo +++ b/eo-runtime/src/test/eo/org/eolang/memory-tests.eo @@ -132,10 +132,8 @@ and. > @ eq. try - [] - m.write 2556 > @ - [e] - e > @ + m.write 2556 > [] + e > [e] TRUE 2556 m.free @@ -146,10 +144,8 @@ and. > @ eq. try - [] - m.write 82.22 > @ - [e] - e > @ + m.write 82.22 > [] + e > [] TRUE 82.22 m.free @@ -160,10 +156,8 @@ and. > @ eq. try - [] - m.write "Prot" > @ - [e] - e > @ + m.write "Prot" > [] + e > [] TRUE "Proto" m.free @@ -188,5 +182,5 @@ m.free try m - [e] (QQ.io.stdout e > @) + QQ.io.stdout e > [e] FALSE diff --git a/eo-runtime/src/test/eo/org/eolang/try-tests.eo b/eo-runtime/src/test/eo/org/eolang/try-tests.eo index 30279adc68..b84af6bbfb 100644 --- a/eo-runtime/src/test/eo/org/eolang/try-tests.eo +++ b/eo-runtime/src/test/eo/org/eolang/try-tests.eo @@ -46,10 +46,8 @@ "some string" 7 5 - [e] - QQ.io.stdout e > @ - [] - FALSE > @ + QQ.io.stdout e > [e] + FALSE > [] # Test. [] > two-nested-try-blocks @@ -61,8 +59,7 @@ "some string" 7 5 - [e] - error e > @ + error e > [e] TRUE [e] QQ.io.stdout e > @ @@ -72,10 +69,8 @@ [] > try-without-error-block eq. > @ try - [] - 30.plus 2 > @ - [e] - e > @ + 30.plus 2 > [] + e > [e] TRUE 32 @@ -86,10 +81,8 @@ * m.write 1 try - [] - m.write (m.as-int.plus 1) > @ - [e] - e > @ + m.write (m.as-int.plus 1) > [] + e > [e] TRUE and. m.as-int.eq 2 @@ -107,8 +100,7 @@ * 5.div 0 m.write (m.plus 1) - [e] - e > @ + e > [e] TRUE and. m.eq 1 diff --git a/eo-runtime/src/test/eo/org/eolang/while-tests.eo b/eo-runtime/src/test/eo/org/eolang/while-tests.eo index dbd8fe514c..4f873d7246 100644 --- a/eo-runtime/src/test/eo/org/eolang/while-tests.eo +++ b/eo-runtime/src/test/eo/org/eolang/while-tests.eo @@ -30,7 +30,7 @@ [] > simple-while-with-false-first while > res FALSE - [i] (TRUE > @) + TRUE > [i] (bool res).not > @ # Test. @@ -38,7 +38,7 @@ (memory TRUE).alloc > condition while > res condition - [i] (condition.write FALSE > @) + condition.write FALSE > [i] and. > @ (bool res).not condition.free From fc3e82cdf2c294497f2d8ab1179df4e8e172e8b7 Mon Sep 17 00:00:00 2001 From: maxonfjvipon Date: Fri, 12 Apr 2024 20:03:02 +0300 Subject: [PATCH 3/5] feat(#1871): classes missedcount 8 --- eo-maven-plugin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo-maven-plugin/pom.xml b/eo-maven-plugin/pom.xml index a2bf09cc92..f58be17b99 100644 --- a/eo-maven-plugin/pom.xml +++ b/eo-maven-plugin/pom.xml @@ -463,7 +463,7 @@ SOFTWARE. CLASS MISSEDCOUNT - 6 + 8 From 61db6133b55abbc1c356cfcff579de86a92e2ff9 Mon Sep 17 00:00:00 2001 From: maxonfjvipon Date: Fri, 12 Apr 2024 20:19:38 +0300 Subject: [PATCH 4/5] feat(#1871): space --- eo-maven-plugin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo-maven-plugin/pom.xml b/eo-maven-plugin/pom.xml index f58be17b99..df47845fee 100644 --- a/eo-maven-plugin/pom.xml +++ b/eo-maven-plugin/pom.xml @@ -463,7 +463,7 @@ SOFTWARE. CLASS MISSEDCOUNT - 8 + 8 From 18bdbcf8c1b3d90e03cd52f8d1f878c93bbd83e3 Mon Sep 17 00:00:00 2001 From: maxonfjvipon Date: Fri, 12 Apr 2024 20:19:44 +0300 Subject: [PATCH 5/5] feat(#1871): back --- eo-maven-plugin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo-maven-plugin/pom.xml b/eo-maven-plugin/pom.xml index df47845fee..f58be17b99 100644 --- a/eo-maven-plugin/pom.xml +++ b/eo-maven-plugin/pom.xml @@ -463,7 +463,7 @@ SOFTWARE. CLASS MISSEDCOUNT - 8 + 8