-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
101 additions
and
464 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
666 | ||
two.f1.f2 x | ||
stdout > z | ||
sprintf > f! | ||
sprintf > f | ||
"Hello, ".trim | ||
x 0x1fff n | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
eo-parser/src/main/resources/org/eolang/parser/const-to-dataized.xsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:eo="https://www.eolang.org" id="const-to-dataized" version="2.0"> | ||
<!-- | ||
Replace @const with dataized.as-bytes | ||
1. a > b! => (dataized a).as-bytes > b | ||
2. x.y z > m! => (dataized (x.y z)).as-bytes > m | ||
--> | ||
<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'"/> | ||
<xsl:attribute name="name" select="@name"/> | ||
<xsl:attribute name="line" select="@line"/> | ||
<xsl:attribute name="pos" select="@pos + 8"/> | ||
<xsl:element name="o"> | ||
<xsl:attribute name="base" select="'org.eolang.dataized'"/> | ||
<xsl:element name="o"> | ||
<xsl:for-each select="@*[name()!='const' and name()!='name']"> | ||
<xsl:attribute name="{name()}"> | ||
<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> | ||
</xsl:element> | ||
</xsl:element> | ||
</xsl:element> | ||
</xsl:template> | ||
<xsl:template match="node()|@*"> | ||
<xsl:copy> | ||
<xsl:apply-templates select="node()|@*"/> | ||
</xsl:copy> | ||
</xsl:template> | ||
</xsl:stylesheet> |
20 changes: 20 additions & 0 deletions
20
eo-parser/src/test/resources/org/eolang/parser/packs/const-to-dataized.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
tests: | ||
- //o[@base='.as-bytes' and @line and @pos and @name='x' and o[@base='org.eolang.dataized' and o[@base='org.eolang.int' and not(@name)]]] | ||
- //o[@base='.as-bytes' and @line and @pos 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 @line and @pos 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 @line and @pos and @name='y' and o[@base='org.eolang.dataized' and o[@base='org.eolang.c' and not(@name)]]] | ||
- //objects[count(//o[@const])=0] | ||
eo: | | ||
# This is the default 64+ symbols comment in front of abstract object. | ||
[] > foo | ||
int > x! | ||
# This is the default 64+ symbols comment in front of named abstract object. | ||
[] > m! | ||
a | ||
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 |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.