-
Notifications
You must be signed in to change notification settings - Fork 17
feat(#120): pos-bigger-than-line #195
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| <?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="pos-bigger-than-line" version="2.0"> | ||
| <xsl:import href="/org/eolang/funcs/lineno.xsl"/> | ||
| <xsl:output encoding="UTF-8" method="xml"/> | ||
| <xsl:template match="/"> | ||
| <defects> | ||
| <xsl:for-each select="//o"> | ||
| <xsl:variable name="line" select="number(@line)"/> | ||
| <xsl:variable name="length" select="sum(//o[@line = $line and not(descendant::o)]/string-length(normalize-space(text())))"/> | ||
| <xsl:if test="@line and number(@pos)>$length"> | ||
| <xsl:element name="defect"> | ||
| <xsl:attribute name="line"> | ||
| <xsl:value-of select="eo:lineno(@line)"/> | ||
| </xsl:attribute> | ||
| <xsl:attribute name="severity"> | ||
| <xsl:text>critical</xsl:text> | ||
| </xsl:attribute> | ||
| <xsl:text>The </xsl:text> | ||
| <xsl:choose> | ||
| <xsl:when test="@name"> | ||
| <xsl:text>object </xsl:text> | ||
| <xsl:text>"</xsl:text> | ||
| <xsl:value-of select="@name"/> | ||
| <xsl:text>"</xsl:text> | ||
| </xsl:when> | ||
| <xsl:otherwise> | ||
| <xsl:text>anonymous object</xsl:text> | ||
| </xsl:otherwise> | ||
| </xsl:choose> | ||
| <xsl:text> has '@pos' (</xsl:text> | ||
| <xsl:value-of select="@pos"/> | ||
| <xsl:text>), that is bigger than its line length (</xsl:text> | ||
| <xsl:value-of select="$length"/> | ||
| <xsl:text>)</xsl:text> | ||
| </xsl:element> | ||
| </xsl:if> | ||
| </xsl:for-each> | ||
| </defects> | ||
| </xsl:template> | ||
| </xsl:stylesheet> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # `@pos` Bigger Than `@line` | ||
|
|
||
| In [XMIR], each `<o/>` must have the value of it's `@pos` attribute not bigger | ||
| than the length of the `@line` it belongs to. | ||
|
|
||
| Incorrect: | ||
|
|
||
| ```xml | ||
| <program> | ||
| <objects> | ||
| <o line="2" pos="5" name="foo"> | ||
| <o line="2" name="xyz"> | ||
| <o line="2">data</o> | ||
| </o> | ||
| </o> | ||
| </objects> | ||
| </program> | ||
| ``` | ||
|
|
||
| Since, line with `foo` object has length `4`, while `@pos` points to the `5`. | ||
|
|
||
| Correct: | ||
|
|
||
| ```xml | ||
| <program> | ||
| <objects> | ||
| <o line="2" pos="2" name="foo"> | ||
| <o line="2" name="xyz"> | ||
| <o line="2">data</o> | ||
| </o> | ||
| </o> | ||
| </objects> | ||
| </program> | ||
| ``` | ||
|
|
||
| [XMIR]: https://news.eolang.org/2022-11-25-xmir-guide.html |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # 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: | ||
| - /org/eolang/lints/critical/pos-bigger-than-line.xsl | ||
| asserts: | ||
| - /defects[count(defect[@severity='critical'])=1] | ||
| - /defects/defect[@line='2'] | ||
| document: | | ||
| <program> | ||
| <objects> | ||
| <o line="1" name="foo"> | ||
| <o line="2" pos="5" name="xyz"> | ||
| <o line="2">dat</o> | ||
| </o> | ||
| </o> | ||
| </objects> | ||
| </program> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # 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: | ||
| - /org/eolang/lints/critical/pos-bigger-than-line.xsl | ||
| asserts: | ||
| - /defects[count(defect[@severity='critical'])=1] | ||
| - /defects/defect[@line='2'] | ||
| document: | | ||
| <program> | ||
| <objects> | ||
| <o line="2" pos="20" name="foo"> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @h1alexbel as I mentioned here, this example in EO will look like this: It almost legal in your case, BUT this EO line has more that 20 symbols which means no error should be caught |
||
| <o line="2" name="xyz"> | ||
| <o line="2">data</o> | ||
| </o> | ||
| </o> | ||
| </objects> | ||
| </program> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # 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: | ||
| - /org/eolang/lints/critical/pos-bigger-than-line.xsl | ||
| asserts: | ||
| - /defects[count(defect[@severity='critical'])=0] | ||
| document: | | ||
| <program> | ||
| <objects> | ||
| <o pos="15" name="foo"/> | ||
| </objects> | ||
| </program> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # 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: | ||
| - /org/eolang/lints/critical/pos-bigger-than-line.xsl | ||
| asserts: | ||
| - /defects[count(defect[@severity='critical'])=0] | ||
| document: | | ||
| <program> | ||
| <objects> | ||
| <o line="2" pos="3" name="foo"> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @h1alexbel this example in EO will look like this: Yes, it's legal in EO, the only part which is not allowed is most deepest abstract object. It can't contain data and it cant' be nameless |
||
| <o line="2" name="xyz"> | ||
| <o line="2">data</o> | ||
| </o> | ||
| </o> | ||
| </objects> | ||
| </program> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # 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: | ||
| - /org/eolang/lints/critical/pos-bigger-than-line.xsl | ||
| asserts: | ||
| - /defects[count(defect[@severity='critical'])=0] | ||
| document: | | ||
| <program> | ||
| <objects> | ||
| <o line="2" name="foo"/> | ||
| </objects> | ||
| </program> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@h1alexbel no, it still looks not correct to me.
Here's how I would try to implement it:
In general:
@name- it EO it looks like this> foo, which isfoolength + 2 extra symbols@base- it just@baselengthx (a b c) (y 1 2) (* (o 2) (q w e))you may see that that there are 10 braces and some amount of spaces without them, so they should be counted as wellMaybe there're some more patterns, I'm not sure, so the task is not such trivial as it seems to be