Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Nov 23, 2023
2 parents 4e2582b + 5321d7f commit 83cd88d
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

/**
* Read XMIR files and translate them to the phi-calculus expression.
* @since 0.33.0
* @since 0.34.0
*/
@Mojo(
name = "xmir-to-phi",
Expand Down
47 changes: 38 additions & 9 deletions eo-maven-plugin/src/main/resources/org/eolang/maven/phi/to-phi.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ SOFTWARE.
<xsl:variable name="arrow">
<select> ↦ </select>
</xsl:variable>
<xsl:variable name="dashed-arrow">
<select> ⤍ </select>
</xsl:variable>
<xsl:variable name="lb">
<select>⟦</select>
</xsl:variable>
<xsl:variable name="rb">
<select>⟧</select>
</xsl:variable>
<xsl:variable name="empty">
<select>∅</select>
</xsl:variable>
<!-- Functions -->
<xsl:function name="eo:specials">
<xsl:param name="n"/>
Expand Down Expand Up @@ -128,9 +140,26 @@ SOFTWARE.
</xsl:function>
<!-- Program -->
<xsl:template match="program">
<xsl:text>[</xsl:text>
<xsl:apply-templates select="objects"/>
<xsl:text>]</xsl:text>
<xsl:text>{</xsl:text>
<xsl:variable name="has-package" select="metas/meta/head[text()='package']"/>
<xsl:variable name="parts" select="tokenize(metas/meta[head[text()='package']]/tail[1], '\.')"/>
<xsl:choose>
<xsl:when test="$has-package">
<xsl:for-each select="$parts">
<xsl:value-of select="."/>
<xsl:value-of select="$arrow"/>
<xsl:value-of select="$lb"/>
</xsl:for-each>
<xsl:apply-templates select="objects"/>
<xsl:for-each select="$parts">
<xsl:value-of select="$rb"/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="objects"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text>}</xsl:text>
</xsl:template>
<!-- Objects -->
<xsl:template match="objects">
Expand All @@ -143,7 +172,7 @@ SOFTWARE.
<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"/>
<xsl:text>?</xsl:text>
<xsl:value-of select="$empty"/>
</xsl:template>
<!-- Just object -->
<xsl:template match="o[@base]">
Expand Down Expand Up @@ -184,7 +213,7 @@ SOFTWARE.
<xsl:if test="@data">
<xsl:text>(</xsl:text>
<xsl:value-of select="$delta"/>
<xsl:value-of select="$arrow"/>
<xsl:value-of select="$dashed-arrow"/>
<xsl:value-of select="eo:bytes(.)"/>
<xsl:text>)</xsl:text>
</xsl:if>
Expand All @@ -195,11 +224,11 @@ SOFTWARE.
<xsl:value-of select="eo:specials(@name)"/>
<xsl:value-of select="$arrow"/>
</xsl:if>
<xsl:text>[</xsl:text>
<xsl:value-of select="$lb"/>
<xsl:if test="@atom">
<xsl:value-of select="$lambda"/>
<xsl:value-of select="$arrow"/>
<xsl:text>lambda</xsl:text>
<xsl:value-of select="$dashed-arrow"/>
<xsl:text>Lambda</xsl:text>
<xsl:if test="count(o)&gt;0">
<xsl:text>, </xsl:text>
</xsl:if>
Expand All @@ -208,7 +237,7 @@ SOFTWARE.
<xsl:value-of select="eo:comma(position())"/>
<xsl:apply-templates select="."/>
</xsl:for-each>
<xsl:text>]</xsl:text>
<xsl:value-of select="$rb"/>
</xsl:template>
<!-- Application -->
<xsl:template match="o" mode="application">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@

/**
* Test cases for {@link PhiMojo}.
*
* @since 0.33.0
* @since 0.34.0
*/
class PhiMojoTest {
@Test
Expand Down Expand Up @@ -66,6 +65,10 @@ void createsFiles(@TempDir final Path temp) throws Exception {
void checksPhiPacks(final String pack, @TempDir final Path temp) throws Exception {
final Map<String, Object> map = new Yaml().load(pack);
MatcherAssert.assertThat(
String.format(
"Result phi expression should be equal to %s, but it doesn't",
map.get("phi").toString()
),
new TextOf(
new FakeMaven(temp)
.withProgram(map.get("eo").toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ eo: |
w > @
5
phi:
"[xyz ↦ Φ.org.eolang.x(attr ↦ Φ.org.eolang.y, α1 ↦ [z ↦ ?, φ ↦ Φ.org.eolang.w], α2 ↦ Φ.org.eolang.int(α0 ↦ Φ.org.eolang.bytes(Δ 00-00-00-00-00-00-00-05)))]"
"{xyz ↦ Φ.org.eolang.x(attr ↦ Φ.org.eolang.y, α1 ↦ z ↦ , φ ↦ Φ.org.eolang.w, α2 ↦ Φ.org.eolang.int(α0 ↦ Φ.org.eolang.bytes(Δ 00-00-00-00-00-00-00-05)))}"
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ eo: |
[] > outer
[] > inner /bytes
phi:
"[main ↦ [λ ↦ lambda], outer ↦ [inner ↦ [λ ↦ lambda]]]"
"{main ↦ ⟦λ ⤍ Lambda⟧, outer ↦ inner ↦ ⟦λ ⤍ Lambda⟧⟧}"
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
eo: -- > empty
phi: "[empty ↦ Φ.org.eolang.bytes(Δ --)]"
phi: "{empty ↦ Φ.org.eolang.bytes(Δ --)}"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ eo: |
QQ.io.stdout > std
Q.org.eolang.x > y
phi:
"[std ↦ Φ.org.eolang.io.stdout, y ↦ Φ.org.eolang.x]"
"{std ↦ Φ.org.eolang.io.stdout, y ↦ Φ.org.eolang.x}"
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
eo: x.y.z > xyz
phi: [xyz ↦ Φ.org.eolang.x.y.z]
phi: "{xyz ↦ Φ.org.eolang.x.y.z}"
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
eo: A2- > bts
phi: "[bts ↦ Φ.org.eolang.bytes(Δ A2-)]"
phi: "{bts ↦ Φ.org.eolang.bytes(Δ A2-)}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
eo: |
+package foo.bar.baz
[] > main
stdout > @
phi: "{foo ↦ ⟦bar ↦ ⟦baz ↦ ⟦main ↦ ⟦φ ↦ Φ.org.eolang.stdout⟧⟧⟧⟧}"
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ eo: |
$.a > a
< > vtx
^.< > self
phi: "[main ↦ [x ↦ ρ.x, h ↦ Φ.org.eolang.y.σ, a ↦ ρ.a, vtx ↦ ν, self ↦ ρ.ν]]"
phi: "{main ↦ x ↦ ρ.x, h ↦ Φ.org.eolang.y.σ, a ↦ ρ.a, vtx ↦ ν, self ↦ ρ.ν⟧}"
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
eo: 5 > five
phi: "[five ↦ Φ.org.eolang.int(α0 ↦ Φ.org.eolang.bytes(Δ 00-00-00-00-00-00-00-05))]"
phi: "{five ↦ Φ.org.eolang.int(α0 ↦ Φ.org.eolang.bytes(Δ 00-00-00-00-00-00-00-05))}"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ eo: |
[a b] > c
d > @
phi:
"[c ↦ [a ↦ ?, b ↦ ?, φ ↦ Φ.org.eolang.d]]"
"{c ↦ a ↦ , b ↦ , φ ↦ Φ.org.eolang.d⟧}"

0 comments on commit 83cd88d

Please sign in to comment.