Skip to content

Commit

Permalink
Merge pull request #3578 from maxonfjvipon/feat/#3474/phi-data-syntax…
Browse files Browse the repository at this point in the history
…-sugar

feat(#3474): added syntax sugar for data
  • Loading branch information
yegor256 authored Nov 30, 2024
2 parents c0f64dd + e95f721 commit 175cffb
Show file tree
Hide file tree
Showing 26 changed files with 369 additions and 186 deletions.
27 changes: 14 additions & 13 deletions eo-maven-plugin/src/main/java/org/eolang/maven/PhiMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
import com.yegor256.xsline.Shift;
import com.yegor256.xsline.TrClasspath;
import com.yegor256.xsline.StClasspath;
import com.yegor256.xsline.TrDefault;
import com.yegor256.xsline.TrJoined;
import com.yegor256.xsline.Train;
import com.yegor256.xsline.Xsline;
Expand All @@ -41,12 +42,12 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.cactoos.experimental.Threads;
import org.cactoos.iterable.Mapped;
import org.cactoos.list.ListOf;
import org.cactoos.number.SumOf;
import org.cactoos.text.TextOf;
import org.eolang.maven.footprint.Saved;
import org.eolang.maven.util.Walk;
import org.eolang.parser.Schema;
import org.eolang.parser.StUnhex;
import org.eolang.parser.TrParsing;

/**
Expand All @@ -64,6 +65,15 @@ public final class PhiMojo extends SafeMojo {
*/
public static final String EXT = "phi";

/**
* Train of mandatory transformations.
*/
private static final Train<Shift> TRANSFORMATIONS = new TrDefault<>(
new StUnhex(),
new StClasspath("/org/eolang/maven/phi/incorrect-inners.xsl"),
new StClasspath("/org/eolang/maven/phi/to-phi.xsl")
);

/**
* The directory where to take xmir files for translation from.
* @checkstyle MemberNameCheck (10 lines)
Expand Down Expand Up @@ -183,18 +193,9 @@ private Train<Shift> train() {
if (this.phiOptimize) {
train = new TrParsing();
} else {
train = new com.yegor256.xsline.TrDefault<>();
train = new TrDefault<>();
}
final List<String> dependent = new ListOf<>(
"/org/eolang/maven/phi/incorrect-inners.xsl"
);
dependent.add("/org/eolang/maven/phi/to-phi.xsl");
return this.measured(
new TrJoined<>(
train,
new TrClasspath<>(dependent.toArray(new String[0])).back()
)
);
return this.measured(new TrJoined<>(train, PhiMojo.TRANSFORMATIONS));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ SOFTWARE.
</xsl:apply-templates>
</xsl:for-each>
</xsl:template>
<!-- Free attribute -->
<!-- Void attribute -->
<xsl:template match="o[parent::o[not(@base)] and not(@base) and not(@atom) and not(o)]">
<xsl:value-of select="./@name"/>
<xsl:value-of select="$arrow"/>
Expand Down Expand Up @@ -259,6 +259,9 @@ SOFTWARE.
</xsl:apply-templates>
<xsl:value-of select="eo:specials(@base, true())"/>
</xsl:when>
<xsl:when test="eo:has-data(.) and (@base='org.eolang.number' or @base='org.eolang.string')">
<xsl:value-of select="text()"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="eo:specials(@base, false())"/>
</xsl:otherwise>
Expand Down Expand Up @@ -300,7 +303,7 @@ SOFTWARE.
</xsl:otherwise>
</xsl:choose>
<!-- Data -->
<xsl:if test="eo:has-data(.)">
<xsl:if test="eo:has-data(.) and @base!='org.eolang.number' and @base!='org.eolang.string'">
<xsl:text>(</xsl:text>
<xsl:value-of select="eo:eol($tabs+1)"/>
<xsl:value-of select="$alpha"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ final class PhiMojoTest {
"# This is the default 64+ symbols comment in front of named abstract object.";

@Test
void convertsSimpleObjectToPhi(@Mktmp final Path temp,
@RandomProgram final String program) throws Exception {
void convertsSimpleObjectToPhi(@Mktmp final Path temp, @RandomProgram final String program)
throws Exception {
new Farea(temp).together(
f -> {
f.clean();
Expand All @@ -83,7 +83,7 @@ void convertsSimpleObjectToPhi(@Mktmp final Path temp,
),
StandardCharsets.UTF_8
),
Matchers.containsString("α0 ↦ ⟦ Δ ⤍ ")
Matchers.containsString("α0 ↦ \"Hello, world!\\n\"")
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ phi: |-
α0 ↦ ξ
).length,
α1 ↦ ξ.greater-than(
α0 ↦ Φ.org.eolang.number(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ 00-00-00-00-00-00-00-00 ⟧
)
)
α0 ↦ 0
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ phi: |-
z ↦ ∅,
φ ↦ Φ.org.eolang.w
⟧,
five ↦ Φ.org.eolang.number(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ 40-14-00-00-00-00-00-00 ⟧
)
)
five ↦ 5
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,7 @@ phi: |-
⟧,
compares-two-different-types ↦ ⟦
φ ↦ Φ.org.eolang.true.eq(
α0 ↦ Φ.org.eolang.number(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ 40-45-00-00-00-00-00-00 ⟧
)
)
α0 ↦ 42
).not
⟧,
compares-bool-to-bytes ↦ ⟦
Expand All @@ -121,18 +117,10 @@ phi: |-
⟧,
compares-bool-to-string ↦ ⟦
φ ↦ Φ.org.eolang.true.eq(
α0 ↦ Φ.org.eolang.string(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ 01- ⟧
)
)
α0 ↦ "\u0001"
).and(
α0 ↦ Φ.org.eolang.false.eq(
α0 ↦ Φ.org.eolang.string(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ 00- ⟧
)
)
α0 ↦ "\u0000"
)
)
⟧,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 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.
---
eo: |
5.plus 5 > ten
"Hello".concat "world" > greetings
phi: |-
{
ten ↦ 5.plus(
α0 ↦ 5
),
greetings ↦ "Hello".concat(
α0 ↦ "world"
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,17 @@ phi: |-
fibonacci ↦ ⟦
n ↦ ∅,
φ ↦ ξ.n.lt(
α0 ↦ Φ.org.eolang.number(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ 40-00-00-00-00-00-00-00 ⟧
)
)
α0 ↦ 2
).if(
α0 ↦ ξ.n,
α1 ↦ ξ.ρ.fibonacci(
α0 ↦ ξ.n.minus(
α0 ↦ Φ.org.eolang.number(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ 3F-F0-00-00-00-00-00-00 ⟧
)
)
α0 ↦ 1
)
).plus(
α0 ↦ ξ.ρ.fibonacci(
α0 ↦ ξ.n.minus(
α0 ↦ Φ.org.eolang.number(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ 40-00-00-00-00-00-00-00 ⟧
)
)
α0 ↦ 2
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,50 +40,26 @@ phi: |-
iterates-over-simple-counter ↦ ⟦
x ↦ Φ.org.eolang.memory(
α0 ↦ Φ.org.eolang.number(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ 00-00-00-00-00-00-00-00 ⟧
)
)
α0 ↦ 0
),
φ ↦ ξ.x.write(
α0 ↦ Φ.org.eolang.number(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ 40-14-00-00-00-00-00-00 ⟧
)
)
α0 ↦ 5
).eq(
α0 ↦ Φ.org.eolang.number(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ 40-14-00-00-00-00-00-00 ⟧
)
)
α0 ↦ 5
).and(
α0 ↦ ξ.x.as-int.lt(
α0 ↦ Φ.org.eolang.number(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ 40-24-00-00-00-00-00-00 ⟧
)
)
α0 ↦ 10
).while(
α0 ↦ ⟦
i ↦ ∅,
φ ↦ ξ.ρ.x.write(
α0 ↦ ξ.ρ.x.as-int.plus(
α0 ↦ Φ.org.eolang.number(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ 3F-F0-00-00-00-00-00-00 ⟧
)
)
α0 ↦ 1
)
)
).eq(
α0 ↦ Φ.org.eolang.number(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ 40-26-00-00-00-00-00-00 ⟧
)
)
α0 ↦ 11
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,11 @@ phi: |-
eolang ↦ ⟦
benchmark ↦ ⟦
j$A ↦ ⟦
access ↦ Φ.org.eolang.number(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ 40-40-00-00-00-00-00-00 ⟧
)
),
supername ↦ Φ.org.eolang.string(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ 6A-61-76-61-2F-6C-61-6E-67-2F-4F-62-6A-65-63-74 ⟧
)
),
access ↦ 32,
supername ↦ "java/lang/Object",
interfaces ↦ Φ.org.eolang.tuple(
α0 ↦ Φ.org.eolang.tuple.empty,
α1 ↦ Φ.org.eolang.string(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ 6F-72-67-2F-65-6F-6C-61-6E-67-2F-62-65-6E-63-68-6D-61-72-6B-2F-46 ⟧
)
)
α1 ↦ "org/eolang/benchmark/F"
)
⟧,
λ ⤍ Package
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ phi: |-
d ↦ ξ.ρ.ρ.a,
z ↦ ⟦
five ↦ ξ.ρ.ρ.ρ.ρ.main(
α0 ↦ Φ.org.eolang.number(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ 40-14-00-00-00-00-00-00 ⟧
)
)
α0 ↦ 5
),
b ↦ ξ.ρ.ρ.ρ.a,
e ↦ ξ.ρ.d
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
---
eo: 5 > five
eo: |-
5 > five
-0 > minus
phi: |-
{
five ↦ Φ.org.eolang.number(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ 40-14-00-00-00-00-00-00 ⟧
)
)
five ↦ 5,
minus ↦ -0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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.
---
origin: |
"""
z
y
x
""" > other
straight: |
"z\n y\n x" > other
reversed: |
"z\n y\n x" > other
Loading

0 comments on commit 175cffb

Please sign in to comment.