Skip to content

Commit

Permalink
fix(#2729): xmir to eo
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon committed Dec 28, 2023
1 parent 055f121 commit 32f0157
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 58 deletions.
4 changes: 1 addition & 3 deletions eo-parser/src/main/java/org/eolang/parser/XMIR.java
Expand Up @@ -40,10 +40,9 @@
*
* Here, the {@code xml} is a {@code String} or an instance
* of {@code XML} from the jcabi-xml package.
*
* @since 0.5
* @checkstyle AbbreviationAsWordInNameCheck (500 lines)
* @link <a href="https://xml.jcabi.com">xml.jcabi.com</a>
* @since 0.5
*/
public final class XMIR {
/**
Expand Down Expand Up @@ -93,7 +92,6 @@ private XMIR(final Unchecked<String> src) {

/**
* Print it to EO.
*
* @return The program in EO
*/
public String toEO() {
Expand Down
102 changes: 47 additions & 55 deletions eo-parser/src/main/resources/org/eolang/parser/xmir-to-eo.xsl
Expand Up @@ -30,11 +30,15 @@ SOFTWARE.
<xsl:import href="/org/eolang/parser/_funcs.xsl"/>
<xsl:variable name="eol" select="'&#10;'"/>
<xsl:output method="text" encoding="UTF-8"/>
<!-- PROGRAM -->
<xsl:template match="program">
<xsl:apply-templates select="license"/>
<xsl:apply-templates select="metas[meta]"/>
<xsl:apply-templates select="objects"/>
<eo>
<xsl:apply-templates select="license"/>
<xsl:apply-templates select="metas[meta]"/>
<xsl:apply-templates select="objects"/>
</eo>
</xsl:template>
<!-- LICENCE -->
<xsl:template match="license">
<xsl:for-each select="tokenize(., $eol)">
<xsl:text># </xsl:text>
Expand All @@ -45,10 +49,12 @@ SOFTWARE.
<xsl:value-of select="$eol"/>
</xsl:if>
</xsl:template>
<!-- METAS -->
<xsl:template match="metas">
<xsl:apply-templates select="meta"/>
<xsl:value-of select="$eol"/>
</xsl:template>
<!-- META -->
<xsl:template match="meta">
<xsl:text>+</xsl:text>
<xsl:value-of select="head"/>
Expand All @@ -58,49 +64,64 @@ SOFTWARE.
</xsl:if>
<xsl:value-of select="$eol"/>
</xsl:template>
<!-- OBJECTS -->
<xsl:template match="objects">
<xsl:apply-templates select="o"/>
</xsl:template>
<xsl:template match="o[eo:attr(.)]">
<!-- nothing, it's a free attribute -->
</xsl:template>
<xsl:template match="o[not(eo:attr(.)) and starts-with(@base, '.')]">
<!-- -->
<!-- <xsl:template match="o[eo:attr(.)]">-->
<!-- nothing, it's a free attribute -->
<!-- </xsl:template>-->
<!-- OBJECT, NOT FREE ATTRIBUTE -->
<xsl:template match="o[not(eo:attr(.))]">
<xsl:param name="indent" select="''"/>
<xsl:apply-templates select="o[position() = 1]">
<xsl:with-param name="indent" select="$indent"/>
</xsl:apply-templates>
<xsl:value-of select="$indent"/>
<xsl:apply-templates select="." mode="head"/>
<xsl:apply-templates select="." mode="tail"/>
<xsl:value-of select="$eol"/>
<xsl:apply-templates select="o[position() &gt; 1]">
<xsl:with-param name="indent" select="concat(' ', $indent)"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="o[not(eo:attr(.)) and not(starts-with(@base, '.'))]">
<xsl:param name="indent" select="''"/>
<xsl:if test="position() &gt; 1 and parent::objects">
<!--IF NOT THE FIRST TOP OBJECT -->
<xsl:if test="position()&gt;1 and parent::objects">
<xsl:value-of select="$eol"/>
</xsl:if>
<xsl:value-of select="$indent"/>
<xsl:apply-templates select="." mode="head"/>
<xsl:apply-templates select="." mode="tail"/>
<xsl:value-of select="$eol"/>
<xsl:apply-templates select="o">
<xsl:apply-templates select="o[not(eo:attr(.))]">
<xsl:with-param name="indent" select="concat(' ', $indent)"/>
</xsl:apply-templates>
</xsl:template>
<!-- BASED -->
<xsl:template match="o[not(@data) and @base]" mode="head">
<xsl:choose>
<xsl:when test="starts-with(@base,'.')">
<xsl:value-of select="substring(@base,2)"/>
<xsl:text>.</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@base"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- ABSTRACT OR ATOM -->
<xsl:template match="o[not(@data) and not(@base)]" mode="head">
<xsl:text>[</xsl:text>
<xsl:for-each select="o[eo:attr(.)]">
<xsl:if test="position()&gt;1">
<xsl:text> </xsl:text>
</xsl:if>
<xsl:value-of select="@name"/>
</xsl:for-each>
<xsl:text>]</xsl:text>
</xsl:template>
<!-- TAIL: SUFFIX, NAME, CONST, COPY, ATOM -->
<xsl:template match="o" mode="tail">
<xsl:if test="@copy">
<xsl:text>'</xsl:text>
</xsl:if>
<xsl:if test="@as">
<xsl:text>:</xsl:text>
<xsl:value-of select="@as"/>
</xsl:if>
<xsl:if test="@name">
<xsl:text> &gt; </xsl:text>
<xsl:value-of select="@name"/>
<xsl:if test="@vararg">
<xsl:text>...</xsl:text>
</xsl:if>
<xsl:if test="@const">
<xsl:text>!</xsl:text>
</xsl:if>
Expand All @@ -110,36 +131,7 @@ SOFTWARE.
</xsl:if>
</xsl:if>
</xsl:template>
<xsl:template match="o[not(@data) and @base]" mode="head">
<xsl:value-of select="@base"/>
</xsl:template>
<xsl:template match="o[not(@data) and not(@base)]" mode="head">
<xsl:text>[</xsl:text>
<xsl:for-each select="o[eo:attr(.)]">
<xsl:if test="position() &gt; 1">
<xsl:text> </xsl:text>
</xsl:if>
<xsl:value-of select="@name"/>
<xsl:if test="@vararg">
<xsl:text>...</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text>]</xsl:text>
</xsl:template>
<xsl:template match="o[@data='tuple']" mode="head">
<xsl:text>*</xsl:text>
</xsl:template>
<xsl:template match="o[@data='string']" mode="head">
<xsl:text>"</xsl:text>
<xsl:value-of select="text()"/>
<xsl:text>"</xsl:text>
</xsl:template>
<xsl:template match="o[@data='bool']" mode="head">
<xsl:value-of select="upper-case(text())"/>
</xsl:template>
<xsl:template match="o[@data and @data!='string' and @data!='tuple' and @data!='bool' and @data!='bytes']" mode="head">
<xsl:value-of select="text()"/>
</xsl:template>
<!-- DATA BYTES -->
<xsl:template match="o[@data='bytes']" mode="head">
<xsl:choose>
<xsl:when test="@base='string'">
Expand Down

0 comments on commit 32f0157

Please sign in to comment.