From 94c9b68ce1ce889b30d321a243d0ced663d18c32 Mon Sep 17 00:00:00 2001 From: maxonfjvipon Date: Wed, 25 Dec 2024 15:38:09 +0300 Subject: [PATCH 1/3] bug(#3757): Conservative PHI --- .../main/java/org/eolang/maven/PhiMojo.java | 4 +- .../src/main/java/org/eolang/parser/Xmir.java | 34 ++++++-- .../org/eolang/parser/phi/to-phi.xsl | 11 ++- .../test/java/org/eolang/parser/XmirTest.java | 13 +-- .../org/eolang/parser/phi-packs/as-phi.yaml | 4 +- .../org/eolang/parser/phi-packs/atoms.yaml | 9 +- .../eolang/parser/phi-packs/auto-named.yaml | 4 +- .../org/eolang/parser/phi-packs/bindings.yaml | 4 +- .../eolang/parser/phi-packs/bool-tests.yaml | 4 +- .../org/eolang/parser/phi-packs/bytes.yaml | 4 +- .../eolang/parser/phi-packs/custom-alias.yaml | 4 +- .../parser/phi-packs/data-dispatch.yaml | 4 +- .../eolang/parser/phi-packs/empty-bytes.yaml | 4 +- .../org/eolang/parser/phi-packs/empty.yaml | 4 +- .../org/eolang/parser/phi-packs/fibonaci.yaml | 4 +- .../parser/phi-packs/full-of-abstracts.yaml | 84 +++++++++++++++++++ .../eolang/parser/phi-packs/full-path.yaml | 4 +- .../parser/phi-packs/inline-bindings.yaml | 4 +- .../phi-packs/iterates-over-counter.yaml | 4 +- .../org/eolang/parser/phi-packs/jeo-part.yaml | 4 +- .../org/eolang/parser/phi-packs/method.yaml | 4 +- .../org/eolang/parser/phi-packs/nan-part.yaml | 4 +- .../parser/phi-packs/negative-inf-part.yaml | 4 +- .../org/eolang/parser/phi-packs/nested.yaml | 4 +- .../eolang/parser/phi-packs/number-part.yaml | 4 +- .../org/eolang/parser/phi-packs/one-byte.yaml | 4 +- .../org/eolang/parser/phi-packs/package.yaml | 4 +- .../parser/phi-packs/positive-inf-part.yaml | 4 +- .../parser/phi-packs/same-name-inner.yaml | 4 +- .../org/eolang/parser/phi-packs/specials.yaml | 4 +- .../eolang/parser/phi-packs/string-part.yaml | 4 +- .../phi-packs/with-anonym-abstract.yaml | 4 +- .../eolang/parser/phi-packs/with-data.yaml | 4 +- .../phi-packs/with-free-attributes.yaml | 4 +- 34 files changed, 188 insertions(+), 79 deletions(-) create mode 100644 eo-parser/src/test/resources/org/eolang/parser/phi-packs/full-of-abstracts.yaml diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/PhiMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/PhiMojo.java index 6bac910026..9c3fae0c91 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/PhiMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/PhiMojo.java @@ -165,9 +165,9 @@ private String translated(final XML xml) throws ImpossibleToPhiTranslationExcept final String phi; try { if (this.phiNoSugar) { - phi = xmir.toPhiNoSugar(); + phi = xmir.toSaltyPhi(); } else { - phi = xmir.toPhi(); + phi = xmir.toPhi(true); } } catch (final IndexOutOfBoundsException exception) { throw new ImpossibleToPhiTranslationException( diff --git a/eo-parser/src/main/java/org/eolang/parser/Xmir.java b/eo-parser/src/main/java/org/eolang/parser/Xmir.java index ac06160b48..5a061fc40c 100644 --- a/eo-parser/src/main/java/org/eolang/parser/Xmir.java +++ b/eo-parser/src/main/java/org/eolang/parser/Xmir.java @@ -59,6 +59,11 @@ */ @SuppressWarnings("PMD.TooManyMethods") public final class Xmir implements XML { + /** + * Unhex transformation. + */ + private static final Shift UNHEX = new StUnhex(); + /** * Train of transformations that prepare XMIR for conversion to EO. */ @@ -175,7 +180,7 @@ public Collection validate(final XML xsd) { /** * Converts XMIR to EO. - * @return EO representation as {@code String} + * @return EO representation as {@link String} */ public String toEO() { return this.converted( @@ -185,7 +190,7 @@ public String toEO() { /** * Converts XMIR to EO, in reverse notation. - * @return EO representation as {@code String} + * @return EO representation as {@link String} */ public String toReversedEO() { return this.converted( @@ -195,14 +200,27 @@ public String toReversedEO() { /** * Converts XMIR to PHI. - * @return EO representation as {@code String} + * @return PHI representation as {@link String} */ public String toPhi() { + return this.toPhi(false); + } + + /** + * Converts XMIR to PHI. + * @param conservative Add empty braces to formations or not + * @return PHI representation as {@link String}. + */ + public String toPhi(final boolean conservative) { return this.converted( new TrJoined<>( Xmir.FOR_PHI, new TrDefault<>( - new StUnhex(), new StClasspath("/org/eolang/parser/phi/to-phi.xsl") + Xmir.UNHEX, + new StClasspath( + "/org/eolang/parser/phi/to-phi.xsl", + String.format("conservative %b", conservative) + ) ) ), "program/phi/text()" @@ -211,9 +229,9 @@ public String toPhi() { /** * Converts XMIR to PHI without any syntax sugar. - * @return EO representation as {@code String} + * @return PHI representation as {@link String} */ - public String toPhiNoSugar() { + public String toSaltyPhi() { return this.converted( Xmir.FOR_PHI, "/org/eolang/parser/phi/to-phi-no-sugar.xsl", "program/phi/text()" ); @@ -224,7 +242,7 @@ public String toPhiNoSugar() { * @param train Train of transformations that prepares XMIR * @param xsl Final XSL transformation * @param xpath Xpath to retrieve the final result - * @return XMIR in other representation as {@code String}. + * @return XMIR in other representation as {@link String}. */ private String converted(final Train train, final String xsl, final String xpath) { return this.converted(new TrJoined<>(train.with(new StClasspath(xsl))), xpath); @@ -234,7 +252,7 @@ private String converted(final Train train, final String xsl, final Strin * Converts XMIR. * @param train Train of transformations that prepares XMIR * @param xpath Xpath to retrieve the final result - * @return XMIR in other representation as {@code String}. + * @return XMIR in other representation as {@link String}. */ private String converted(final Train train, final String xpath) { return new Xsline(train).pass(this.xml).xpath(xpath).get(0); diff --git a/eo-parser/src/main/resources/org/eolang/parser/phi/to-phi.xsl b/eo-parser/src/main/resources/org/eolang/parser/phi/to-phi.xsl index 2c4834c3d6..dad2514965 100644 --- a/eo-parser/src/main/resources/org/eolang/parser/phi/to-phi.xsl +++ b/eo-parser/src/main/resources/org/eolang/parser/phi/to-phi.xsl @@ -22,9 +22,10 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --> - + + @@ -288,6 +289,10 @@ SOFTWARE. + + + + @@ -511,7 +516,7 @@ SOFTWARE. - + @@ -568,7 +573,7 @@ SOFTWARE. - + diff --git a/eo-parser/src/test/java/org/eolang/parser/XmirTest.java b/eo-parser/src/test/java/org/eolang/parser/XmirTest.java index c80f6ef91f..619505c291 100644 --- a/eo-parser/src/test/java/org/eolang/parser/XmirTest.java +++ b/eo-parser/src/test/java/org/eolang/parser/XmirTest.java @@ -66,23 +66,24 @@ void printsToEoReversed(final String pack) throws IOException { @ParameterizedTest @ClasspathSource(value = "org/eolang/parser/phi-packs", glob = "**.yaml") - void convertsToPhi(final String pack) throws IOException { + void convertsToSweetPhi(final String pack) throws IOException { final Xtory xtory = new XtSticky(new XtYaml(pack)); + final boolean conservative = xtory.map().containsKey("conservative"); MatcherAssert.assertThat( "Result PHI should be equal to provided PHI with syntax sugar", - this.asXmir((String) xtory.map().get("input")).toPhi(), - Matchers.equalTo(xtory.map().get("with-sugar")) + this.asXmir((String) xtory.map().get("input")).toPhi(conservative), + Matchers.equalTo(xtory.map().get("sweet")) ); } @ParameterizedTest @ClasspathSource(value = "org/eolang/parser/phi-packs", glob = "**.yaml") - void convertsToPhiNoSugar(final String pack) throws IOException { + void convertsToSaltyPhi(final String pack) throws IOException { final Xtory xtory = new XtSticky(new XtYaml(pack)); MatcherAssert.assertThat( "Result PHI should be equal to provided PHI with syntax sugar", - this.asXmir((String) xtory.map().get("input")).toPhiNoSugar(), - Matchers.equalTo(xtory.map().get("no-sugar")) + this.asXmir((String) xtory.map().get("input")).toSaltyPhi(), + Matchers.equalTo(xtory.map().get("salty")) ); } diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/as-phi.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/as-phi.yaml index 80a180ddb7..feb50fb46c 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/as-phi.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/as-phi.yaml @@ -27,13 +27,13 @@ input: | length. as-phi $ $.greater-than 0 -with-sugar: |- +sweet: |- {⟦ prints-itself ↦ ⟦ φ ↦ Φ̇.assert-that(Φ̇.as-phi(ξ).length, ξ.greater-than(0)) ⟧ ⟧} -no-sugar: |- +salty: |- { ⟦ prints-itself ↦ ⟦ diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/atoms.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/atoms.yaml index f563e2383f..16077398d4 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/atoms.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/atoms.yaml @@ -24,27 +24,28 @@ input: | # No comments. [] > main /int # No comments. - [] > outer + [x] > outer # No comments. [] > inner /bytes -with-sugar: |- +sweet: |- {⟦ main ↦ ⟦ λ ⤍ Lmain ⟧, - outer ↦ ⟦ + outer(x) ↦ ⟦ inner ↦ ⟦ λ ⤍ Louter_inner ⟧ ⟧ ⟧} -no-sugar: |- +salty: |- { ⟦ main ↦ ⟦ λ ⤍ Lmain ⟧, outer ↦ ⟦ + x ↦ ∅, inner ↦ ⟦ λ ⤍ Louter_inner ⟧ diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/auto-named.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/auto-named.yaml index 61eb8bee38..087c3447ac 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/auto-named.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/auto-named.yaml @@ -26,7 +26,7 @@ input: | x > first [] >> 01- > b -with-sugar: |- +sweet: |- {⟦ object ↦ ⟦ first ↦ Φ̇.x(ξ.auto-named-attr-at-4-6), @@ -35,7 +35,7 @@ with-sugar: |- ⟧ ⟧ ⟧} -no-sugar: |- +salty: |- { ⟦ object ↦ ⟦ diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/bindings.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/bindings.yaml index 06f18c11bd..fe8a0a3d8d 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/bindings.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/bindings.yaml @@ -27,7 +27,7 @@ input: | w > @ 5:five "hello":3 -with-sugar: |- +sweet: |- {⟦ xyz ↦ Φ̇.x( attr ↦ Φ̇.y, @@ -38,7 +38,7 @@ with-sugar: |- α3 ↦ "hello" ) ⟧} -no-sugar: |- +salty: |- { ⟦ xyz ↦ Φ.org.eolang.x( diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/bool-tests.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/bool-tests.yaml index 2cf4a2af2a..0c5da0604e 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/bool-tests.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/bool-tests.yaml @@ -84,7 +84,7 @@ input: | 01-.as-bytes.eq true 00-.as-bytes.eq false -with-sugar: |- +sweet: |- {⟦ org ↦ ⟦ eolang ↦ ⟦ @@ -115,7 +115,7 @@ with-sugar: |- λ ⤍ Package ⟧ ⟧} -no-sugar: |- +salty: |- { ⟦ org ↦ ⟦ diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/bytes.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/bytes.yaml index 42632dcdf0..1be5df999f 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/bytes.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/bytes.yaml @@ -82,7 +82,7 @@ input: | # the current and the provided one, # as a new sequence. [b] > concat /bytes -with-sugar: |- +sweet: |- {⟦ org ↦ ⟦ eolang ↦ ⟦ @@ -138,7 +138,7 @@ with-sugar: |- λ ⤍ Package ⟧ ⟧} -no-sugar: |- +salty: |- { ⟦ org ↦ ⟦ diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/custom-alias.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/custom-alias.yaml index d80c027066..1aa2eab995 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/custom-alias.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/custom-alias.yaml @@ -27,7 +27,7 @@ input: | # No comments. [y] > main x y > z -with-sugar: |- +sweet: |- {⟦ foo ↦ ⟦ bar ↦ ⟦ @@ -39,7 +39,7 @@ with-sugar: |- λ ⤍ Package ⟧ ⟧} -no-sugar: |- +salty: |- { ⟦ foo ↦ ⟦ diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/data-dispatch.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/data-dispatch.yaml index 6a06659b6f..53018417c5 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/data-dispatch.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/data-dispatch.yaml @@ -23,12 +23,12 @@ input: | 5.plus 5 > ten "Hello".concat "world" > greetings -with-sugar: |- +sweet: |- {⟦ ten ↦ 5.plus(5), greetings ↦ "Hello".concat("world") ⟧} -no-sugar: |- +salty: |- { ⟦ ten ↦ Φ.org.eolang.number( diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/empty-bytes.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/empty-bytes.yaml index 7d42ee8174..92be451fe2 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/empty-bytes.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/empty-bytes.yaml @@ -21,11 +21,11 @@ # SOFTWARE. --- input: -- > empty -with-sugar: |- +sweet: |- {⟦ empty ↦ Φ̇.bytes(⟦ Δ ⤍ -- ⟧) ⟧} -no-sugar: |- +salty: |- { ⟦ empty ↦ Φ.org.eolang.bytes( diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/empty.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/empty.yaml index a2b85afde1..fc1b2d0c79 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/empty.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/empty.yaml @@ -26,14 +26,14 @@ input: | # No comments. [] > x seq > y -with-sugar: |- +sweet: |- {⟦ main(z) ↦ ⟦ x ↦ ⟦⟧, y ↦ Φ̇.seq ⟧ ⟧} -no-sugar: |- +salty: |- { ⟦ main ↦ ⟦ diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/fibonaci.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/fibonaci.yaml index 371bf26275..fcdec9773b 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/fibonaci.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/fibonaci.yaml @@ -35,7 +35,7 @@ input: | n.minus 1 fibonacci n.minus 2 -with-sugar: |- +sweet: |- {⟦ eo ↦ ⟦ example ↦ ⟦ @@ -49,7 +49,7 @@ with-sugar: |- λ ⤍ Package ⟧ ⟧} -no-sugar: |- +salty: |- { ⟦ eo ↦ ⟦ diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/full-of-abstracts.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/full-of-abstracts.yaml new file mode 100644 index 0000000000..3def042a73 --- /dev/null +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/full-of-abstracts.yaml @@ -0,0 +1,84 @@ +# The MIT License (MIT) +# +# Copyright (c) 2016-2024 Objectionary.com +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +--- +conservative: true +input: | + +package org.eolang + + # No comments. + [x] > foo + [] > empty + m > n + [y] > inner /number + bar > baz + [q] + a > b +sweet: |- + {⟦ + org() ↦ ⟦ + eolang() ↦ ⟦ + foo(x) ↦ ⟦ + empty() ↦ ⟦ + n ↦ Φ̇.m + ⟧, + inner(y) ↦ ⟦ + λ ⤍ Lorg_eolang_foo_inner + ⟧, + baz ↦ Φ̇.bar( + ⟦ + q ↦ ∅, + b ↦ Φ̇.a + ⟧ + ) + ⟧, + λ ⤍ Package + ⟧, + λ ⤍ Package + ⟧ + ⟧} +salty: |- + { + ⟦ + org ↦ ⟦ + eolang ↦ ⟦ + foo ↦ ⟦ + x ↦ ∅, + empty ↦ ⟦ + n ↦ Φ.org.eolang.m + ⟧, + inner ↦ ⟦ + λ ⤍ Lorg_eolang_foo_inner, + y ↦ ∅ + ⟧, + baz ↦ Φ.org.eolang.bar( + α0 ↦ ⟦ + q ↦ ∅, + b ↦ Φ.org.eolang.a + ⟧ + ) + ⟧, + λ ⤍ Package + ⟧, + λ ⤍ Package + ⟧ + ⟧ + } diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/full-path.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/full-path.yaml index 3aa176dad4..df9352feea 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/full-path.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/full-path.yaml @@ -23,12 +23,12 @@ input: | QQ.io.stdout > std Q.org.eolang.x > y -with-sugar: |- +sweet: |- {⟦ std ↦ Φ̇.io.stdout, y ↦ Φ̇.x ⟧} -no-sugar: |- +salty: |- { ⟦ std ↦ Φ.org.eolang.io.stdout, diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/inline-bindings.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/inline-bindings.yaml index 8b42ecef82..aa332c37e3 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/inline-bindings.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/inline-bindings.yaml @@ -25,11 +25,11 @@ input: | "f":0 "s":1 "t":2 -with-sugar: |- +sweet: |- {⟦ xyz ↦ Φ̇.x("f", "s", "t") ⟧} -no-sugar: |- +salty: |- { ⟦ xyz ↦ Φ.org.eolang.x( diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/iterates-over-counter.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/iterates-over-counter.yaml index be15d477ed..05d370f6b4 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/iterates-over-counter.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/iterates-over-counter.yaml @@ -35,7 +35,7 @@ input: | x.write > @ x.as-int.plus 1 11 -with-sugar: |- +sweet: |- {⟦ iterates-over-simple-counter ↦ ⟦ x ↦ Φ̇.memory(0), @@ -49,7 +49,7 @@ with-sugar: |- ) ⟧ ⟧} -no-sugar: |- +salty: |- { ⟦ iterates-over-simple-counter ↦ ⟦ diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/jeo-part.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/jeo-part.yaml index d3e7cac9e0..b295e06edc 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/jeo-part.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/jeo-part.yaml @@ -29,7 +29,7 @@ input: | "java/lang/Object" > supername * > interfaces "org/eolang/benchmark/F" -with-sugar: |- +sweet: |- {⟦ org ↦ ⟦ eolang ↦ ⟦ @@ -46,7 +46,7 @@ with-sugar: |- λ ⤍ Package ⟧ ⟧} -no-sugar: |- +salty: |- { ⟦ org ↦ ⟦ diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/method.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/method.yaml index ad155aeb13..dd796a5cb0 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/method.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/method.yaml @@ -21,11 +21,11 @@ # SOFTWARE. --- input: x.y.z > xyz -with-sugar: |- +sweet: |- {⟦ xyz ↦ Φ̇.x.y.z ⟧} -no-sugar: |- +salty: |- { ⟦ xyz ↦ Φ.org.eolang.x.y.z diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/nan-part.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/nan-part.yaml index 67c902373f..d579c29226 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/nan-part.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/nan-part.yaml @@ -24,13 +24,13 @@ input: | # Nan. [] > nan number 7F-F8-00-00-00-00-00-00 > @ -with-sugar: |- +sweet: |- {⟦ nan ↦ ⟦ φ ↦ Φ̇.number(Φ̇.bytes(⟦ Δ ⤍ 7F-F8-00-00-00-00-00-00 ⟧)) ⟧ ⟧} -no-sugar: |- +salty: |- { ⟦ nan ↦ ⟦ diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/negative-inf-part.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/negative-inf-part.yaml index 4e46f954db..9acc566967 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/negative-inf-part.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/negative-inf-part.yaml @@ -24,13 +24,13 @@ input: | # Foo. [] > negative-infinity number FF-F0-00-00-00-00-00-00 > @ -with-sugar: |- +sweet: |- {⟦ negative-infinity ↦ ⟦ φ ↦ Φ̇.number(Φ̇.bytes(⟦ Δ ⤍ FF-F0-00-00-00-00-00-00 ⟧)) ⟧ ⟧} -no-sugar: |- +salty: |- { ⟦ negative-infinity ↦ ⟦ diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/nested.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/nested.yaml index c2d3014ec5..8194e1c29c 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/nested.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/nested.yaml @@ -33,7 +33,7 @@ input: | main 5 > five a > b d > e -with-sugar: |- +sweet: |- {⟦ main(a) ↦ ⟦ x ↦ ⟦ @@ -48,7 +48,7 @@ with-sugar: |- ⟧ ⟧ ⟧} -no-sugar: |- +salty: |- { ⟦ main ↦ ⟦ diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/number-part.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/number-part.yaml index 93a63208b9..7797f689ee 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/number-part.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/number-part.yaml @@ -27,7 +27,7 @@ input: | # The `number` object is an abstraction of a 64-bit floating-point [as-bytes] > number $.times -1 > neg -with-sugar: |- +sweet: |- {⟦ org ↦ ⟦ eolang ↦ ⟦ @@ -39,7 +39,7 @@ with-sugar: |- λ ⤍ Package ⟧ ⟧} -no-sugar: |- +salty: |- { ⟦ org ↦ ⟦ diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/one-byte.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/one-byte.yaml index 5478c2cebd..1d4a6cecff 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/one-byte.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/one-byte.yaml @@ -21,11 +21,11 @@ # SOFTWARE. --- input: A2- > bts -with-sugar: |- +sweet: |- {⟦ bts ↦ Φ̇.bytes(⟦ Δ ⤍ A2- ⟧) ⟧} -no-sugar: |- +salty: |- { ⟦ bts ↦ Φ.org.eolang.bytes( diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/package.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/package.yaml index 994868dfd6..04cee86a37 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/package.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/package.yaml @@ -26,7 +26,7 @@ input: | # No comments. [] > main stdout > @ -with-sugar: |- +sweet: |- {⟦ foo ↦ ⟦ bar ↦ ⟦ @@ -41,7 +41,7 @@ with-sugar: |- λ ⤍ Package ⟧ ⟧} -no-sugar: |- +salty: |- { ⟦ foo ↦ ⟦ diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/positive-inf-part.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/positive-inf-part.yaml index fe4fd9b784..64a2e46e84 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/positive-inf-part.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/positive-inf-part.yaml @@ -24,13 +24,13 @@ input: | # Foo. [] > positive-infinity number 7F-F0-00-00-00-00-00-00 > @ -with-sugar: |- +sweet: |- {⟦ positive-infinity ↦ ⟦ φ ↦ Φ̇.number(Φ̇.bytes(⟦ Δ ⤍ 7F-F0-00-00-00-00-00-00 ⟧)) ⟧ ⟧} -no-sugar: |- +salty: |- { ⟦ positive-infinity ↦ ⟦ diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/same-name-inner.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/same-name-inner.yaml index 989f10027e..5c858ac571 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/same-name-inner.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/same-name-inner.yaml @@ -34,7 +34,7 @@ input: | # Long object 5. [] > long-object-name true > @ -with-sugar: |- +sweet: |- {⟦ compiles-correctly-with-long-duplicate-names ↦ ⟦ long-object-name ↦ ⟦ @@ -49,7 +49,7 @@ with-sugar: |- φ ↦ Φ̇.true ⟧ ⟧} -no-sugar: |- +salty: |- { ⟦ compiles-correctly-with-long-duplicate-names ↦ ⟦ diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/specials.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/specials.yaml index 877edb8e2f..28943c5cae 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/specials.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/specials.yaml @@ -26,7 +26,7 @@ input: | ^.x > x $.a > b @.@ > phi -with-sugar: |- +sweet: |- {⟦ main ↦ ⟦ x ↦ ξ.ρ.x, @@ -34,7 +34,7 @@ with-sugar: |- phi ↦ ξ.φ.φ ⟧ ⟧} -no-sugar: |- +salty: |- { ⟦ main ↦ ⟦ diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/string-part.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/string-part.yaml index 4fb1e9c328..058d2f5482 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/string-part.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/string-part.yaml @@ -38,7 +38,7 @@ input: | sprintf "Expected %d byte character at %d index, but there are not enough bytes for it: %x" * char-size index ^.^.as-bytes -with-sugar: |- +sweet: |- {⟦ org ↦ ⟦ eolang ↦ ⟦ @@ -63,7 +63,7 @@ with-sugar: |- λ ⤍ Package ⟧ ⟧} -no-sugar: |- +salty: |- { ⟦ org ↦ ⟦ diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/with-anonym-abstract.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/with-anonym-abstract.yaml index a894ebf522..f7982f04b4 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/with-anonym-abstract.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/with-anonym-abstract.yaml @@ -25,7 +25,7 @@ input: | [] > test ([] (^ > x)).plus > s int -with-sugar: |- +sweet: |- {⟦ test ↦ ⟦ s ↦ ⟦ @@ -33,7 +33,7 @@ with-sugar: |- ⟧.plus(Φ̇.int) ⟧ ⟧} -no-sugar: |- +salty: |- { ⟦ test ↦ ⟦ diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/with-data.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/with-data.yaml index ac00c21d6d..7a7ea6a85a 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/with-data.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/with-data.yaml @@ -23,12 +23,12 @@ input: |- 5 > five -0 > minus -with-sugar: |- +sweet: |- {⟦ five ↦ 5, minus ↦ -0 ⟧} -no-sugar: |- +salty: |- { ⟦ five ↦ Φ.org.eolang.number( diff --git a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/with-free-attributes.yaml b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/with-free-attributes.yaml index 9edd87ebc5..7957164442 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/phi-packs/with-free-attributes.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/phi-packs/with-free-attributes.yaml @@ -24,13 +24,13 @@ input: | # No comments. [a b] > c d > @ -with-sugar: |- +sweet: |- {⟦ c(a, b) ↦ ⟦ φ ↦ Φ̇.d ⟧ ⟧} -no-sugar: |- +salty: |- { ⟦ c ↦ ⟦ From 8b0478ff754bb3349b4e9deabb26dbc19a3cd35f Mon Sep 17 00:00:00 2001 From: maxonfjvipon Date: Wed, 25 Dec 2024 15:51:22 +0300 Subject: [PATCH 2/3] bug(#3757): param --- .../src/main/java/org/eolang/maven/PhiMojo.java | 7 ++++++- .../src/test/java/org/eolang/maven/FakeMaven.java | 1 + .../src/test/java/org/eolang/maven/PhiMojoTest.java | 5 +++-- .../src/test/java/org/eolang/maven/UnphiMojoTest.java | 3 ++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/PhiMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/PhiMojo.java index 9c3fae0c91..6ae2f84cea 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/PhiMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/PhiMojo.java @@ -76,6 +76,11 @@ public final class PhiMojo extends SafeMojo { ) private File phiOutputDir; + /** + * Print all the braces in sweet notation. + */ + private boolean conservative = true; + /** * Convert to PHI without syntax sugar. * @checkstyle MemberNameCheck (10 lines) @@ -167,7 +172,7 @@ private String translated(final XML xml) throws ImpossibleToPhiTranslationExcept if (this.phiNoSugar) { phi = xmir.toSaltyPhi(); } else { - phi = xmir.toPhi(true); + phi = xmir.toPhi(this.conservative); } } catch (final IndexOutOfBoundsException exception) { throw new ImpossibleToPhiTranslationException( diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/FakeMaven.java b/eo-maven-plugin/src/test/java/org/eolang/maven/FakeMaven.java index f04ba7c505..eac0facc12 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/FakeMaven.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/FakeMaven.java @@ -240,6 +240,7 @@ public FakeMaven execute(final Class mojo) throws IO this.params.putIfAbsent("offline", false); this.params.putIfAbsent("phiNoSugar", false); this.params.putIfAbsent("phiSkipFailed", false); + this.params.putIfAbsent("conservative", false); this.params.putIfAbsent( "phiInputDir", this.workspace.absolute( diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/PhiMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/PhiMojoTest.java index 4352711366..774e3397c2 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/PhiMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/PhiMojoTest.java @@ -195,12 +195,13 @@ void checksPhiPacksWithSugar(final String pack, @Mktmp final Path temp) throws E new TextOf( new FakeMaven(temp) .withProgram(xtory.map().get("input").toString()) + .with("conservative", xtory.map().get("conservative") != null) .with("phiNoSugar", false) .execute(new FakeMaven.Phi()) .result() .get("target/phi/foo/x/main.phi") ).asString(), - Matchers.equalTo(xtory.map().get("with-sugar").toString()) + Matchers.equalTo(xtory.map().get("sweet").toString()) ); } @@ -219,7 +220,7 @@ void checksPhiPacksNoSugar(final String pack, @Mktmp final Path temp) throws Exc .result() .get("target/phi/foo/x/main.phi") ).asString(), - Matchers.equalTo(xtory.map().get("no-sugar").toString()) + Matchers.equalTo(xtory.map().get("salty").toString()) ); } } diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java index daf6dab59c..83c0abb551 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java @@ -235,7 +235,7 @@ void checksUnphiPacks(final String pack, @Mktmp final Path temp) throws Exceptio void convertsToXmirAndBack(final String pack, @Mktmp final Path temp) throws Exception { final Xtory xtory = new XtSticky(new XtYaml(pack)); Assumptions.assumeTrue(xtory.map().get("skip") == null); - final String phi = xtory.map().get("with-sugar").toString(); + final String phi = xtory.map().get("sweet").toString(); final String main = "target/phi/main.phi"; final Path path = Paths.get(main); new HmBase(temp).save(phi, path); @@ -244,6 +244,7 @@ void convertsToXmirAndBack(final String pack, @Mktmp final Path temp) throws Exc final Path xmir = temp.resolve(String.format("target/%s/main.xmir", ParseMojo.DIR)); maven.foreignTojos().add("name").withXmir(xmir); final Path result = maven + .with("conservative", xtory.map().get("conservative") != null) .execute(OptimizeMojo.class) .execute(PhiMojo.class) .result() From a6cc1e849fa73105581064fd36cb8910be803e12 Mon Sep 17 00:00:00 2001 From: maxonfjvipon Date: Wed, 25 Dec 2024 15:56:30 +0300 Subject: [PATCH 3/3] bug(#3757): PMD --- eo-maven-plugin/src/main/java/org/eolang/maven/PhiMojo.java | 1 + 1 file changed, 1 insertion(+) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/PhiMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/PhiMojo.java index 6ae2f84cea..9a61611821 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/PhiMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/PhiMojo.java @@ -79,6 +79,7 @@ public final class PhiMojo extends SafeMojo { /** * Print all the braces in sweet notation. */ + @SuppressWarnings("PMD.ImmutableField") private boolean conservative = true; /**