Skip to content

Commit

Permalink
Merge pull request #3615 from maxonfjvipon/feat/#3607/org-eolang-shor…
Browse files Browse the repository at this point in the history
…ter-phi

feat(#3607): shorter 'org.eolang' in phi
  • Loading branch information
yegor256 authored Dec 5, 2024
2 parents 489435f + 2a7f62e commit 62c6db3
Show file tree
Hide file tree
Showing 24 changed files with 110 additions and 40 deletions.
3 changes: 2 additions & 1 deletion eo-maven-plugin/src/main/java/org/eolang/maven/PhiMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ public final class PhiMojo extends SafeMojo {
* Train of mandatory transformations.
*/
private static final Train<Shift> TRANSFORMATIONS = new TrDefault<>(
new StUnhex(),
new StClasspath("/org/eolang/maven/phi/incorrect-inners.xsl"),
new StUnhex(),
new StClasspath("/org/eolang/maven/phi/wrap-default-package.xsl"),
new StClasspath("/org/eolang/maven/phi/to-phi.xsl")
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ 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.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" id="incorrect-inners" version="2.0">
<xsl:stylesheet xmlns:eo="https://www.eolang.org" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" id="incorrect-inners" version="2.0">
<!--
Here we catch an elements which does not have @base attribute or which are not abstract
but have inner elements.
-->
<xsl:import href="/org/eolang/parser/_funcs.xsl"/>
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:template match="/program/errors">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<xsl:for-each select="//o[count(o)&gt;0 and not(@base) and not(@abstract) and not(@atom)]">
<xsl:for-each select="//o[count(o)&gt;0 and not(eo:abstract(.)) and not(@base)]">
<xsl:element name="error">
<xsl:attribute name="check">
<xsl:text>incorrect-inners</xsl:text>
Expand All @@ -45,7 +50,7 @@ SOFTWARE.
<xsl:attribute name="severity">
<xsl:text>critical</xsl:text>
</xsl:attribute>
<xsl:text>Element can't have child elements if it does not have 'base' or 'abstract' attribute</xsl:text>
<xsl:text>Element can't have child elements if it does not have 'base' attribute or if it isn't abstract</xsl:text>
<xsl:if test="@name">
<xsl:text>. Name of the object - </xsl:text>
<xsl:value-of select="@name"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ SOFTWARE.
<xsl:variable name="program">
<select>Φ</select>
</xsl:variable>
<xsl:variable name="def-package">
<select>Φ̇</select>
</xsl:variable>
<xsl:variable name="lambda">
<select>λ</select>
</xsl:variable>
Expand Down Expand Up @@ -118,9 +121,8 @@ SOFTWARE.
<xsl:value-of select="$program"/>
</xsl:when>
<xsl:when test="starts-with($n, 'org.eolang')">
<xsl:value-of select="$program"/>
<xsl:text>.</xsl:text>
<xsl:value-of select="$n"/>
<xsl:value-of select="$def-package"/>
<xsl:value-of select="substring-after($n, 'org.eolang')"/>
</xsl:when>
<xsl:when test="$aliases[text()=$n]">
<xsl:value-of select="$program"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<xsl:stylesheet xmlns:eo="https://www.eolang.org" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" id="wrap-default-package" version="2.0">
<!--
Here we change elements:
<o base=".eolang">
<o base=".org">
<o base="Q"/>
</o>
</o>
with:
<o base="org.eolang"/>
-->
<xsl:import href="/org/eolang/parser/_funcs.xsl"/>
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:template match="o[@base='.eolang' and o[1][@base='.org' and o[1][@base='Q']]]">
<xsl:element name="o">
<xsl:for-each select="@*[name()!='base']">
<xsl:attribute name="{name()}" select="."/>
</xsl:for-each>
<xsl:attribute name="base" select="'org.eolang'"/>
<xsl:for-each select="o[position()!=1]">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:element>
</xsl:template>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void convertsObjectWithSystemType(@Mktmp final Path temp) throws Exception {
Files.readString(temp.resolve("target/eo/phi/org/eolang/bytes.phi")),
Matchers.allOf(
Matchers.containsString("yes ↦ ξ.eq("),
Matchers.containsString("Φ.org.eolang.bytes(⟦ Δ ⤍ 01-02-03 ⟧)")
Matchers.containsString("Φ̇.bytes(⟦ Δ ⤍ 01-02-03 ⟧)")
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ phi: |-
{
prints-itself ↦ ⟦
φ ↦ Φ.org.eolang.assert-that(
Φ.org.eolang.as-phi(ξ).length, ξ.greater-than(0)
)
φ ↦ Φ̇.assert-that(Φ̇.as-phi(ξ).length, ξ.greater-than(0))
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ phi: |-
{
object ↦ ⟦
first ↦ Φ.org.eolang.x(ξ.auto-named-attr-at-4-6),
first ↦ Φ̇.x(ξ.auto-named-attr-at-4-6),
auto-named-attr-at-4-6 ↦ ⟦
b ↦ Φ.org.eolang.bytes(⟦ Δ ⤍ 01- ⟧)
b ↦ Φ̇.bytes(⟦ Δ ⤍ 01- ⟧)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ eo: |
phi: |-
{
xyz ↦ Φ.org.eolang.x(
attr ↦ Φ.org.eolang.y,
xyz ↦ Φ̇.x(
attr ↦ Φ̇.y,
abs ↦ ⟦
z ↦ ∅,
φ ↦ Φ.org.eolang.w
φ ↦ Φ̇.w
⟧,
five ↦ 5
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,25 @@ phi: |-
org ↦ ⟦
eolang ↦ ⟦
compares-two-bools ↦ ⟦
φ ↦ Φ.org.eolang.true.eq(Φ.org.eolang.true)
φ ↦ Φ̇.true.eq(Φ̇.true)
⟧,
true-as-bool ↦ ⟦
φ ↦ Φ.org.eolang.true.as-bool
φ ↦ Φ̇.true.as-bool
⟧,
compares-two-different-types ↦ ⟦
φ ↦ Φ.org.eolang.true.eq(42).not
φ ↦ Φ̇.true.eq(42).not
⟧,
compares-bool-to-bytes ↦ ⟦
φ ↦ Φ.org.eolang.true.eq(Φ.org.eolang.bytes(⟦ Δ ⤍ 01- ⟧)).and(
Φ.org.eolang.false.eq(Φ.org.eolang.bytes(⟦ Δ ⤍ 00- ⟧))
φ ↦ Φ̇.true.eq(Φ̇.bytes(⟦ Δ ⤍ 01- ⟧)).and(
Φ̇.false.eq(Φ̇.bytes(⟦ Δ ⤍ 00- ⟧))
)
⟧,
compares-bool-to-string ↦ ⟦
φ ↦ Φ.org.eolang.true.eq("\u0001").and(Φ.org.eolang.false.eq("\u0000"))
φ ↦ Φ̇.true.eq("\u0001").and(Φ̇.false.eq("\u0000"))
⟧,
compares-bool-to-bytes-reverse ↦ ⟦
φ ↦ Φ.org.eolang.bytes(⟦ Δ ⤍ 01- ⟧).as-bytes.eq(Φ.org.eolang.true).and(
Φ.org.eolang.bytes(⟦ Δ ⤍ 00- ⟧).as-bytes.eq(Φ.org.eolang.false)
φ ↦ Φ̇.bytes(⟦ Δ ⤍ 01- ⟧).as-bytes.eq(Φ̇.true).and(
Φ̇.bytes(⟦ Δ ⤍ 00- ⟧).as-bytes.eq(Φ̇.false)
)
⟧,
λ ⤍ Package
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ phi: |-
x ↦ ∅
⟧,
as-bool ↦ ⟦
φ ↦ ξ.ρ.eq(Φ.org.eolang.bytes(⟦ Δ ⤍ 01- ⟧))
φ ↦ ξ.ρ.eq(Φ̇.bytes(⟦ Δ ⤍ 01- ⟧))
⟧,
as-bytes ↦ ⟦
φ ↦ ξ.ρ
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ eo: -- > empty
phi: |-
{
empty ↦ Φ.org.eolang.bytes(⟦ Δ ⤍ -- ⟧)
empty ↦ Φ̇.bytes(⟦ Δ ⤍ -- ⟧)
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ phi: |-
main ↦ ⟦
z ↦ ∅,
x ↦ ⟦⟧,
y ↦ Φ.org.eolang.seq
y ↦ Φ̇.seq
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ eo: |
phi: |-
{
std ↦ Φ.org.eolang.io.stdout,
y ↦ Φ.org.eolang.x
std ↦ Φ̇.io.stdout,
y ↦ Φ̇.x
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ phi: |-
{
iterates-over-simple-counter ↦ ⟦
x ↦ Φ.org.eolang.memory(0),
x ↦ Φ̇.memory(0),
φ ↦ ξ.x.write(5).eq(5).and(
ξ.x.as-int.lt(10).while(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ phi: |-
j$A ↦ ⟦
access ↦ 32,
supername ↦ "java/lang/Object",
interfaces ↦ Φ.org.eolang.tuple(
Φ.org.eolang.tuple.empty, "org/eolang/benchmark/F"
)
interfaces ↦ Φ̇.tuple(Φ̇.tuple.empty, "org/eolang/benchmark/F")
⟧,
λ ⤍ Package
⟧,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ eo: x.y.z > xyz
phi: |-
{
xyz ↦ Φ.org.eolang.x.y.z
xyz ↦ Φ̇.x.y.z
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ eo: A2- > bts
phi: |-
{
bts ↦ Φ.org.eolang.bytes(⟦ Δ ⤍ A2- ⟧)
bts ↦ Φ̇.bytes(⟦ Δ ⤍ A2- ⟧)
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ phi: |-
bar ↦ ⟦
baz ↦ ⟦
main ↦ ⟦
φ ↦ Φ.org.eolang.stdout
φ ↦ Φ̇.stdout
⟧,
λ ⤍ Package
⟧,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ phi: |-
⟧,
φ ↦ Φ.org.eolang.true
φ ↦ Φ̇.true
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ phi: |-
test ↦ ⟦
s ↦ ⟦
x ↦ ξ.ρ
⟧.plus(Φ.org.eolang.int)
⟧.plus(Φ̇.int)
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ phi: |-
c ↦ ⟦
a ↦ ∅,
b ↦ ∅,
φ ↦ Φ.org.eolang.d
φ ↦ Φ̇.d
}
4 changes: 4 additions & 0 deletions eo-parser/src/main/antlr4/org/eolang/parser/Phi.g4
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ formation
scoped
: XI
| HOME
| DEF_PACKAGE
;

bindings
Expand Down Expand Up @@ -154,6 +155,9 @@ LAMBDA
;
HOME: 'Φ'
;
DEF_PACKAGE
: 'Φ̇'
;
ERROR
: ''
;
Expand Down
4 changes: 4 additions & 0 deletions eo-parser/src/main/java/org/eolang/parser/XePhiListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ public void exitFormation(final PhiParser.FormationContext ctx) {
public void enterScoped(final PhiParser.ScopedContext ctx) {
if (ctx.HOME() != null) {
this.objects().prop("base", "Q");
} else if (ctx.DEF_PACKAGE() != null) {
this.objects().prop("base", "Q").leave()
.start().prop("base", ".org").prop("method").leave()
.start().prop("base", ".eolang").prop("method");
} else {
this.objects().prop("base", "$");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
minus ↦ -0,
inline-application ↦ Φ.x(
"Hello", 42, Φ.y("world", 11.plus(12)), 42.5
)
),
default-package ↦ Φ̇.number(42)
⟧}

0 comments on commit 62c6db3

Please sign in to comment.