Skip to content

Commit

Permalink
Merge pull request #3873 from maxonfjvipon/bug/#3872/expand-aliases-p…
Browse files Browse the repository at this point in the history
…roperly

bug(#3872): fixed aliases expanding and resolving
  • Loading branch information
yegor256 authored Jan 30, 2025
2 parents fa9b299 + 715411f commit 79c82ff
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,35 @@ SOFTWARE.
-->
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:template match="/program/metas/meta[head='alias']">
<xsl:variable name="expanded" select="contains(tail, ' ')"/>
<xsl:variable name="composite" select="contains(tail, ' ')"/>
<xsl:variable name="split" select="tokenize(tail/text(), ' ')"/>
<xsl:variable name="last">
<xsl:choose>
<xsl:when test="$expanded">
<xsl:value-of select="tokenize(tail/text(), ' ')[last()]"/>
<xsl:when test="$composite">
<xsl:value-of select="$split[last()]"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="tail/text()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="parts" select="tokenize($last, '\.')"/>
<xsl:variable name="first">
<xsl:choose>
<xsl:when test="$composite">
<xsl:value-of select="$split[1]"/>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="contains($last, '.')">
<xsl:value-of select="tokenize($last, '\.')[last()]"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="tail/text()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="tail">
<xsl:if test="not(starts-with($last, 'Q.'))">
<xsl:text>Q.</xsl:text>
Expand All @@ -56,13 +73,26 @@ SOFTWARE.
<xsl:copy>
<xsl:apply-templates select="node() except tail except part|@*"/>
<xsl:element name="tail">
<xsl:value-of select="$parts[last()]"/>
<xsl:value-of select="$first"/>
<xsl:if test="$composite">
<xsl:for-each select="$split[position()&gt;1 and position()!=last()]">
<xsl:text> </xsl:text>
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:if>
<xsl:text> </xsl:text>
<xsl:value-of select="$tail"/>
</xsl:element>
<xsl:element name="part">
<xsl:value-of select="$parts[last()]"/>
<xsl:value-of select="$first"/>
</xsl:element>
<xsl:if test="$composite">
<xsl:for-each select="$split[position()&gt;1 and position()!=last()]">
<xsl:element name="part">
<xsl:value-of select="."/>
</xsl:element>
</xsl:for-each>
</xsl:if>
<xsl:element name="part">
<xsl:value-of select="$tail"/>
</xsl:element>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ SOFTWARE.
<xsl:variable name="meta" select="/program/metas/meta[head='alias' and part[1] = $o/@base]"/>
<xsl:choose>
<xsl:when test="$meta">
<xsl:variable name="tail" select="$meta/part[2]"/>
<xsl:variable name="tail" select="$meta/part[last()]"/>
<xsl:value-of select="$tail[1]"/>
</xsl:when>
<xsl:otherwise>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ asserts:
- /program[not(errors)]
- //meta[head='alias' and tail='scanner Q.org.eolang.txt.scanner' and part[1]='scanner' and part[2]='Q.org.eolang.txt.scanner']
- //meta[head='alias' and tail='stdin Q.org.eolang.io.stdin' and part[1]='stdin' and part[2]='Q.org.eolang.io.stdin']
- //meta[head='alias' and tail='a b Q.c' and part[1]='a' and part[2]='b' and part[3]='Q.c']
- //meta[head='alias' and tail='a b c e Q.f' and part[1]='a' and part[2]='b' and part[3]='c' and part[4]='e' and part[5]='Q.f']
input: |
+alias org.eolang.txt.scanner
+alias stdin org.eolang.io.stdin
+alias a b c
+alias a b c e f
# No comments.
[args] > main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,21 @@ sheets:
asserts:
- /program[not(errors)]
- /program/objects[count(o)=1]
- /program/metas/meta[head='foo' and @line='4']
- /program/metas[count(meta)=4]
- /program/metas/meta[head='foo']
- /program/metas[count(meta)=6]
- //o[@base='Q.org.eolang.txt.scanner']
- //o[@base='Q.org.eolang.io.stdout' and @line='10']
- //o[@base='and' and @line='8']
- //o[@base='Q.org.eolang.io.stdout']
- //o[@base='and']
- //o[@base='$']
- //o[@base='^']
- //o[@base='Q.org.eolang.txt.regex']
- //o[@base='Q.org.d']
input: |
+alias org.eolang.txt.scanner
+alias stdin org.eolang.io.stdin
+alias stdout org.eolang.io.stdout
+alias custom org.eolang.txt.regex
+alias a b c org.d
+foo Some other meta
# No comments.
Expand All @@ -49,3 +53,5 @@ input: |
(stdout "You entered" line).print
^.x
$
custom 5
a

0 comments on commit 79c82ff

Please sign in to comment.