Skip to content

Commit

Permalink
Merge pull request #3653 from maxonfjvipon/fix/#3646/phi-nan
Browse files Browse the repository at this point in the history
fix(#3646): fixed converting to phi for primitives
  • Loading branch information
yegor256 authored Dec 12, 2024
2 parents 671021c + 2790ee7 commit de9d416
Show file tree
Hide file tree
Showing 9 changed files with 353 additions and 17 deletions.
25 changes: 13 additions & 12 deletions eo-parser/src/main/java/org/eolang/parser/StUnhex.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,18 @@ public StUnhex() {
StUnhex.class.getSimpleName(),
new StXPath(
StUnhex.xpath("number"),
xml -> StUnhex.append(
StUnhex.number(
StUnhex.buffer(
StUnhex.undash(xml.xpath("./o/text()").get(0))
).getDouble()
)
)
xml -> {
final double number = StUnhex.buffer(
StUnhex.undash(xml.xpath("./o/text()").get(0))
).getDouble();
final Iterable<Directive> dirs;
if (Double.isNaN(number) || Double.isInfinite(number)) {
dirs = new Directives().attr("skip", "");
} else {
dirs = StUnhex.append(StUnhex.number(number));
}
return dirs;
}
),
new StXPath(
StUnhex.xpath("string"),
Expand All @@ -74,10 +79,6 @@ public StUnhex() {
)
)
)
),
new StXPath(
"(//o[@data='bytes' and (@base='bytes' or @base='org.eolang.bytes') and empty(text())]/parent::o[(@base='string' or @base='org.eolang.string')])[1]",
xml -> new Directives().set("").attr("data", "string")
)
)
)
Expand Down Expand Up @@ -147,7 +148,7 @@ private static String undash(final String txt) {
*/
private static String xpath(final String type) {
return String.format(
"(//o[not(o) and string-length(normalize-space(text())) > 0 and (@base='bytes' or @base='org.eolang.bytes') and not(empty(text()))]/parent::o[(@base='%s' or @base='org.eolang.%1$s')])[1]",
"(//o[(@base='%s' or @base='org.eolang.%1$s') and(not(@skip)) and o[not(o) and string-length(normalize-space(text()))>0 and (@base='bytes' or @base='org.eolang.bytes')]])[1]",
type
);
}
Expand Down
11 changes: 8 additions & 3 deletions eo-parser/src/main/resources/org/eolang/parser/add-refs.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@ SOFTWARE.
-->
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:key name="o-by-name" match="o[@name]" use="@name"/>
<xsl:template match="o[not(@base='bytes' and /program/metas/meta[head='package' and tail='org.eolang'] and /program/objects/o[@name='bytes'])]">
<xsl:apply-templates select="." mode="not-bytes"/>
<xsl:variable name="primitives" as="element()*">
<a>bytes</a>
<a>string</a>
<a>number</a>
</xsl:variable>
<xsl:template match="o[not($primitives/text()=@base and /program/objects/o/@name=@base and /program/metas/meta[head='package' and tail='org.eolang'])]">
<xsl:apply-templates select="." mode="not-primitive"/>
</xsl:template>
<xsl:template match="o[@base]" mode="not-bytes">
<xsl:template match="o[@base]" mode="not-primitive">
<xsl:apply-templates select="." mode="with-base"/>
</xsl:template>
<xsl:template match="o[not(contains(@base, '.'))]" mode="with-base">
Expand Down
4 changes: 3 additions & 1 deletion eo-parser/src/test/java/org/eolang/parser/StUnhexTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ void convertsMaxIntFromHexToEo() {
"<p><o base='number'><o base='org.eolang.bytes'>FF-FF-FF-FF-FF-FF-FF-FF</o></o></p>"
)
),
XhtmlMatchers.hasXPaths("//o[text()='NaN']")
XhtmlMatchers.hasXPaths(
"//o[@base='number' and @skip and o[@base='org.eolang.bytes' and text()!='']]"
)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ asserts:
input: |
+package org.eolang
# No comments.
# Bytes.
[] > bytes
$.eq 01- > yes
# String.
[] > string
string > x
# Number.
[] > number
number > x
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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.
---
input: |
# Nan.
[] > nan
number 7F-F8-00-00-00-00-00-00 > @
with-sugar: |-
{
nan ↦ ⟦
φ ↦ Φ̇.number(Φ̇.bytes(⟦ Δ ⤍ 7F-F8-00-00-00-00-00-00 ⟧))
}
no-sugar: |-
{
nan ↦ ⟦
φ ↦ Φ.org.eolang.number(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ 7F-F8-00-00-00-00-00-00 ⟧
)
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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.
---
input: |
# Foo.
[] > negative-infinity
number FF-F0-00-00-00-00-00-00 > @
with-sugar: |-
{
negative-infinity ↦ ⟦
φ ↦ Φ̇.number(Φ̇.bytes(⟦ Δ ⤍ FF-F0-00-00-00-00-00-00 ⟧))
}
no-sugar: |-
{
negative-infinity ↦ ⟦
φ ↦ Φ.org.eolang.number(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ FF-F0-00-00-00-00-00-00 ⟧
)
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 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.
---
input: |
+package org.eolang
+alias org.eolang.txt.sprintf
# The `number` object is an abstraction of a 64-bit floating-point
[as-bytes] > number
$.times -1 > neg
with-sugar: |-
{
org ↦ ⟦
eolang ↦ ⟦
number ↦ ⟦
as-bytes ↦ ∅,
neg ↦ ξ.times(-1)
⟧,
λ ⤍ Package
⟧,
λ ⤍ Package
}
no-sugar: |-
{
org ↦ ⟦
eolang ↦ ⟦
number ↦ ⟦
as-bytes ↦ ∅,
neg ↦ ξ.times(
α0 ↦ Φ.org.eolang.number(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ BF-F0-00-00-00-00-00-00 ⟧
)
)
)
⟧,
λ ⤍ Package
⟧,
λ ⤍ Package
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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.
---
input: |
# Foo.
[] > positive-infinity
number 7F-F0-00-00-00-00-00-00 > @
with-sugar: |-
{
positive-infinity ↦ ⟦
φ ↦ Φ̇.number(Φ̇.bytes(⟦ Δ ⤍ 7F-F0-00-00-00-00-00-00 ⟧))
}
no-sugar: |-
{
positive-infinity ↦ ⟦
φ ↦ Φ.org.eolang.number(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ 7F-F0-00-00-00-00-00-00 ⟧
)
)
}
Loading

0 comments on commit de9d416

Please sign in to comment.