Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add xsl to check for negative binding indexes #2675

Merged
merged 6 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions eo-parser/src/main/java/org/eolang/parser/ParsingTrain.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@
* Train of XSL shifts.
*
* @since 0.1
* @todo #2665:30min Check negative int bindings via xsl. It's possible now to make application
* with integer bindings like {@code x a:0 b:1}. Need to add xsl transformation that would check
* if such binding is negative and would add an error to "errors" section.
*/
public final class ParsingTrain extends TrEnvelope {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License (MIT)

Copyright (c) 2016-2023 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" id="negative-binding-indexes" version="2.0">
c71n93 marked this conversation as resolved.
Show resolved Hide resolved
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:template match="/program/errors">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<xsl:for-each select="//o[@as and matches(@as, '^(-|\+)\d+$')]">
<xsl:element name="error">
<xsl:attribute name="check">
<xsl:text>zero-version</xsl:text>
</xsl:attribute>
<xsl:attribute name="line">
<xsl:value-of select="@line"/>
</xsl:attribute>
<xsl:attribute name="severity">
<xsl:text>error</xsl:text>
</xsl:attribute>
<xsl:text>Binding index of application must not be a negative number "</xsl:text>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@c71n93 I think not only negative but positive with + too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<xsl:value-of select="tail/text()"/>
<xsl:text>"</xsl:text>
</xsl:element>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
xsls:
- /org/eolang/parser/errors/negative-binding-indexes.xsl
tests:
- /program/errors[count(error[@severity='error'])=2]
eo: |
object c:-1 d:-2 a:0 b:1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@c71n93 let's add a case with index with +

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loading