From 38e31bd0e03c26ce37fe1b46e1db9f7814669c63 Mon Sep 17 00:00:00 2001 From: maxonfjvipon Date: Wed, 18 Dec 2024 15:22:27 +0300 Subject: [PATCH 1/3] bug(#3619): grammar --- .../src/main/antlr4/org/eolang/parser/Eo.g4 | 5 +++ .../java/org/eolang/parser/XeEoListener.java | 45 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/eo-parser/src/main/antlr4/org/eolang/parser/Eo.g4 b/eo-parser/src/main/antlr4/org/eolang/parser/Eo.g4 index aa1bb19eac..929074c754 100644 --- a/eo-parser/src/main/antlr4/org/eolang/parser/Eo.g4 +++ b/eo-parser/src/main/antlr4/org/eolang/parser/Eo.g4 @@ -239,6 +239,11 @@ vapplicationHead | versioned ; +// Compact arrays +compactArray + : NAME SPACE STAR INT? + ; + // Vertical application head with optional name vapplicationHeadNamed : vapplicationHead oname? diff --git a/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java b/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java index 830a67070b..c65fedd6b6 100644 --- a/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java +++ b/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java @@ -522,6 +522,51 @@ public void exitVapplicationHead(final EoParser.VapplicationHeadContext ctx) { // Nothing here } + @Override + public void enterCompactArray(final EoParser.CompactArrayContext ctx) { + if (ctx.INT() != null) { + final String num = ctx.INT().getText(); + if (num.charAt(0) == '+' + || num.charAt(0) == '-' + || (num.length() > 1 && num.charAt(0) == '0') + || Integer.parseInt(num) < 0 + ) { + this.errors.put( + ctx, + "Index after '*' must be a positive integer without leading zero or arithmetic signs" + ); + } + } + this.startObject(ctx) + .prop("base", ctx.NAME().getText()) + .start( + ctx.getStart().getLine(), + ctx.getStart().getCharPositionInLine() + ctx.NAME().getText().length() + 1 + ) + .prop("base", "tuple") + .prop("star"); + +// if (ctx.STAR() != null) { +// base = "tuple"; +// this.objects.prop("star"); +// } else if (ctx.NAME() != null) { +// base = ctx.NAME().getText(); +// } else if (ctx.PHI() != null) { +// base = "@"; +// } else { +// base = ""; +// } +// if (!base.isEmpty()) { +// this.objects.prop("base", base); +// } + this.objects.leave(); + } + + @Override + public void exitCompactArray(final EoParser.CompactArrayContext ctx) { + // Nothing here + } + @Override public void enterVapplicationHeadNamed(final EoParser.VapplicationHeadNamedContext ctx) { // Nothing here From e06261a65349a995b51b0cadbc23ffe566f25d25 Mon Sep 17 00:00:00 2001 From: maxonfjvipon Date: Thu, 26 Dec 2024 17:58:24 +0300 Subject: [PATCH 2/3] bug(#3619): Sugar for tuples --- .../src/main/antlr4/org/eolang/parser/Eo.g4 | 1 + .../main/java/org/eolang/parser/EoSyntax.java | 9 ++- .../java/org/eolang/parser/TrCanonical.java | 4 + .../java/org/eolang/parser/XeEoListener.java | 31 ++------ .../org/eolang/parser/resolve-before-star.xsl | 71 ++++++++++++++++++ .../eolang/parser/validate-before-stars.xsl | 74 +++++++++++++++++++ .../java/org/eolang/parser/TrParsingTest.java | 3 +- .../eolang/parser/eo-packs/full-syntax.yaml | 3 + .../parser/eo-packs/syntax/before-star.yaml | 51 +++++++++++++ eo-runtime/src/main/eo/org/eolang/bytes.eo | 2 +- eo-runtime/src/main/eo/org/eolang/fs/dir.eo | 25 +++---- eo-runtime/src/main/eo/org/eolang/fs/file.eo | 55 ++++++-------- .../src/main/eo/org/eolang/io/console.eo | 40 +++++----- .../main/eo/org/eolang/io/malloc-as-output.eo | 9 +-- .../src/main/eo/org/eolang/io/stdout.eo | 7 +- .../src/main/eo/org/eolang/io/tee-input.eo | 11 ++- eo-runtime/src/main/eo/org/eolang/malloc.eo | 14 ++-- .../src/main/eo/org/eolang/math/integral.eo | 34 ++++----- .../src/main/eo/org/eolang/net/socket.eo | 14 ++-- .../src/main/eo/org/eolang/structs/list.eo | 7 +- eo-runtime/src/main/eo/org/eolang/while.eo | 7 +- .../resources/org/eolang/snippets/simple.yaml | 13 ++-- 22 files changed, 326 insertions(+), 159 deletions(-) create mode 100644 eo-parser/src/main/resources/org/eolang/parser/resolve-before-star.xsl create mode 100644 eo-parser/src/main/resources/org/eolang/parser/validate-before-stars.xsl create mode 100644 eo-parser/src/test/resources/org/eolang/parser/eo-packs/syntax/before-star.yaml diff --git a/eo-parser/src/main/antlr4/org/eolang/parser/Eo.g4 b/eo-parser/src/main/antlr4/org/eolang/parser/Eo.g4 index b96dc19ea1..483fb2e4dc 100644 --- a/eo-parser/src/main/antlr4/org/eolang/parser/Eo.g4 +++ b/eo-parser/src/main/antlr4/org/eolang/parser/Eo.g4 @@ -231,6 +231,7 @@ vapplicationHead : applicable | hmethod | vmethod + | compactArray ; // Compact arrays diff --git a/eo-parser/src/main/java/org/eolang/parser/EoSyntax.java b/eo-parser/src/main/java/org/eolang/parser/EoSyntax.java index 7b3be07cdd..b7bdc7ab24 100644 --- a/eo-parser/src/main/java/org/eolang/parser/EoSyntax.java +++ b/eo-parser/src/main/java/org/eolang/parser/EoSyntax.java @@ -68,12 +68,19 @@ public final class EoSyntax implements Syntax { * Ctor. * * @param ipt The EO program to parse - * @since 0.40.0 */ public EoSyntax(final Input ipt) { this("unknown", ipt); } + /** + * Ctor. + * @param ipt The EO program to parse + */ + public EoSyntax(final String ipt) { + this("unknown", ipt); + } + /** * Ctor. * diff --git a/eo-parser/src/main/java/org/eolang/parser/TrCanonical.java b/eo-parser/src/main/java/org/eolang/parser/TrCanonical.java index 373b630819..e7071ecd7a 100644 --- a/eo-parser/src/main/java/org/eolang/parser/TrCanonical.java +++ b/eo-parser/src/main/java/org/eolang/parser/TrCanonical.java @@ -50,6 +50,10 @@ public TrCanonical() { new TrLambda( new TrLogged( new TrJoined<>( + new TrClasspath<>( + "/org/eolang/parser/validate-before-stars.xsl", + "/org/eolang/parser/resolve-before-star.xsl" + ).back(), new TrDefault<>( new StEndless( new StClasspath( diff --git a/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java b/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java index 0983b290a0..aef01cd29e 100644 --- a/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java +++ b/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java @@ -524,11 +524,12 @@ public void exitVapplicationHead(final EoParser.VapplicationHeadContext ctx) { @Override public void enterCompactArray(final EoParser.CompactArrayContext ctx) { + final int count; if (ctx.INT() != null) { final String num = ctx.INT().getText(); if (num.charAt(0) == '+' || num.charAt(0) == '-' - || (num.length() > 1 && num.charAt(0) == '0') + || num.length() > 1 && num.charAt(0) == '0' || Integer.parseInt(num) < 0 ) { this.errors.put( @@ -536,35 +537,19 @@ public void enterCompactArray(final EoParser.CompactArrayContext ctx) { "Index after '*' must be a positive integer without leading zero or arithmetic signs" ); } + final int number = Integer.parseInt(num); + count = Math.max(number, 0); + } else { + count = 0; } this.startObject(ctx) .prop("base", ctx.NAME().getText()) - .start( - ctx.getStart().getLine(), - ctx.getStart().getCharPositionInLine() + ctx.NAME().getText().length() + 1 - ) - .prop("base", "tuple") - .prop("star"); - -// if (ctx.STAR() != null) { -// base = "tuple"; -// this.objects.prop("star"); -// } else if (ctx.NAME() != null) { -// base = ctx.NAME().getText(); -// } else if (ctx.PHI() != null) { -// base = "@"; -// } else { -// base = ""; -// } -// if (!base.isEmpty()) { -// this.objects.prop("base", base); -// } - this.objects.leave(); + .prop("before-star", count); } @Override public void exitCompactArray(final EoParser.CompactArrayContext ctx) { - // Nothing here + this.objects.leave(); } @Override diff --git a/eo-parser/src/main/resources/org/eolang/parser/resolve-before-star.xsl b/eo-parser/src/main/resources/org/eolang/parser/resolve-before-star.xsl new file mode 100644 index 0000000000..677b487864 --- /dev/null +++ b/eo-parser/src/main/resources/org/eolang/parser/resolve-before-star.xsl @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/eo-parser/src/main/resources/org/eolang/parser/validate-before-stars.xsl b/eo-parser/src/main/resources/org/eolang/parser/validate-before-stars.xsl new file mode 100644 index 0000000000..2d23e9500b --- /dev/null +++ b/eo-parser/src/main/resources/org/eolang/parser/validate-before-stars.xsl @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + Index after '*' ( + + ) must be less than amount arguments ( + + ) + + + + + + + + + + + + + + + + + diff --git a/eo-parser/src/test/java/org/eolang/parser/TrParsingTest.java b/eo-parser/src/test/java/org/eolang/parser/TrParsingTest.java index fd7812007b..9be161e7b0 100644 --- a/eo-parser/src/test/java/org/eolang/parser/TrParsingTest.java +++ b/eo-parser/src/test/java/org/eolang/parser/TrParsingTest.java @@ -28,7 +28,6 @@ import com.jcabi.xml.XMLDocument; import com.yegor256.xsline.TrClasspath; import com.yegor256.xsline.Xsline; -import org.cactoos.io.InputOf; import org.eolang.jucs.ClasspathSource; import org.eolang.xax.XtSticky; import org.eolang.xax.XtStrict; @@ -92,7 +91,7 @@ void parsesPacks(final String yaml) { yaml, eo -> new EoSyntax( "scenario", - new InputOf(String.format("%s\n", eo)) + String.format("%s\n", eo) ).parsed(), new TrParsing().empty() ) diff --git a/eo-parser/src/test/resources/org/eolang/parser/eo-packs/full-syntax.yaml b/eo-parser/src/test/resources/org/eolang/parser/eo-packs/full-syntax.yaml index 7010d44be7..038de5df83 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/eo-packs/full-syntax.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/eo-packs/full-syntax.yaml @@ -57,6 +57,9 @@ input: | # This is very good object # No comments. [x] > first + sprintf *1 > xyz + "Hello, %s" + "Jeff" x > @ second > hello $.plus.@ 5 > i diff --git a/eo-parser/src/test/resources/org/eolang/parser/eo-packs/syntax/before-star.yaml b/eo-parser/src/test/resources/org/eolang/parser/eo-packs/syntax/before-star.yaml new file mode 100644 index 0000000000..7e81dfbd7b --- /dev/null +++ b/eo-parser/src/test/resources/org/eolang/parser/eo-packs/syntax/before-star.yaml @@ -0,0 +1,51 @@ +# 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: [ ] +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[count(//o[@before-star])=0] +input: | + # No comments. + [] > foo + sprintf *2 > with-error + x + sprintf * > first + x + y + sprintf *1 > second + x + y + z + sprintf *2 > third + x + y + z + sprintf *1 > fourth + sprintf * + x + y + z diff --git a/eo-runtime/src/main/eo/org/eolang/bytes.eo b/eo-runtime/src/main/eo/org/eolang/bytes.eo index f1d968b63c..4c58e3a5f6 100644 --- a/eo-runtime/src/main/eo/org/eolang/bytes.eo +++ b/eo-runtime/src/main/eo/org/eolang/bytes.eo @@ -55,7 +55,7 @@ error sprintf "Can't convert non 8 length bytes to a number, bytes are %x" - * + * ^ # Equals to another object. [b] > eq /org.eolang.bool diff --git a/eo-runtime/src/main/eo/org/eolang/fs/dir.eo b/eo-runtime/src/main/eo/org/eolang/fs/dir.eo index 7f82fed14a..a5bbf8274d 100644 --- a/eo-runtime/src/main/eo/org/eolang/fs/dir.eo +++ b/eo-runtime/src/main/eo/org/eolang/fs/dir.eo @@ -40,10 +40,9 @@ if. > @ ^.exists ^ - seq - * - mkdir - ^ + seq * + mkdir + ^ # Makes a directory together with all required # parent directories. @@ -64,10 +63,9 @@ walked.length > len! if. > @ ^.exists - seq - * - rec-delete walked 0 - ^ + seq * + rec-delete walked 0 + ^ ^ # Deletes files and directories in current directory recursively. @@ -79,12 +77,11 @@ if. > @ ^.len.eq index true - seq - * - tup.tail.deleted.exists - ^.rec-delete - tup.head - index.plus 1 + seq * + tup.tail.deleted.exists + ^.rec-delete + tup.head + index.plus 1 # Creates an empty temporary file in the current directory. [] > tmpfile diff --git a/eo-runtime/src/main/eo/org/eolang/fs/file.eo b/eo-runtime/src/main/eo/org/eolang/fs/file.eo index f3394be06d..67fbb1a430 100644 --- a/eo-runtime/src/main/eo/org/eolang/fs/file.eo +++ b/eo-runtime/src/main/eo/org/eolang/fs/file.eo @@ -45,10 +45,9 @@ if. > @ ^.exists ^ - seq - * - touch - ^ + seq * + touch + ^ # Creates new empty file. # @@ -61,10 +60,9 @@ [] > deleted if. > @ ^.exists - seq - * - delete - ^ + seq * + delete + ^ ^ # Deletes the file and returns `true`. @@ -156,23 +154,20 @@ sprintf "File must exist for given access mod: '%s'" * access - seq - * - ^.touched.touch - process-file - ^ + seq * + ^.touched.touch + process-file + ^ if. truncate - seq - * - ^.deleted.delete - ^.touched.touch - process-file - ^ - seq - * - process-file - ^ + seq * + ^.deleted.delete + ^.touched.touch + process-file + ^ + seq * + process-file + ^ # Process current file in the provided scope. # @@ -219,10 +214,9 @@ sprintf "Can't read from file with provided access mode '%s'" * ^.^.^.^.^.access - seq - * - read-bytes - ^.^.input-block read-bytes + seq * + read-bytes + ^.^.input-block read-bytes # Bytes read from file input stream # @@ -261,10 +255,9 @@ sprintf "Can't write to file with provided access mode '%s'" * ^.^.^.^.^.access - seq - * - ^.^.written-bytes buffer - ^.^.output-block + seq * + ^.^.written-bytes buffer + ^.^.output-block # Bytes written to file output stream. # diff --git a/eo-runtime/src/main/eo/org/eolang/io/console.eo b/eo-runtime/src/main/eo/org/eolang/io/console.eo index fc049e2796..60bdada6a9 100644 --- a/eo-runtime/src/main/eo/org/eolang/io/console.eo +++ b/eo-runtime/src/main/eo/org/eolang/io/console.eo @@ -116,10 +116,9 @@ "read" * posix.stdin-fileno size self. > @ - seq - * - read-bytes - ^.^.input-block read-bytes + seq * + read-bytes + ^.^.input-block read-bytes # Write given `buffer` to console. # Here `buffer` is either sequence of bytes or and object that can be @@ -140,13 +139,12 @@ # Returns new instance of `output-block` ready to write again. [buffer] > write self. > @ - seq - * - code. - posix - "write" - * posix.stdout-fileno buffer buffer.size - ^.^.output-block + seq * + code. + posix + "write" + * posix.stdout-fileno buffer buffer.size + ^.^.output-block # Windows console. # It uses kernel32.dll system function calls to read/write standard inputs/outputs. @@ -174,10 +172,9 @@ "ReadFile" * win32.std-input-handle size self. > @ - seq - * - read-bytes - ^.^.input-block read-bytes + seq * + read-bytes + ^.^.input-block read-bytes # Write given `buffer` to console. # Here `buffer` is either sequence of bytes or and object that can be @@ -198,10 +195,9 @@ # Returns new instance of `output-block` ready to write again. [buffer] > write self. > @ - seq - * - code. - win32 - "WriteFile" - * win32.std-output-handle buffer buffer.size - ^.^.output-block + seq * + code. + win32 + "WriteFile" + * win32.std-output-handle buffer buffer.size + ^.^.output-block diff --git a/eo-runtime/src/main/eo/org/eolang/io/malloc-as-output.eo b/eo-runtime/src/main/eo/org/eolang/io/malloc-as-output.eo index 0d227dbaff..4b39959d45 100644 --- a/eo-runtime/src/main/eo/org/eolang/io/malloc-as-output.eo +++ b/eo-runtime/src/main/eo/org/eolang/io/malloc-as-output.eo @@ -65,8 +65,7 @@ # Returns new instance of `output-block` ready to write again. [buffer] > write self. > @ - seq - * - ^.^.^.allocated.write offset buffer - ^.^.output-block - offset.plus buffer.size + seq * + ^.^.^.allocated.write offset buffer + ^.^.output-block + offset.plus buffer.size diff --git a/eo-runtime/src/main/eo/org/eolang/io/stdout.eo b/eo-runtime/src/main/eo/org/eolang/io/stdout.eo index b68c29011f..e7614ff6a4 100644 --- a/eo-runtime/src/main/eo/org/eolang/io/stdout.eo +++ b/eo-runtime/src/main/eo/org/eolang/io/stdout.eo @@ -36,7 +36,6 @@ # # Here the "Hello, world!" string is printed to operation system console. [text] > stdout - seq > @ - * - console.write text - true + seq * > @ + console.write text + true diff --git a/eo-runtime/src/main/eo/org/eolang/io/tee-input.eo b/eo-runtime/src/main/eo/org/eolang/io/tee-input.eo index b108588a05..fc527dd73c 100644 --- a/eo-runtime/src/main/eo/org/eolang/io/tee-input.eo +++ b/eo-runtime/src/main/eo/org/eolang/io/tee-input.eo @@ -66,10 +66,9 @@ (^.input.read size).read.^ > read-bytes (^.output.write read-bytes).write.^ > written-bytes self. > @ - seq - * + seq * + written-bytes + ^.^.input-block + read-bytes written-bytes - ^.^.input-block - read-bytes - written-bytes - read-bytes.as-bytes + read-bytes.as-bytes diff --git a/eo-runtime/src/main/eo/org/eolang/malloc.eo b/eo-runtime/src/main/eo/org/eolang/malloc.eo index 608307109a..89acb66b97 100644 --- a/eo-runtime/src/main/eo/org/eolang/malloc.eo +++ b/eo-runtime/src/main/eo/org/eolang/malloc.eo @@ -94,10 +94,9 @@ malloc.of > @ bts.size [m] >> - seq > @ - * - m.write 0 ^.bts - ^.scope m + seq * > @ + m.write 0 ^.bts + ^.scope m # Allocates block in memory of given `size`. After allocation the `size` zero bytes bytes are # written into memory. @@ -134,7 +133,6 @@ # Put `object` into the allocated block in memory. The `object` is supposed to be dataizable. [object] > put - seq > @ - * - ^.write 0 object - ^.get + seq * > @ + ^.write 0 object + ^.get diff --git a/eo-runtime/src/main/eo/org/eolang/math/integral.eo b/eo-runtime/src/main/eo/org/eolang/math/integral.eo index dfe32bc5e9..58d90bd9b6 100644 --- a/eo-runtime/src/main/eo/org/eolang/math/integral.eo +++ b/eo-runtime/src/main/eo/org/eolang/math/integral.eo @@ -53,22 +53,20 @@ [left] >> ^.^.b > right ((right.minus left).div ^.^.n).as-number > step - seq > @ - * - while - [i] >> - if. > @ - (^.left.as-number.plus ^.step).lt ^.right - seq - * - ^.^.sum.put - ^.^.sum.as-number.plus - ^.^.^.subsection - ^.left.as-number - ^.left.as-number.plus ^.step - ^.left.put + seq * > @ + while + [i] >> + if. > @ + (^.left.as-number.plus ^.step).lt ^.right + seq * + ^.^.sum.put + ^.^.sum.as-number.plus + ^.^.^.subsection + ^.left.as-number ^.left.as-number.plus ^.step - true - false - true > [i] - sum + ^.left.put + ^.left.as-number.plus ^.step + true + false + true > [i] + sum diff --git a/eo-runtime/src/main/eo/org/eolang/net/socket.eo b/eo-runtime/src/main/eo/org/eolang/net/socket.eo index dee0466390..bdfe1aef91 100644 --- a/eo-runtime/src/main/eo/org/eolang/net/socket.eo +++ b/eo-runtime/src/main/eo/org/eolang/net/socket.eo @@ -120,10 +120,9 @@ [size] > read (^.^.^.recv size).as-bytes > read-bytes self. > @ - seq - * - read-bytes - ^.^.input-block read-bytes + seq * + read-bytes + ^.^.input-block read-bytes # Makes an `output` from posix socket. # The object allows to use `socket` as output stream and `write` to it sequentially. @@ -151,10 +150,9 @@ # Returns new instance of `output-block` ready to write again. [buffer] > write self. > @ - seq - * - ^.^.^.send buffer - ^.^.output-block + seq * + ^.^.^.send buffer + ^.^.output-block # Posix platform specified socket. # diff --git a/eo-runtime/src/main/eo/org/eolang/structs/list.eo b/eo-runtime/src/main/eo/org/eolang/structs/list.eo index a3201a18a6..f0c34ddbc2 100644 --- a/eo-runtime/src/main/eo/org/eolang/structs/list.eo +++ b/eo-runtime/src/main/eo/org/eolang/structs/list.eo @@ -111,10 +111,9 @@ ^.reducedi > @ true [acc item index] >> - seq > @ - * - acc - ^.func item index + seq * > @ + acc + ^.func item index # For each collection element dataize the object # Here "func" must be an abstract object with diff --git a/eo-runtime/src/main/eo/org/eolang/while.eo b/eo-runtime/src/main/eo/org/eolang/while.eo index fd2d533c41..0843cbe66e 100644 --- a/eo-runtime/src/main/eo/org/eolang/while.eo +++ b/eo-runtime/src/main/eo/org/eolang/while.eo @@ -63,8 +63,7 @@ body index > current if. > @ (condition (index.plus 1)).as-bool - seq - * - current - ^.loop (index.plus 1) + seq * + current + ^.loop (index.plus 1) current diff --git a/eo-runtime/src/test/resources/org/eolang/snippets/simple.yaml b/eo-runtime/src/test/resources/org/eolang/snippets/simple.yaml index a4ce431bf6..417762654f 100644 --- a/eo-runtime/src/test/resources/org/eolang/snippets/simple.yaml +++ b/eo-runtime/src/test/resources/org/eolang/snippets/simple.yaml @@ -27,14 +27,11 @@ args: [ "org.eolang.snippets.simple" ] eo: | +package org.eolang.snippets +alias org.eolang.io.stdout + +alias org.eolang.txt.sprintf # No comments. [args] > simple - seq > @ - * - stdout - "Hello, " - stdout - "Jeff" - stdout - "!" + stdout > @ + sprintf *1 + "Hello, %s!" + "Jeff" From 12f0d087c277d562bf8d23494447309dadd7cecb Mon Sep 17 00:00:00 2001 From: maxonfjvipon Date: Thu, 26 Dec 2024 18:12:28 +0300 Subject: [PATCH 3/3] bug(#3619): merge master --- .../java/org/eolang/parser/XeEoListener.java | 46 +++++++++++-------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java b/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java index fcce5400e5..054df63882 100644 --- a/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java +++ b/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java @@ -526,9 +526,11 @@ public void enterCompactArray(final EoParser.CompactArrayContext ctx) { || num.length() > 1 && num.charAt(0) == '0' || Integer.parseInt(num) < 0 ) { - this.errors.put( - ctx, - "Index after '*' must be a positive integer without leading zero or arithmetic signs" + this.errors.add( + XeEoListener.error( + ctx, + "Index after '*' must be a positive integer without leading zero or arithmetic signs" + ) ); } final int number = Integer.parseInt(num); @@ -1084,21 +1086,7 @@ public void enterAs(final EoParser.AsContext ctx) { } else { final int index = Integer.parseInt(ctx.INT().getText()); if (index < 0) { - this.errors.add( - new ParsingException( - ctx.getStart().getLine(), - new MsgLocated( - ctx.getStart().getLine(), - ctx.getStart().getCharPositionInLine(), - "Object binding can't be negative" - ).formatted(), - new MsgUnderlined( - XeEoListener.line(ctx), - ctx.getStart().getCharPositionInLine(), - ctx.getText().length() - ).formatted() - ) - ); + this.errors.add(XeEoListener.error(ctx, "Object binding can't be negative")); } has = String.format("α%d", index); } @@ -1252,6 +1240,28 @@ private static String trimMargin(final String text, final int indent) { return res.toString(); } + /** + * Create parsing exception from given context. + * @param ctx Context + * @param msg Error message + * @return Parsing exception from current context + */ + private static ParsingException error(final ParserRuleContext ctx, final String msg) { + return new ParsingException( + ctx.getStart().getLine(), + new MsgLocated( + ctx.getStart().getLine(), + ctx.getStart().getCharPositionInLine(), + msg + ).formatted(), + new MsgUnderlined( + XeEoListener.line(ctx), + ctx.getStart().getCharPositionInLine(), + ctx.getText().length() + ).formatted() + ); + } + /** * Get line from context. * @param ctx Context