Skip to content

Commit

Permalink
bug(#3864): finished
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon committed Feb 9, 2025
1 parent 735c4fa commit 9c8773c
Show file tree
Hide file tree
Showing 10 changed files with 296 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ jobs:
key: ubuntu-surefire-jdk-21-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: ubuntu-surefire-jdk-21-maven-
- run: |
mvn clean install -PskipUTs --errors --batch-mode
mvn clean install -Deo:skipLinting -PskipUTs --errors --batch-mode
2 changes: 1 addition & 1 deletion .github/workflows/mvn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ jobs:
- uses: JesseTG/[email protected]
with:
path: ~/.m2/repository/org/eolang
- run: mvn clean install -PskipITs --errors --batch-mode
- run: mvn clean install -Deo:skipLinting -PskipITs --errors --batch-mode
21 changes: 21 additions & 0 deletions eo-maven-plugin/src/main/java/org/eolang/maven/LintMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,29 @@ public final class LintMojo extends SafeMojo {
@Parameter(property = "eo.lintAsPackage", required = true, defaultValue = "true")
private boolean lintAsPackage;

/**
* Whether we should skip linting at all.
*
* @checkstyle MemberNameCheck (11 lines)
*/
@SuppressWarnings("PMD.ImmutableField")
@Parameter(property = "eo.skipLinting", required = true, defaultValue = "false")
private boolean skipLinting;

@Override
void exec() throws IOException {
if (this.skipLinting) {
Logger.info(this, "Linting is skipped because eo:skipLinting is TRUE");
} else {
this.lint();
}
}

/**
* Lint.
* @throws IOException If fails
*/
private void lint() throws IOException {
final long start = System.currentTimeMillis();
final Collection<ForeignTojo> tojos = this.scopedTojos().withShaken();
final ConcurrentHashMap<Severity, Integer> counts = new ConcurrentHashMap<>();
Expand Down
19 changes: 12 additions & 7 deletions eo-parser/src/main/java/org/eolang/parser/Xmir.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.yegor256.xsline.StEndless;
import com.yegor256.xsline.TrClasspath;
import com.yegor256.xsline.TrDefault;
import com.yegor256.xsline.TrJoined;
import com.yegor256.xsline.Train;
import com.yegor256.xsline.Xsline;
import java.util.Collection;
Expand Down Expand Up @@ -61,14 +62,18 @@ public final class Xmir implements XML {
* Train of transformations that prepare XMIR for conversion to EO.
*/
private static final Train<Shift> FOR_EO = new TrFull(
new TrDefault<>(
new StEndless(
new StClasspath("/org/eolang/parser/print/tuples-to-stars.xsl")
new TrJoined<>(
new TrDefault<>(
new StEndless(
new StClasspath("/org/eolang/parser/print/tuples-to-stars.xsl")
)
),
new StClasspath("/org/eolang/parser/print/dataized-to-const.xsl"),
new StClasspath("/org/eolang/parser/print/unhex-data.xsl"),
new StClasspath("/org/eolang/parser/print/wrap-data.xsl"),
new StClasspath("/org/eolang/parser/print/to-eo.xsl")
new TrClasspath<>(
"/org/eolang/parser/print/dataized-to-const.xsl",
"/org/eolang/parser/print/unhex-data.xsl",
"/org/eolang/parser/print/wrap-data.xsl",
"/org/eolang/parser/print/to-eo.xsl"
).back()
)
);

Expand Down
105 changes: 91 additions & 14 deletions eo-parser/src/main/resources/org/eolang/parser/_funcs.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,57 @@ SOFTWARE.
<xsl:param name="o" as="element()"/>
<xsl:sequence select="$o/@base='∅'"/>
</xsl:function>
<xsl:function name="eo:hex-to-utf8" as="xs:string">
<xsl:param name="hex" as="xs:string"/>
<xsl:variable name="hex-upper" select="upper-case(normalize-space($hex))"/>
<xsl:variable name="length" select="string-length($hex-upper)"/>
<xsl:variable name="hex-digits" select="string-to-codepoints('0123456789ABCDEF')"/>
<xsl:variable name="decimal" select="sum(for $i in 1 to $length return (index-of($hex-digits, string-to-codepoints(substring($hex-upper, $i, 1))) - 1) * math:pow(16, $length - $i))"/>
<xsl:value-of select="codepoints-to-string(xs:int($decimal))"/>
</xsl:function>
<!-- BYTES TO STRING -->
<xsl:function name="eo:bytes-to-string" as="xs:string">
<xsl:param name="bytes" as="xs:string"/>
<xsl:choose>
<xsl:when test="$bytes = '--'">
<xsl:sequence select="''"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="byte-values" select="for $byte in tokenize($bytes, '-') return eo:hex-to-utf8($byte)"/>


<xsl:sequence select="string-join(for $byte in tokenize($bytes, '-') return eo:hex-to-utf8($byte), '')"/>
<xsl:variable name="decoded">
<xsl:for-each select="eo:decode-bytes(for $byte in (if (ends-with($bytes, '-')) then substring-before($bytes, '-') else tokenize($bytes, '-')) return eo:hex-to-utf8($byte))">
<xsl:choose>
<xsl:when test=".=10">
<xsl:value-of select="'\n'"/>
</xsl:when>
<xsl:when test=".=9">
<xsl:value-of select="'\t'"/>
</xsl:when>
<xsl:when test=".=13">
<xsl:value-of select="'\r'"/>
</xsl:when>
<!-- Keep ASCII characters -->
<xsl:when test=". ge 32 and . le 126">
<xsl:variable name="char" select="codepoints-to-string(.)"/>
<xsl:if test="$char='\' or $char='&quot;'">
<xsl:text>\</xsl:text>
</xsl:if>
<xsl:value-of select="$char"/>
</xsl:when>
<!-- Convert non-ASCII to \uXXXX -->
<xsl:when test=". le 65535">
<xsl:value-of select="concat('\u', eo:int-to-hex(xs:int(.)))"/>
</xsl:when>
<!-- Handle surrogate pairs for code points above U+FFFF -->
<xsl:otherwise>
<!-- 55296 = 0xD800 -->
<xsl:variable name="cp1" select="xs:int(floor((. - 65536) div 1024) + 55296)"/>
<!-- 56320 = 0xDC00 -->
<xsl:variable name="cp2" select="xs:int(((. - 65536) mod 1024) + 56320)"/>
<xsl:value-of select="concat('\u', eo:int-to-hex($cp1), '\u', eo:int-to-hex($cp2))"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:variable>
<xsl:sequence select="$decoded"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<!-- Convert string bytes sequence to double number, e.g. 40-14-00-00-00-00-00-00 => 5 -->
<!-- BYTES TO NUMBER, e.g. 40-14-00-00-00-00-00-00 => 5 -->
<xsl:function name="eo:bytes-to-number" as="xs:anyAtomicType">
<xsl:param name="bytes"/>
<!-- Undash -->
<xsl:variable name="hex" select="translate($bytes, '-', '')"/>
<xsl:variable name="map" as="element()*">
<entry h="0" b="0000"/>
Expand All @@ -80,13 +106,64 @@ SOFTWARE.
<entry h="F" b="1111"/>
</xsl:variable>
<xsl:variable name="bin" as="xs:string" select="string-join(for $c in string-to-codepoints(upper-case($hex)) return $map[@h = codepoints-to-string($c)]/@b, '')"/>
<!-- Sign bit (1 for negative, 0 for positive) -->
<xsl:variable name="sign" select="if (substring($bin, 1, 1) = '1') then -1 else 1"/>
<!-- Extract exponent (11 bits) and convert to integer -->
<xsl:variable name="exponentBits" select="substring($bin, 2, 11)"/>
<xsl:variable name="exponent" select="sum(for $i in 1 to string-length($exponentBits) return xs:double(substring($exponentBits, $i, 1)) * math:pow(2, string-length($exponentBits) - $i)) - 1023"/>
<!-- Extract mantissa (52 bits) -->
<xsl:variable name="mantissaBits" select="substring($bin, 13, 52)"/>
<xsl:variable name="mantissaValue">
<xsl:sequence select="sum(for $i in 1 to string-length($mantissaBits) return xs:double(substring($mantissaBits, $i, 1)) * math:pow(2, -$i))"/>
<xsl:sequence select="sum(for $i in 1 to string-length($mantissaBits) return xs:double(substring($mantissaBits, $i, 1)) div math:pow(2, $i))"/>
</xsl:variable>
<!-- Compute final double value -->
<xsl:sequence select="$sign * (1 + $mantissaValue) * math:pow(2, $exponent)"/>
</xsl:function>
<!-- HELPER FUNCTIONS -->
<!-- Function to decode UTF-8 bytes into Unicode code points -->
<xsl:function name="eo:decode-bytes" as="xs:integer*">
<xsl:param name="bytes" as="xs:integer*"/>
<xsl:choose>
<!-- 1-byte sequence: 0xxxxxxx -->
<xsl:when test="$bytes[1] lt 128">
<xsl:sequence select="$bytes[1]"/>
<xsl:sequence select="eo:decode-bytes(subsequence($bytes, 2))"/>
</xsl:when>
<!-- 2-byte sequence: 110xxxxx 10xxxxxx -->
<xsl:when test="$bytes[1] ge 192 and $bytes[1] lt 224">
<xsl:variable name="code-point" select="(($bytes[1] - 192) * 64) + ($bytes[2] - 128)"/>
<xsl:sequence select="$code-point"/>
<xsl:sequence select="eo:decode-bytes(subsequence($bytes, 3))"/>
</xsl:when>
<!-- 3-byte sequence: 1110xxxx 10xxxxxx 10xxxxxx -->
<xsl:when test="$bytes[1] ge 224 and $bytes[1] lt 240">
<xsl:variable name="code-point" select="(($bytes[1] - 224) * 4096) + (($bytes[2] - 128) * 64) + ($bytes[3] - 128)"/>
<xsl:sequence select="$code-point"/>
<xsl:sequence select="eo:decode-bytes(subsequence($bytes, 4))"/>
</xsl:when>
<!-- 4-byte sequence: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx -->
<xsl:when test="$bytes[1] ge 240 and $bytes[1] lt 248">
<xsl:variable name="code-point" select="(($bytes[1] - 240) * 262144) + (($bytes[2] - 128) * 4096) + (($bytes[3] - 128) * 64) + ($bytes[4] - 128)"/>
<xsl:sequence select="$code-point"/>
<xsl:sequence select="eo:decode-bytes(subsequence($bytes, 5))"/>
</xsl:when>
<!-- Otherwise, return empty (should not occur if input is valid UTF-8) -->
<xsl:otherwise/>
</xsl:choose>
</xsl:function>
<!-- Function to convert integer to 4-digit hex string -->
<xsl:function name="eo:int-to-hex" as="xs:string">
<xsl:param name="value" as="xs:integer"/>
<xsl:variable name="hex-chars" select="'0123456789ABCDEF'"/>
<xsl:variable name="hex" select="concat(substring($hex-chars, floor($value idiv 4096) + 1, 1), substring($hex-chars, floor(($value mod 4096) idiv 256) + 1, 1), substring($hex-chars, floor(($value mod 256) idiv 16) + 1, 1), substring($hex-chars, ($value mod 16) + 1, 1))"/>
<xsl:sequence select="$hex"/>
</xsl:function>
<xsl:function name="eo:hex-to-utf8" as="xs:integer">
<xsl:param name="hex" as="xs:string"/>
<xsl:variable name="hex-upper" select="upper-case(normalize-space($hex))"/>
<xsl:variable name="length" select="string-length($hex-upper)"/>
<xsl:variable name="hex-digits" select="string-to-codepoints('0123456789ABCDEF')"/>
<xsl:variable name="decimal" select="sum(for $i in 1 to $length return (index-of($hex-digits, string-to-codepoints(substring($hex-upper, $i, 1))) - 1) * math:pow(16, $length - $i))"/>
<xsl:value-of select="xs:int($decimal)"/>
</xsl:function>
</xsl:stylesheet>
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ SOFTWARE.
</xsl:template>
<xsl:template match="o[@base='Q.org.eolang.number' and o[1][eo:has-data(.)]]">
<xsl:variable name="bytes" select="o[1]/text()"/>
<xsl:variable name="num" select="eo:bytes-to-number($bytes)"/>
<xsl:choose>
<xsl:when test="$bytes='7F-F8-00-00-00-00-00-00' or $bytes='7F-F0-00-00-00-00-00-00' or $bytes='FF-F0-00-00-00-00-00-00'">
<xsl:copy-of select="."/>
Expand All @@ -58,7 +57,7 @@ SOFTWARE.
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:value-of select="$num"/>
<xsl:value-of select="eo:bytes-to-number($bytes)"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2025 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: |
# No comments.
[] > main
regex "/^[\\x00-\\x7F]*$/" > rgx
"foo\\bar<:>?*\"|baz\\asdf" > ptn
sweet: |-
{⟦
main ↦ ⟦
rgx ↦ Φ̇.regex("/^[\\x00-\\x7F]*$/"),
ptn ↦ "foo\\bar<:>?*\"|baz\\asdf"
⟧}
salty: |-
{
main ↦ ⟦
rgx ↦ Φ.org.eolang.regex(
α0 ↦ Φ.org.eolang.string(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ 2F-5E-5B-5C-78-30-30-2D-5C-78-37-46-5D-2A-24-2F ⟧
)
)
),
ptn ↦ Φ.org.eolang.string(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ 66-6F-6F-5C-62-61-72-3C-3A-3E-3F-2A-22-7C-62-61-7A-5C-61-73-64-66 ⟧
)
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2025 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: |
# No comments.
[] > main
"🌵" > cactoos
"😀" > smile
sweet: |-
{⟦
main ↦ ⟦
cactoos ↦ "\uD83C\uDF35",
smile ↦ "\uD83D\uDE00"
⟧}
salty: |-
{
main ↦ ⟦
cactoos ↦ Φ.org.eolang.string(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ F0-9F-8C-B5 ⟧
)
),
smile ↦ Φ.org.eolang.string(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ F0-9F-98-80 ⟧
)
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2025 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.
---
origin: |
# No comments.
[] > main
regex "/^[\\x00-\\x7F]*$/" > rgx
printed: |
# No comments.
[] > main
regex > rgx
"/^[\\x00-\\x7F]*$/"
Loading

0 comments on commit 9c8773c

Please sign in to comment.