Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Sep 8, 2023
2 parents 835e861 + 391d7a3 commit e47e390
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ xsls:
- /org/eolang/parser/add-default-package.xsl
- /org/eolang/parser/wrap-method-calls.xsl
- /org/eolang/parser/set-locators.xsl
- /org/eolang/parser/explicit-data.xsl
- /org/eolang/maven/pre/classes.xsl
- /org/eolang/maven/pre/attrs.xsl
- /org/eolang/maven/pre/data.xsl
Expand All @@ -15,11 +16,13 @@ tests:
- //java[contains(text(), 'new PhLocated(ret_base, 7, 2, "Φ.bar.φ.ρ")')]
- //java[contains(text(), 'new PhLocated(ret, 7, 4, "Φ.bar.φ")')]
- //java[contains(text(), 'new PhLocated(ret_1, 7, 10, "Φ.bar.φ.α0")')]
- //java[contains(text(), 'new PhLocated(ret, 8, 2, "Φ.bar.five")')]
eo: |
[] > foo
42 > @
[y] > other
43.plus y > @
[] > bar
42.plus 43 > @
42.plus 43 > @
int 5 > five
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ public final class ParsingTrain extends TrEnvelope {
"/org/eolang/parser/warnings/correct-package-meta.xsl",
"/org/eolang/parser/warnings/prohibited-package.xsl",
"/org/eolang/parser/errors/unused-aliases.xsl",
"/org/eolang/parser/errors/data-objects.xsl",
"/org/eolang/parser/warnings/unit-test-without-phi.xsl",
"/org/eolang/parser/set-locators.xsl",
"/org/eolang/parser/explicit-data.xsl",
};

/**
Expand Down
103 changes: 103 additions & 0 deletions eo-parser/src/main/resources/org/eolang/parser/explicit-data.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License (MIT)
Copyright (c) 2016-2023 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="explicit-data" version="2.0">
<!--
Here we transform just data into application
- 5 => 5
- int 5 => 5
- float 22.4 => 22.4
- QQ.bool TRUE > TRUE
In the level of xmir it looks like:
- <o base="org.eolang.int" data="int">2</o> => <o base="org.eolang.int" data="int">2</o>
- <o base="org.eolang.int" name="num"> <o base="org.eolang.int" data="int" name="num">
<o base="org.eolang.int" data="int"> => 42
42 </o>
</o>
</o>
- <o base=".bool" name="b"> <o base="org.eolang.bool" data="bytes" name="b">
<o base=".eolang"> => 01
<o base=".org"> </o>
<o base="Q"></o>
</o>
</o
<o base="org.eolang.bool" data="bytes">
01
</o>
</o>
-->
<xsl:import href="/org/eolang/parser/_datas.xsl"/>
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:variable name="reversed" as="element()*">
<xsl:for-each select="$literal-objects">
<a>
<xsl:value-of select="replace(./text(), 'org\.eolang\.', '.')"/>
</a>
</xsl:for-each>
</xsl:variable>
<xsl:template match="//o[o[last() and @data] and @base!='org.eolang.tuple']">
<xsl:variable name="base" select="@base"/>
<xsl:variable name="last-base" select="o[last()]/@base"/>
<xsl:choose>
<xsl:when test="$literal-objects[text()=$base]">
<o>
<xsl:for-each select="@*">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:attribute name="data">
<xsl:value-of select="o/@data"/>
</xsl:attribute>
<xsl:value-of select="o"/>
</o>
</xsl:when>
<xsl:when test="$reversed[text()=$base] and count(o)=2 and o[position()=1 and @base='.eolang' and o[@base='.org' and o[@base='Q']]] and o[last() and @data] and $literal-objects[text()=$last-base]">
<o>
<xsl:for-each select="@*[name()!='base']">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:attribute name="data">
<xsl:value-of select="o[last()]/@data"/>
</xsl:attribute>
<xsl:attribute name="base">
<xsl:value-of select="o[last()]/@base"/>
</xsl:attribute>
<xsl:value-of select="o[last()]"/>
</o>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</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
@@ -0,0 +1,23 @@
xsls:
- /org/eolang/parser/wrap-method-calls.xsl
- /org/eolang/parser/expand-qqs.xsl
- /org/eolang/parser/add-default-package.xsl
- /org/eolang/parser/explicit-data.xsl
tests:
- /program/errors[count(*)=0]
- //o[@base='org.eolang.int' and @name='first' and @data]
- //o[@base='org.eolang.float' and @name='second' and @data and count(o)=0]
- //o[@base='org.eolang.bool' and @name='third' and @data and count(o)=0]
- //o[@base='org.eolang.bytes' and @name='fourth' and @data and count(o)=0]
- //o[@base='org.eolang.string' and @name='str' and @data and count(o)=0]
- //o[@base='org.eolang.tuple' and o[@base='org.eolang.tuple']]
eo: |
42 > first
float 22.2 > second
QQ.bool TRUE > third
QQ.bytes > fourth
11-21
Q.org.eolang.string "Hey" > str
tuple
* 1
2

0 comments on commit e47e390

Please sign in to comment.