Skip to content

Commit

Permalink
bug(objectionary#3481): tuple and seq
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon committed Jan 17, 2025
1 parent 9282cd6 commit 919e923
Show file tree
Hide file tree
Showing 18 changed files with 129 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
---
skip: true
locators:
- .org .eolang .test
- .org .eolang .number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ sheets:
- /org/eolang/maven/transpile/to-java.xsl
asserts:
- /program[not(errors)]
- //java[contains(text(), 'Phi r = Phi.Φ.take("org").take("eolang").take("tuple");')]
- //java[contains(text(), ' Phi r1 = Phi.Φ.take("org").take("eolang").take("tuple");')]
- //java[contains(text(), ' Phi r11 = Phi.Φ.take("org").take("eolang").take("tuple");')]
- //java[contains(text(), ' Phi r111b = Phi.Φ.take("org").take("eolang").take("tuple");')]
- //java[contains(text(), ' Phi r111 = new PhMethod(r111b, "empty");')]
- //java[contains(text(), ' Phi r2 = Phi.Φ.take("org").take("eolang").take("tuple");')]
- //java[contains(text(), ' Phi r21 = Phi.Φ.take("org").take("eolang").take("tuple");')]
- //java[contains(text(), ' Phi r211b = Phi.Φ.take("org").take("eolang").take("tuple");')]
- //java[contains(text(), ' Phi r211 = new PhMethod(r211b, "empty");')]
- //java[contains(text(), ' Phi rbbbb = Phi.Φ.take("org").take("eolang").take("tuple");')]
- //java[contains(text(), ' Phi rbbb = new PhMethod(rbbbb, "empty");')]
- //java[contains(text(), ' Phi rbbb = new PhMethod(rbbbb, "empty");')]
- //java[contains(text(), ' rbb = new PhWith(rbb, 0, rbb1);')]
- //java[contains(text(), ' Phi rb = new PhMethod(rbb, "with");')]
- //java[contains(text(), ' rb = new PhWith(rb, 0, rb1);')]
- //java[contains(text(), ' Phi r = new PhMethod(rb, "with");')]
input: |
# No comments.
[] > foo
Expand Down
30 changes: 8 additions & 22 deletions eo-parser/src/main/java/org/eolang/parser/TrCanonical.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@
*/
package org.eolang.parser;

import com.yegor256.xsline.StClasspath;
import com.yegor256.xsline.StEndless;
import com.yegor256.xsline.TrClasspath;
import com.yegor256.xsline.TrDefault;
import com.yegor256.xsline.TrEnvelope;
import com.yegor256.xsline.TrJoined;

/**
* Train of XSL shifts that turn XMIR into canonical one.
Expand All @@ -42,24 +38,14 @@ final class TrCanonical extends TrEnvelope {
TrCanonical() {
super(
new TrFull(
new TrJoined<>(
new TrClasspath<>(
"/org/eolang/parser/parse/move-voids-up.xsl",
"/org/eolang/parser/parse/validate-before-stars.xsl",
"/org/eolang/parser/parse/resolve-before-star.xsl"
).back(),
new TrDefault<>(
new StEndless(
new StClasspath(
"/org/eolang/parser/parse/stars-to-tuples.xsl"
)
)
),
new TrClasspath<>(
"/org/eolang/parser/parse/wrap-method-calls.xsl",
"/org/eolang/parser/parse/const-to-dataized.xsl"
).back()
)
new TrClasspath<>(
"/org/eolang/parser/parse/move-voids-up.xsl",
"/org/eolang/parser/parse/validate-before-stars.xsl",
"/org/eolang/parser/parse/resolve-before-star.xsl",
"/org/eolang/parser/parse/wrap-method-calls.xsl",
"/org/eolang/parser/parse/const-to-dataized.xsl",
"/org/eolang/parser/parse/stars-to-tuples.xsl"
).back()
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,68 +49,29 @@ SOFTWARE.
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:template match="o[@star]">
<xsl:choose>
<xsl:when test="count(o)=0">
<xsl:choose>
<xsl:when test="count(following-sibling::o)=0 or following-sibling::o[1][not(@base) or @base!='.empty']">
<o>
<xsl:for-each select="@*[name()!='star' and name()!='name']">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
</o>
<o base=".empty" method="">
<xsl:if test="./@name">
<xsl:attribute name="name">
<xsl:value-of select="./@name"/>
</xsl:attribute>
</xsl:if>
<xsl:attribute name="line">
<xsl:value-of select="./@line"/>
</xsl:attribute>
<xsl:attribute name="pos">
<xsl:value-of select="./@pos+1"/>
</xsl:attribute>
</o>
</xsl:when>
<xsl:otherwise>
<o>
<xsl:for-each select="@*[name()!='star']">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
</o>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="count(o[not(@method)])=1">
<o>
<xsl:for-each select="@*[name()!='star']">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<o base="tuple"/>
<o base=".empty" method=""/>
<xsl:copy-of select="o"/>
</o>
</xsl:when>
<xsl:when test="count(o[not(@method)])&gt;1">
<o>
<xsl:for-each select="@*[name()!='star']">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<o base="tuple" star="">
<xsl:for-each select="o[not(@method)][last()]/preceding-sibling::o">
<xsl:copy-of select="."/>
</xsl:for-each>
</o>
<xsl:copy-of select="o[not(@method)][last()] | o[not(@method)][last()]/following-sibling::o"/>
</o>
<xsl:when test="count(o)&gt;0">
<xsl:variable name="nested">
<xsl:element name="o">
<xsl:attribute name="star"/>
<xsl:apply-templates select="o[position()!=last()]"/>
</xsl:element>
</xsl:variable>
<xsl:element name="o">
<xsl:attribute name="base" select="'.with'"/>
<xsl:apply-templates select="@* except (@star | @base)"/>
<xsl:apply-templates select="$nested"/>
<xsl:apply-templates select="o[last()]"/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="o">
<xsl:attribute name="base" select="'.empty'"/>
<xsl:apply-templates select="@* except (@star | @base)"/>
<xsl:element name="o">
<xsl:attribute name="base" select="'tuple'"/>
</xsl:element>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="node()|@*">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,20 @@ SOFTWARE.
Performs the reverse operation of "/org/eolang/parser/stars-to-tuples.xsl"
-->
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:template match="o[@base='.empty' and o[position()=1 and @base='tuple' or @base='org.eolang.tuple']]">
<xsl:template match="o[@base='.empty' and o[1][@base='tuple' or @base='org.eolang.tuple']]">
<xsl:element name="o">
<xsl:attribute name="star"/>
<xsl:for-each select="@* except @base">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:attribute name="base" select="'tuple'"/>
<xsl:apply-templates select="@* except @base"/>
</xsl:element>
</xsl:template>
<xsl:template match="o[(@base='tuple' or @base='org.eolang.tuple') and o[position()=1 and @star and @base='tuple']]">
<xsl:template match="o[@base='.with' and o[1][@star]]">
<xsl:element name="o">
<xsl:attribute name="star"/>
<xsl:for-each select="@* except base">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:attribute name="base" select="'tuple'"/>
<xsl:for-each select="o[@star]/o">
<xsl:copy-of select="."/>
</xsl:for-each>
<xsl:for-each select="o[not(@star)]">
<xsl:copy-of select="."/>
</xsl:for-each>
<xsl:apply-templates select="@* except @base"/>
<xsl:copy-of select="o[@star]/o"/>
<xsl:copy-of select="o[not(@star)]"/>
</xsl:element>
</xsl:template>
<xsl:template match="node()|@*">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
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//o[@name='first' and count(o)=1]/o[@base='.with' and count(o)=2]
- /program/objects//o[@name='second' and count(o)=2]/o[position()=2 and @base='.with' and count(o)=2]
- /program/objects//o[@name='third' and count(o)=3]/o[position()=3 and @base='.with' and count(o)=2]
- /program/objects//o[@name='fourth' and count(o)=2]/o[@base='sprintf' and count(o)=1]/o[@base='.with' and count(o)=2]
- /program/objects[count(//o[@before-star])=0]
input: |
# No comments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,25 @@ sheets: [ ]
asserts:
- //objects[count(o)=7]
- //objects[count(//o[@star])=0]
- //o[@base='.empty' and @line=1 and @name='xs']/o[@base='tuple' and @line=1 and not(@name)]
- //o[@base='tuple' and @line=2 and @name='xl']/o[@base='.empty']/o[@base='tuple']
- //o[@base='tuple' and @line=2 and @name='xl']/o[@base='number']
- //o[@base='tuple' and @line=3]/o[@base='number']
- //o[@base='tuple' and @line=3]/o[@base='tuple']/o[@base='.empty']/o[@base='tuple']
- //o[@base='tuple' and @line=3]/o[@base='tuple']/o[@base='number']
- //o[@base='.empty' and @line=4]/o[@base='tuple']
# first
- //o[@base='.empty' and @line=1 and @name='xs']/o[@base='tuple' and not(@name)]
# second
- //o[@base='.with' and @line=2 and @name='xl']/o[@base='.empty']/o[@base='tuple']
- //o[@base='.with' and @line=2 and @name='xl']/o[@base='number']
# third
- //o[@base='.with' and @line=3 and not(@name)]/o[@base='.with']/o[@base='.empty']/o[@base='tuple']
- //o[@base='.with' and @line=3 and not(@name)]/o[@base='.with']/o[@base='number']
- //o[@base='.with' and @line=3 and not(@name)]/o[@base='number']
# fourth
- //o[@base='.empty' and @line=4]/o[@base='.empty']/o[@base='tuple']
# fifth
- //o[@base='.with' and @line=5 and not(@name)]/o[@base='.with']/o[@base='.with']/o[@base='.empty']/o[@base='tuple']
- //o[@base='.with' and @line=5 and not(@name)]/o[@base='.with']/o[@base='.with']/o[@base='.c']
- //o[@base='.with' and @line=5 and not(@name)]/o[@base='.with']/o[@base='.f']
- //o[@base='.with' and @line=5 and not(@name)]/o[@base='.i']
# sixth
- //o[@base='.elements']/o[@base='arr']/o[@base='.empty']/o[@base='tuple']
# seventh
- //o[@base='.reduced']/o[@base='list']
- //o[@base='.reduced']/o[@base='.empty']/o[@base='tuple']
- //o[@base='.reduced']/o[not(@base)]/o[@base='∅' and @name='x']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ input: |
# No comments.
[] > foo
tuple
tuple
tuple
with.
with.
with.
tuple.empty
1
2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ asserts:
- //o[@base='org.eolang.string' and @loc='Φ.org.abc.a.φ.α0.α0']
- //o[@base='x' and @name='tt' and @loc='Φ.org.abc.tt']
- //o[@base='org.eolang.number' and @loc='Φ.org.abc.tt.α0']
- //o[@base='org.eolang.tuple' and @loc='Φ.org.abc.tt.α1']
- //o[@base='org.eolang.number' and @loc='Φ.org.abc.tt.α1.α1']
- //o[@base='org.eolang.tuple' and @loc='Φ.org.abc.tt.α1.ρ.ρ.ρ']
- //o[@base='org.eolang.number' and @loc='Φ.org.abc.tt.α1.ρ.α0']
- //o[not(@base) and @loc='Φ.org.abc.tt.α2']
- //o[@base='∅' and @name='e' and @loc='Φ.org.abc.tt.α2.e']
- //o[@base='.hello' and @loc='Φ.org.abc.tt.α2.φ']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ asserts:
- //o[@base='org.eolang.bytes' and @name='fourth' and not(o) and text()='11-21']
- //o[@base='.string' and @name='str' and count(o)=2 and o[last() and @base='org.eolang.bytes' and text()='48-65-79']]
- //o[@base='org.eolang.bytes' and @name='bt' and count(o)=0 and text()='A2-']
- //o[@base='org.eolang.tuple' and o[@base='org.eolang.tuple' and o[@base='org.eolang.number' and o[@base='org.eolang.bytes' and text()='3F-F0-00-00-00-00-00-00']]]]
- //o[@base='.with']/o[@base='.with']/o[@base='.with']/o[@base='org.eolang.number']/o[@base='org.eolang.bytes' and text()='3F-F0-00-00-00-00-00-00']
input: |
42 > first
number 11-21 > bts
Expand All @@ -41,6 +41,6 @@ input: |
11-21
Q.org.eolang.string "Hey" > str
Q.org.eolang.bytes A2- > bt
tuple
*
* 1
2
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ sweet: |-
j$A ↦ ⟦
access ↦ 32,
supername ↦ "java/lang/Object",
interfaces ↦ Φ̇.tuple(Φ̇.tuple.empty, "org/eolang/benchmark/F")
interfaces ↦ Φ̇.tuple.empty.with("org/eolang/benchmark/F")
⟧,
λ ⤍ Package
⟧,
Expand All @@ -63,9 +63,8 @@ salty: |-
α0 ↦ ⟦ Δ ⤍ 6A-61-76-61-2F-6C-61-6E-67-2F-4F-62-6A-65-63-74 ⟧
)
),
interfaces ↦ Φ.org.eolang.tuple(
α0 ↦ Φ.org.eolang.tuple.empty,
α1 ↦ Φ.org.eolang.string(
interfaces ↦ Φ.org.eolang.tuple.empty.with(
α0 ↦ Φ.org.eolang.string(
α0 ↦ Φ.org.eolang.bytes(
α0 ↦ ⟦ Δ ⤍ 6F-72-67-2F-65-6F-6C-61-6E-67-2F-62-65-6E-63-68-6D-61-72-6B-2F-46 ⟧
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ sweet: |-
Φ̇.error(
Φ̇.txt.sprintf(
"Expected %d byte character at %d index, but there are not enough bytes for it: %x",
Φ̇.tuple(
Φ̇.tuple(Φ̇.tuple(Φ̇.tuple.empty, ξ.char-size), ξ.index), ξ.ρ.ρ.as-bytes
Φ̇.tuple.empty.with(ξ.char-size).with(ξ.index).with(
ξ.ρ.ρ.as-bytes
)
)
)
Expand Down Expand Up @@ -87,15 +87,12 @@ salty: |-
α0 ↦ ⟦ Δ ⤍ 45-78-70-65-63-74-65-64-20-25-64-20-62-79-74-65-20-63-68-61-72-61-63-74-65-72-20-61-74-20-25-64-20-69-6E-64-65-78-2C-20-62-75-74-20-74-68-65-72-65-20-61-72-65-20-6E-6F-74-20-65-6E-6F-75-67-68-20-62-79-74-65-73-20-66-6F-72-20-69-74-3A-20-25-78 ⟧
)
),
α1 ↦ Φ.org.eolang.tuple(
α0 ↦ Φ.org.eolang.tuple(
α0 ↦ Φ.org.eolang.tuple(
α0 ↦ Φ.org.eolang.tuple.empty,
α1 ↦ ξ.char-size
),
α1 ↦ ξ.index
),
α1 ↦ ξ.ρ.ρ.as-bytes
α1 ↦ Φ.org.eolang.tuple.empty.with(
α0 ↦ ξ.char-size
).with(
α0 ↦ ξ.index
).with(
α0 ↦ ξ.ρ.ρ.as-bytes
)
)
)
Expand Down
23 changes: 12 additions & 11 deletions eo-runtime/src/main/eo/org/eolang/seq.eo
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,22 @@
if. > @
steps.length.eq 0
true
loop 0
steps.length.minus 1 > max-len!
if.
steps.length.eq 1
steps.tail
loop steps
steps.length.plus -1 > last-index!

# Recursive steps dataization.
#
# Attention! The object is for internal usage only, please
# don't use the object programmatically outside of `seq` object.
[index] > loop
[tup] > loop
if. > @
and.
index.lt max-len
or.
(dataized (steps.at index)).as-bool
true
loop
index.plus 1
steps.at index

tup.length.gt 1
loop tup.head
tup.tail
or.
(dataized tup.tail).as-bool.eq --
tup.length.eq last-index
Loading

0 comments on commit 919e923

Please sign in to comment.