Skip to content

Commit

Permalink
feat(#3042): unique name for abstract objects
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon committed Apr 10, 2024
1 parent 8bc2d9a commit 7e791c0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Expand Up @@ -22,7 +22,7 @@ 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="const-to-dataized" version="2.0">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:eo="https://www.eolang.org" id="const-to-dataized" version="2.0">
<!--
Here we go through all objects and find what their @base
are referring to. If we find the object they refer to,
Expand All @@ -32,6 +32,22 @@ SOFTWARE.
global or just a mistake.
-->
<xsl:output encoding="UTF-8" method="xml"/>
<!-- Generate unique name for an abstract object -->
<xsl:function name="eo:unique-name">
<xsl:param name="name"/>
<xsl:param name="scope"/>
<xsl:param name="counter"/>
<xsl:variable name="unique" select="concat($name, '-', $counter)"/>
<xsl:choose>
<xsl:when test="$scope[o[@name=$unique]]">
<xsl:value-of select="eo:unique-name($name, $scope, $counter + 1)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$unique"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<!-- Template -->
<xsl:template match="o[@const]">
<xsl:element name="o">
<xsl:attribute name="base" select="'.as-bytes'"/>
Expand All @@ -44,6 +60,11 @@ SOFTWARE.
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:if test="@abstract">
<xsl:attribute name="name">
<xsl:value-of select="eo:unique-name(@name, ./parent::o, 1)"/>
</xsl:attribute>
</xsl:if>
<xsl:for-each select="o">
<xsl:apply-templates select="."/>
</xsl:for-each>
Expand Down
@@ -1,6 +1,8 @@
tests:
- //o[@base='.as-bytes' and @name='x' and o[@base='org.eolang.dataized' and o[@base='org.eolang.int' and not(@name)]]]
- //o[@base='.as-bytes' and @name='y' and o[@base='org.eolang.dataized' and o[@base='org.eolang.int' and not(@name)]]]
- //o[@base='.as-bytes' and @name='m' and o[@base='org.eolang.dataized' and o[@abstract and @name='m-3' and count(o)=2]]]
- //o[@base='.as-bytes' and @name='z' and o[@base='org.eolang.dataized' and o[@base='.o' and not(@name) and count(o)=1]]]
- //o[@base='.as-bytes' and @name='y' and o[@base='org.eolang.dataized' and o[@base='org.eolang.c' and not(@name)]]]
eo: |
# This is the default 64+ symbols comment in front of abstract object.
[] > foo
Expand All @@ -11,3 +13,7 @@ eo: |
b
c 1 2 > y!
.o > z!
# This is the default 64+ symbols comment in front of named abstract object.
[] > m-1
# This is the default 64+ symbols comment in front of named abstract object.
[] > m-2

0 comments on commit 7e791c0

Please sign in to comment.