Skip to content

Commit

Permalink
fix(#3147): lowercased auto generated name
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon committed May 8, 2024
1 parent 8e3997b commit d1c00dd
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ origin: |
straight: |
x > first
[] >>
# This is the default 64+ symbols comment in front of named abstract object.
[] > auto-named-attr-at-2-4
5 > five
reversed: |
x > first
[] >>
# This is the default 64+ symbols comment in front of named abstract object.
[] > auto-named-attr-at-2-4
5 > five
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ public void enterAname(final EoParser.AnameContext ctx) {
.prop(
"name",
String.format(
"OBJ-%d-%d",
"auto-named-attr-at-%d-%d",
ctx.getStart().getLine(),
ctx.getStart().getCharPositionInLine()
)
Expand Down
Original file line number Diff line number Diff line change
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" xmlns:eo="https://www.eolang.org" xmlns:xs="http://www.w3.org/2001/XMLSchema" id="xmir-to-eo-reversed" version="2.0">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:eo="https://www.eolang.org" id="xmir-to-eo-reversed" version="2.0">
<!--
This one maps XMIR to EO original syntax in reversed notation.
It's used in XmirReversed.java class.
Expand All @@ -34,11 +34,6 @@ SOFTWARE.
<xsl:value-of select="$eol"/>
</xsl:variable>
<xsl:output method="text" encoding="UTF-8"/>
<!-- Check if given name is auto-generated -->
<xsl:function name="eo:is-auto-generated" as="xs:boolean">
<xsl:param name="name"/>
<xsl:sequence select="starts-with($name,'OBJ-')"/>
</xsl:function>
<!-- PROGRAM -->
<xsl:template match="program">
<eo>
Expand Down Expand Up @@ -113,7 +108,7 @@ SOFTWARE.
<!-- ABSTRACT OR ATOM -->
<xsl:template match="o[not(@data) and not(@base)]" mode="head">
<xsl:param name="indent"/>
<xsl:if test="@name and not(eo:is-auto-generated(@name))">
<xsl:if test="@name">
<xsl:value-of select="$comment"/>
<xsl:value-of select="$indent"/>
</xsl:if>
Expand All @@ -133,24 +128,15 @@ SOFTWARE.
<xsl:value-of select="@as"/>
</xsl:if>
<xsl:if test="@name">
<xsl:choose>
<!-- Auto-generated name -->
<xsl:when test="eo:is-auto-generated(@name)">
<xsl:text> &gt;&gt;</xsl:text>
</xsl:when>
<!-- Regular case -->
<xsl:otherwise>
<xsl:text> &gt; </xsl:text>
<xsl:value-of select="@name"/>
<xsl:if test="@const">
<xsl:text>!</xsl:text>
</xsl:if>
<xsl:if test="@atom">
<xsl:text> /</xsl:text>
<xsl:value-of select="@atom"/>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<xsl:text> &gt; </xsl:text>
<xsl:value-of select="@name"/>
<xsl:if test="@const">
<xsl:text>!</xsl:text>
</xsl:if>
<xsl:if test="@atom">
<xsl:text> /</xsl:text>
<xsl:value-of select="@atom"/>
</xsl:if>
</xsl:if>
</xsl:template>
<!-- DATA -->
Expand Down
36 changes: 11 additions & 25 deletions eo-parser/src/main/resources/org/eolang/parser/xmir-to-eo.xsl
Original file line number Diff line number Diff line change
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" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:eo="https://www.eolang.org" id="xmir-to-eo" version="2.0">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:eo="https://www.eolang.org" id="xmir-to-eo" version="2.0">
<!--
This one maps XMIR to EO original syntax in straight notation.
It's used in Xmir.java class.
Expand All @@ -34,11 +34,6 @@ SOFTWARE.
<xsl:value-of select="$eol"/>
</xsl:variable>
<xsl:output method="text" encoding="UTF-8"/>
<!-- Check if given name is auto-generated -->
<xsl:function name="eo:is-auto-generated" as="xs:boolean">
<xsl:param name="name"/>
<xsl:sequence select="starts-with($name,'OBJ-')"/>
</xsl:function>
<!-- PROGRAM -->
<xsl:template match="program">
<eo>
Expand Down Expand Up @@ -129,7 +124,7 @@ SOFTWARE.
<!-- ABSTRACT OR ATOM -->
<xsl:template match="o[not(@data) and not(@base)]" mode="head">
<xsl:param name="indent"/>
<xsl:if test="@name and not(eo:is-auto-generated(@name))">
<xsl:if test="@name">
<xsl:value-of select="$comment"/>
<xsl:value-of select="$indent"/>
</xsl:if>
Expand All @@ -149,24 +144,15 @@ SOFTWARE.
<xsl:value-of select="@as"/>
</xsl:if>
<xsl:if test="@name">
<xsl:choose>
<!-- Auto-generated name -->
<xsl:when test="eo:is-auto-generated(@name)">
<xsl:text> &gt;&gt;</xsl:text>
</xsl:when>
<!-- Regular case -->
<xsl:otherwise>
<xsl:text> &gt; </xsl:text>
<xsl:value-of select="@name"/>
<xsl:if test="@const">
<xsl:text>!</xsl:text>
</xsl:if>
<xsl:if test="@atom">
<xsl:text> /</xsl:text>
<xsl:value-of select="@atom"/>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<xsl:text> &gt; </xsl:text>
<xsl:value-of select="@name"/>
<xsl:if test="@const">
<xsl:text>!</xsl:text>
</xsl:if>
<xsl:if test="@atom">
<xsl:text> /</xsl:text>
<xsl:value-of select="@atom"/>
</xsl:if>
</xsl:if>
</xsl:template>
<!-- DATA -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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.
---
# @todo #3147:30min Make duplicate names catcher more powerful. This test pack is disabled now
# because names duplication is not caught here. It happens because of "duplicate-names.xsl" thinks
# that abstract objects in the tests are on the different levels. Syntactically they are, but
# semantically they're not. So we need to make this duplicate catcher more powerful, enable the
# test by removing "skip: true" line and make sure it works.
skip: true
xsls:
- /org/eolang/parser/critical-errors/duplicate-names.xsl
tests:
- /program/errors[count(error)=1]
eo: |
# This is the default 64+ symbols comment in front of abstract object.
[] > main
x > f
[] >>
# This is the default 64+ symbols comment in front of abstract object.
[] > auto-named-attr-at-4-6
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
xsls: [ ]
tests:
- //errors[count(error)=0]
- //o[@abstract and starts-with(@name,'OBJ-') and o[@name='five']]
- //o[@abstract and starts-with(@name,'OBJ-') and o[@name='ten']]
- //o[@abstract and starts-with(@name,'OBJ-') and @as='hello' and o[@name='eleven']]
- //o[@abstract and @name='auto-named-attr-at-2-4' and o[@name='five']]
- //o[@abstract and @name='auto-named-attr-at-4-2' and o[@name='ten']]
- //o[@abstract and @name='auto-named-attr-at-8-10' and @as='hello' and o[@name='eleven']]
eo: |
x > first
[] >>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ origin: |
straight: |
x > first
[] >>
# This is the default 64+ symbols comment in front of named abstract object.
[] > auto-named-attr-at-2-4
5 > five
reversed: |
x > first
[] >>
# This is the default 64+ symbols comment in front of named abstract object.
[] > auto-named-attr-at-2-4
5 > five

0 comments on commit d1c00dd

Please sign in to comment.