Skip to content

Commit

Permalink
fix(#3169): decapitalize auto named objects on phi
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon committed May 6, 2024
1 parent 19897d1 commit 7c0e03b
Show file tree
Hide file tree
Showing 20 changed files with 224 additions and 8 deletions.
29 changes: 21 additions & 8 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,8 +27,9 @@
import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
import com.yegor256.xsline.Shift;
import com.yegor256.xsline.StClasspath;
import com.yegor256.xsline.TrClasspath;
import com.yegor256.xsline.TrDefault;
import com.yegor256.xsline.TrJoined;
import com.yegor256.xsline.Train;
import com.yegor256.xsline.Xsline;
import java.io.File;
Expand Down Expand Up @@ -62,7 +63,15 @@ public final class PhiMojo extends SafeMojo {
/**
* Extension of the file where we put phi-calculus expression (.phi).
*/
public static final String EXT = "phi";
static final String EXT = "phi";

/**
* Sheets for converting to phi.
*/
private static final String[] SHEETS = {
"/org/eolang/maven/phi/decapitalize-auto-named.xsl",
"/org/eolang/maven/phi/to-phi.xsl",
};

/**
* The directory where to take xmir files for translation from.
Expand Down Expand Up @@ -98,12 +107,18 @@ public final class PhiMojo extends SafeMojo {
@Override
public void exec() {
final Home home = new HmBase(this.phiOutputDir);
final Train<Shift> train;
final Train<Shift> def;
if (this.phiOptimize) {
train = new ParsingTrain();
def = new ParsingTrain();
} else {
train = new TrDefault<>();
def = new TrDefault<>();
}
final Train<Shift> train = new TrJoined<>(
def,
new TrClasspath<>(
PhiMojo.SHEETS
).back()
);
final int count = new SumOf(
new Threads<>(
Runtime.getRuntime().availableProcessors(),
Expand Down Expand Up @@ -174,9 +189,7 @@ count, new Rel(this.phiInputDir), new Rel(this.phiOutputDir)
*/
private static String translated(final Train<Shift> train, final XML xmir)
throws ImpossibleToPhiTranslationException {
final XML translated = new Xsline(
train.with(new StClasspath("/org/eolang/maven/phi/to-phi.xsl"))
).pass(xmir);
final XML translated = new Xsline(train).pass(xmir);
Logger.debug(PhiMojo.class, "XML after translation to phi:\n%s", translated);
final List<String> phi = translated.xpath("phi/text()");
if (phi.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?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:xsl="http://www.w3.org/1999/XSL/Transform" id="decapitalize-auto-named" version="2.0">
<!--
Such EO code:
x
[] >>
is translated to such XMIR:
<o base="x">
<o abstract="" and name="OBJ-2-2"/>
</o>
Object with name "OBJ-2-2" can't be converted to PHI because attribute should start with
lowercase letter. So this transformation converts this name to "obj-2-2"
-->
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:template match="//o[@abstract and starts-with(@name,'OBJ-')]">
<xsl:copy>
<xsl:attribute name="name">
<xsl:value-of select="string-join(('obj', substring-after(@name,'-')),'-')"/>
</xsl:attribute>
<xsl:apply-templates select="node()|(@* except @name)"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//o[not(@name) and starts-with(@base,'OBJ-')]">
<xsl:copy>
<xsl:attribute name="base">
<xsl:value-of select="string-join(('obj', substring-after(@base,'-')),'-')"/>
</xsl:attribute>
<xsl:apply-templates select="node()|(@* except @base)"/>
</xsl:copy>
</xsl:template>
<xsl:template match="node()|@*" mode="#all">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# 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.
---
xsls:
- /org/eolang/parser/errors/not-empty-atoms.xsl
- /org/eolang/parser/critical-errors/duplicate-names.xsl
- /org/eolang/parser/errors/many-free-attributes.xsl
- /org/eolang/parser/errors/broken-aliases.xsl
- /org/eolang/parser/errors/duplicate-aliases.xsl
- /org/eolang/parser/errors/global-nonames.xsl
- /org/eolang/parser/errors/same-line-names.xsl
- /org/eolang/parser/errors/self-naming.xsl
- /org/eolang/parser/cti/cti-adds-errors.xsl
- /org/eolang/parser/add-refs.xsl
- /org/eolang/parser/wrap-method-calls.xsl
- /org/eolang/parser/expand-qqs.xsl
- /org/eolang/parser/add-probes.xsl
- /org/eolang/parser/vars-float-up.xsl
- /org/eolang/parser/add-refs.xsl
- /org/eolang/parser/warnings/sparse-decoration.xsl
- /org/eolang/parser/warnings/unsorted-metas.xsl
- /org/eolang/parser/warnings/incorrect-architect.xsl
- /org/eolang/parser/warnings/incorrect-home.xsl
- /org/eolang/parser/warnings/incorrect-version.xsl
- /org/eolang/parser/expand-aliases.xsl
- /org/eolang/parser/resolve-aliases.xsl
- /org/eolang/parser/add-refs.xsl
- /org/eolang/parser/add-default-package.xsl
- /org/eolang/parser/errors/broken-refs.xsl
- /org/eolang/parser/errors/unknown-names.xsl
- /org/eolang/parser/errors/noname-attributes.xsl
- /org/eolang/parser/critical-errors/duplicate-names.xsl
- /org/eolang/parser/warnings/duplicate-metas.xsl
- /org/eolang/parser/warnings/mandatory-package-meta.xsl
- /org/eolang/parser/warnings/mandatory-home-meta.xsl
- /org/eolang/parser/warnings/mandatory-version-meta.xsl
- /org/eolang/parser/warnings/correct-package-meta.xsl
- /org/eolang/parser/warnings/prohibited-package.xsl
- /org/eolang/parser/errors/external-weak-typed-atoms.xsl
- /org/eolang/parser/errors/unused-aliases.xsl
- /org/eolang/parser/warnings/unit-test-without-phi.xsl
- /org/eolang/parser/explicit-data.xsl
- /org/eolang/parser/const-to-dataized.xsl
- /org/eolang/parser/set-locators.xsl
- /org/eolang/maven/phi/decapitalize-auto-named.xsl
tests:
- //o[@abstract and @name='obj-2-4' and count(o)=1]
- //o[@base='obj-2-4']
eo: |
x
[] >>
5 > five
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 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: |
# This is the default 64+ symbols comment in front of named abstract object.
[] > object
x > first
[] >>
01- > b
phi: |-
{
object ↦ ⟦
first ↦ Φ.org.eolang.x(
α0 ↦ ξ.obj-4-6
),
obj-4-6 ↦ ⟦
b ↦ Φ.org.eolang.bytes(
Δ ⤍ 01-
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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.
---
tests:
- /program/objects/o[@name='main' and @atom and @abstract]
- /program/objects/o[@name='outer' and @abstract]
- /program/objects/o[@name='outer' and @abstract]/o[@name='inner' and @atom and @abstract]
phi:
"{⟦main ↦ ⟦λ ⤍ Lambda⟧, outer ↦ ⟦inner ↦ ⟦λ ⤍ Lambda⟧⟧⟧}"

0 comments on commit 7c0e03b

Please sign in to comment.