-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
bug(#3619): added sugar for compact tuples
- Loading branch information
Showing
22 changed files
with
378 additions
and
151 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
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
71 changes: 71 additions & 0 deletions
71
eo-parser/src/main/resources/org/eolang/parser/resolve-before-star.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,71 @@ | ||
<?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:xs="http://www.w3.org/2001/XMLSchema" id="resolve-before-star" version="2.0"> | ||
<!-- | ||
Converts such XMIR with @before-star attributes: | ||
<o base="seq" before-star="2"> | ||
<o base="1".../> | ||
<o base="2".../> | ||
<o base="3".../> | ||
<o base="4".../> | ||
</o> | ||
Into the next one: | ||
<o base="seq"> | ||
<o base="1".../> | ||
<o base="2".../> | ||
<o base="tuple" star=""> | ||
<o base="3".../> | ||
<o base="4".../> | ||
</o> | ||
</o> | ||
--> | ||
<xsl:output encoding="UTF-8" method="xml"/> | ||
<xsl:template match="o[@before-star]"> | ||
<xsl:variable name="before" select="@before-star" as="xs:int"/> | ||
<xsl:element name="o"> | ||
<xsl:for-each select="@* except @before-star"> | ||
<xsl:attribute name="{name()}" select="."/> | ||
</xsl:for-each> | ||
<xsl:for-each select="o[position() <= $before]"> | ||
<xsl:apply-templates select="."/> | ||
</xsl:for-each> | ||
<xsl:element name="o"> | ||
<xsl:attribute name="base" select="'tuple'"/> | ||
<xsl:attribute name="star"/> | ||
<xsl:for-each select="o[position() > $before]"> | ||
<xsl:apply-templates select="."/> | ||
</xsl:for-each> | ||
</xsl:element> | ||
</xsl:element> | ||
</xsl:template> | ||
<xsl:template match="node()|@*"> | ||
<xsl:copy> | ||
<xsl:apply-templates select="node()|@*"/> | ||
</xsl:copy> | ||
</xsl:template> | ||
</xsl:stylesheet> |
74 changes: 74 additions & 0 deletions
74
eo-parser/src/main/resources/org/eolang/parser/validate-before-stars.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,74 @@ | ||
<?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:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" id="validate-before-stars" version="2.0"> | ||
<!-- | ||
Checks if index after '*' in compact array syntax is more than amount of arguments. | ||
Correct: | ||
``` | ||
sprintf *1 | ||
"Hello, %s" | ||
"world" | ||
``` | ||
Incorrect: | ||
``` | ||
sprintf *3 | ||
"Hello, %s" | ||
"world" | ||
``` | ||
--> | ||
<xsl:output encoding="UTF-8" method="xml"/> | ||
<xsl:template match="/program"> | ||
<xsl:copy> | ||
<xsl:apply-templates select="(node() except errors)|@*"/> | ||
<xsl:variable name="errors" as="element()*"> | ||
<xsl:for-each select="//o[@before-star > count(o)]"> | ||
<xsl:element name="error"> | ||
<xsl:attribute name="check" select="'validate-before-stars'"/> | ||
<xsl:attribute name="line" select="if (@line) then @line else 0"/> | ||
<xsl:attribute name="severity" select="'error'"/> | ||
<xsl:text>Index after '*' (</xsl:text> | ||
<xsl:value-of select="@before-star"/> | ||
<xsl:text>) must be less than amount arguments (</xsl:text> | ||
<xsl:value-of select="count(o)"/> | ||
<xsl:text>)</xsl:text> | ||
</xsl:element> | ||
</xsl:for-each> | ||
</xsl:variable> | ||
<xsl:if test="not(empty($errors)) or exists(/program/errors)"> | ||
<errors> | ||
<xsl:apply-templates select="/program/errors/error"/> | ||
<xsl:copy-of select="$errors"/> | ||
</errors> | ||
</xsl:if> | ||
</xsl:copy> | ||
</xsl:template> | ||
<xsl:template match="node()|@*"> | ||
<xsl:copy> | ||
<xsl:apply-templates select="node()|@*"/> | ||
</xsl:copy> | ||
</xsl:template> | ||
</xsl:stylesheet> |
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
51 changes: 51 additions & 0 deletions
51
eo-parser/src/test/resources/org/eolang/parser/eo-packs/syntax/before-star.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,51 @@ | ||
# 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. | ||
--- | ||
sheets: [ ] | ||
asserts: | ||
- /program/errors/error[@line='3' and @severity='error'] | ||
- /program/objects//o[@name='first' and count(o)=1]/o[@base='tuple' and count(o)=2] | ||
- /program/objects//o[@name='second' and count(o)=2]/o[position()=2 and @base='tuple' and count(o)=2] | ||
- /program/objects//o[@name='third' and count(o)=3]/o[position()=3 and @base='tuple' and count(o)=2] | ||
- /program/objects//o[@name='fourth' and count(o)=2]/o[@base='sprintf' and count(o)=1]/o[@base='tuple' and count(o)=2] | ||
- /program/objects[count(//o[@before-star])=0] | ||
input: | | ||
# No comments. | ||
[] > foo | ||
sprintf *2 > with-error | ||
x | ||
sprintf * > first | ||
x | ||
y | ||
sprintf *1 > second | ||
x | ||
y | ||
z | ||
sprintf *2 > third | ||
x | ||
y | ||
z | ||
sprintf *1 > fourth | ||
sprintf * | ||
x | ||
y | ||
z |
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
Oops, something went wrong.