diff --git a/.github/workflows/telegram.yml b/.github/workflows/telegram.yml index 09d736c727..088e17bafa 100644 --- a/.github/workflows/telegram.yml +++ b/.github/workflows/telegram.yml @@ -36,7 +36,7 @@ jobs: - uses: djdefi/cloc-action@7 with: options: --json --report-file=cloc.json - - run: sudo apt-get update && sudo apt-get install --yes jq + - run: sudo apt-get update && sudo apt-get install --yes jq bc - uses: ruby/setup-ruby@v1 with: ruby-version: 3.2 @@ -44,22 +44,25 @@ jobs: - run: | git fetch --tag ( - printf 'Good news, we have just published the %dth release ' \ + printf 'Good news, we have just published the %d-th release ' \ "$(git tag | wc -l | xargs)" printf 'of [EO-to-Java compiler](https://github.com/objectionary/eo): ' printf '[%s](https://github.com/objectionary/eo/releases/tag/%s). ' \ "${{github.ref_name}}" "${{github.ref_name}}" - printf 'At the moment, there are %d lines-of code ' \ - "$(jq '.SUM.code' message.md - uses: appleboy/telegram-action@master with: diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParse.java b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParse.java index 964a3bfba5..225f119ec3 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParse.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParse.java @@ -45,7 +45,7 @@ import org.eolang.maven.rust.Names; import org.eolang.maven.rust.RustNode; import org.eolang.maven.tojos.ForeignTojo; -import org.eolang.parser.ParsingTrain; +import org.eolang.parser.TrParsing; /** * Parse rust inserts. @@ -67,7 +67,7 @@ public final class BinarizeParse { * appropriate XSL transformation. */ private static final Train TRAIN = new TrBulk<>( - new TrClasspath<>(new ParsingTrain().empty()), + new TrClasspath<>(new TrParsing().empty()), Arrays.asList("/org/eolang/maven/add_rust/add_rust.xsl") ).back().back(); diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/OptimizeMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/OptimizeMojo.java index 0abc105626..8a041b0eb2 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/OptimizeMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/OptimizeMojo.java @@ -43,7 +43,7 @@ import org.eolang.maven.optimization.Optimization; import org.eolang.maven.tojos.ForeignTojo; import org.eolang.maven.tojos.TojoHash; -import org.eolang.parser.ParsingTrain; +import org.eolang.parser.TrParsing; /** * Optimize XML files. @@ -143,7 +143,7 @@ private int optimized(final ForeignTojo tojo, final Optimization optimization) */ private Optimization optimization() { final Optimization opt; - final Train train = this.measured(new ParsingTrain()); + final Train train = this.measured(new TrParsing()); if (this.trackOptimizationSteps) { opt = new OptSpy( train, diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/PhiMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/PhiMojo.java index c58bf7bb5c..c25c8c7cf1 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/PhiMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/PhiMojo.java @@ -28,7 +28,6 @@ import com.jcabi.xml.XMLDocument; import com.yegor256.xsline.Shift; 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; @@ -48,8 +47,8 @@ import org.cactoos.text.TextOf; import org.eolang.maven.footprint.Saved; import org.eolang.maven.util.Walk; -import org.eolang.parser.ParsingTrain; import org.eolang.parser.Schema; +import org.eolang.parser.TrParsing; /** * Read XMIR files and translate them to the phi-calculus expression. @@ -219,9 +218,9 @@ private int translate(final Path xmir, final Xsline xsline, final int position, private Train train() { final Train train; if (this.phiOptimize) { - train = new ParsingTrain(); + train = new TrParsing(); } else { - train = new TrDefault<>(); + train = new com.yegor256.xsline.TrDefault<>(); } final List dependent = new ListOf<>( "/org/eolang/parser/critical-errors/duplicate-names.xsl", diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java index bcc1b6bb4a..5fd89291eb 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java @@ -49,6 +49,7 @@ import org.eolang.maven.util.Home; import org.eolang.maven.util.Walk; import org.eolang.parser.PhiSyntax; +import org.eolang.parser.TrStepped; import org.xembly.Directive; import org.xembly.Directives; @@ -65,11 +66,13 @@ public final class UnphiMojo extends SafeMojo { /** * Unphi transformations. */ - private static final Train TRANSFORMATIONS = new TrClasspath<>( - "/org/eolang/maven/unphi/wrap-bytes.xsl", - "/org/eolang/parser/wrap-method-calls.xsl", - "/org/eolang/maven/unphi/atoms-with-bound-attrs.xsl" - ).back(); + private static final Train TRANSFORMATIONS = new TrStepped( + new TrClasspath<>( + "/org/eolang/maven/unphi/wrap-bytes.xsl", + "/org/eolang/parser/wrap-method-calls.xsl", + "/org/eolang/maven/unphi/atoms-with-bound-attrs.xsl" + ).back() + ); /** * The directory where to take phi files for parsing from. diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/OptimizeMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/OptimizeMojoTest.java index d8e699bcaa..97a5ddbfc9 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/OptimizeMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/OptimizeMojoTest.java @@ -80,7 +80,6 @@ void optimizesSimpleObject(@Mktmp final Path temp) throws Exception { f.files().file("target/eo/2-optimize/foo.xmir").exists(), Matchers.is(true) ); - f.files().show(); } ); } diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/PhiMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/PhiMojoTest.java index 87c9e5c3e5..c309be4dd4 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/PhiMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/PhiMojoTest.java @@ -74,11 +74,40 @@ void convertsSimpleObjectToPhi(@Mktmp final Path temp, f.files().file("target/eo/phi/foo.phi").exists(), Matchers.is(true) ); - f.files().show(); } ); } + @Test + void convertsObjectWithSystemType(@Mktmp final Path temp) throws Exception { + new Farea(temp).together( + f -> { + f.clean(); + f.files().file("src/main/eo/org/eolang/bytes.eo").write( + String.join( + "\n", + "+package org.eolang", + "", + "# In this program, we define a 'system' object, similar", + "# to how it is defined in org.eolang package, trying to", + "# reproduce the error.", + "[] > bytes", + " $.eq 01- > yes", + "" + ).getBytes() + ); + f.build().plugins().appendItself(); + f.exec("eo:register", "eo:parse", "eo:optimize"); + f.exec("eo:xmir-to-phi"); + } + ); + MatcherAssert.assertThat( + "the .phi file is generated", + temp.resolve("target/eo/phi/org/eolang/bytes.phi").toFile().exists(), + Matchers.is(true) + ); + } + @Test void createsFiles(@Mktmp final Path temp) throws Exception { MatcherAssert.assertThat( diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/PrintMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/PrintMojoTest.java index 53bed7f0cd..a252865d23 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/PrintMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/PrintMojoTest.java @@ -76,7 +76,6 @@ void printsSimpleObject(@Mktmp final Path temp) throws Exception { f.files().file("target/generated-sources/eo/foo.eo").exists(), Matchers.is(true) ); - f.files().show(); } ); } diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/SodgMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/SodgMojoTest.java index 5b8912bf46..190730e8ce 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/SodgMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/SodgMojoTest.java @@ -78,13 +78,11 @@ void convertsSimpleObjectToGraph(@Mktmp final Path temp) throws Exception { .execution() .goals("register", "parse", "optimize", "shake", "sodg"); f.exec("compile"); - f.files().show(); MatcherAssert.assertThat( "the .sodg file is generated", f.files().file("target/eo/sodg/foo.sodg").exists(), Matchers.is(true) ); - f.files().show(); } ); } diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java index b701c6a2bf..c9ec12ef61 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java @@ -165,16 +165,15 @@ void checksUnphiPacks(final String pack, @Mktmp final Path temp) throws Exceptio void convertsToXmirAndBack(final String pack, @Mktmp final Path temp) throws Exception { final Map map = new Yaml().load(pack); if (map.get("skip") != null) { - Assumptions.abort( - String.format("%s is not ready", pack) - ); + Assumptions.abort(String.format("%s is not ready", pack)); } final String phi = map.get("phi").toString(); final String main = "target/phi/main.phi"; final Path path = Paths.get(main); new HmBase(temp).save(phi, path); final long saved = temp.resolve(path).toFile().lastModified(); - final FakeMaven maven = new FakeMaven(temp).execute(UnphiMojo.class); + final FakeMaven maven = new FakeMaven(temp) + .execute(UnphiMojo.class); maven.foreignTojos().add("name") .withXmir(temp.resolve(String.format("target/%s/main.xmir", ParseMojo.DIR))); final Path result = maven @@ -189,10 +188,8 @@ void convertsToXmirAndBack(final String pack, @Mktmp final Path temp) throws Exc ); MatcherAssert.assertThat( "Origin phi should equal to phi got from \"unphied\" xmir, but it isn't", - phi, - Matchers.equalTo( - new TextOf(result).asString() - ) + new TextOf(result).asString(), + Matchers.equalTo(phi) ); } diff --git a/eo-parser/src/main/java/org/eolang/parser/CheckPack.java b/eo-parser/src/main/java/org/eolang/parser/CheckPack.java index 95a19848a6..2640411e73 100644 --- a/eo-parser/src/main/java/org/eolang/parser/CheckPack.java +++ b/eo-parser/src/main/java/org/eolang/parser/CheckPack.java @@ -69,7 +69,7 @@ public Collection failures() throws IOException { final Map map = yaml.load(this.script); final String src = map.get("eo").toString(); final Iterable xsls = (Iterable) map.get("xsls"); - Train train = new ParsingTrain(); + Train train = new TrParsing(); if (xsls != null) { if (!map.containsKey("defaults")) { train = train.empty(); diff --git a/eo-parser/src/main/java/org/eolang/parser/ParsingTrain.java b/eo-parser/src/main/java/org/eolang/parser/ParsingTrain.java deleted file mode 100644 index d1002324bb..0000000000 --- a/eo-parser/src/main/java/org/eolang/parser/ParsingTrain.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * 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. - */ -package org.eolang.parser; - -import com.jcabi.xml.ClasspathSources; -import com.jcabi.xml.XSL; -import com.jcabi.xml.XSLDocument; -import com.yegor256.xsline.StAfter; -import com.yegor256.xsline.StEndless; -import com.yegor256.xsline.StLambda; -import com.yegor256.xsline.StSequence; -import com.yegor256.xsline.TrClasspath; -import com.yegor256.xsline.TrDefault; -import com.yegor256.xsline.TrEnvelope; -import com.yegor256.xsline.TrFast; -import com.yegor256.xsline.TrJoined; -import com.yegor256.xsline.TrLambda; -import com.yegor256.xsline.TrLogged; -import java.util.logging.Level; - -/** - * Train of XSL shifts. - * - * @since 0.1 - */ -public final class ParsingTrain extends TrEnvelope { - - /** - * Apply changes to each XML after processing. - */ - private static final XSL EACH = new XSLDocument( - ParsingTrain.class.getResourceAsStream("_each.xsl"), - "each.xsl" - ).with(new ClasspathSources(ParsingTrain.class)); - - /** - * Transform stars to tuples. - */ - private static final XSL TUPLES = new XSLDocument( - ParsingTrain.class.getResourceAsStream("stars-to-tuples.xsl"), - "stars-to-tuples.xsl" - ).with(new ClasspathSources(ParsingTrain.class)); - - /** - * Sheets in the right order. - */ - private static final String[] SHEETS = { - "/org/eolang/parser/errors/not-empty-atoms.xsl", - "/org/eolang/parser/critical-errors/duplicate-names.xsl", - "/org/eolang/parser/errors/broken-aliases.xsl", - "/org/eolang/parser/errors/duplicate-aliases.xsl", - "/org/eolang/parser/errors/global-nonames.xsl", - "/org/eolang/parser/errors/same-line-names.xsl", - "/org/eolang/parser/errors/self-naming.xsl", - "/org/eolang/parser/cti/cti-adds-errors.xsl", - "/org/eolang/parser/add-refs.xsl", - "/org/eolang/parser/wrap-method-calls.xsl", - "/org/eolang/parser/expand-qqs.xsl", - "/org/eolang/parser/add-probes.xsl", - "/org/eolang/parser/vars-float-up.xsl", - "/org/eolang/parser/add-refs.xsl", - "/org/eolang/parser/warnings/sparse-decoration.xsl", - "/org/eolang/parser/warnings/unsorted-metas.xsl", - "/org/eolang/parser/warnings/incorrect-architect.xsl", - "/org/eolang/parser/warnings/incorrect-home.xsl", - "/org/eolang/parser/warnings/incorrect-version.xsl", - "/org/eolang/parser/expand-aliases.xsl", - "/org/eolang/parser/resolve-aliases.xsl", - "/org/eolang/parser/add-refs.xsl", - "/org/eolang/parser/add-default-package.xsl", - "/org/eolang/parser/errors/broken-refs.xsl", - "/org/eolang/parser/errors/unknown-names.xsl", - "/org/eolang/parser/errors/noname-attributes.xsl", - "/org/eolang/parser/critical-errors/duplicate-names.xsl", - "/org/eolang/parser/warnings/duplicate-metas.xsl", - "/org/eolang/parser/warnings/mandatory-package-meta.xsl", - "/org/eolang/parser/warnings/mandatory-home-meta.xsl", - "/org/eolang/parser/warnings/mandatory-version-meta.xsl", - "/org/eolang/parser/warnings/correct-package-meta.xsl", - "/org/eolang/parser/warnings/prohibited-package.xsl", - "/org/eolang/parser/errors/external-weak-typed-atoms.xsl", - "/org/eolang/parser/errors/unused-aliases.xsl", - "/org/eolang/parser/warnings/unit-test-without-phi.xsl", - "/org/eolang/parser/explicit-data.xsl", - "/org/eolang/parser/const-to-dataized.xsl", - "/org/eolang/parser/set-locators.xsl", - }; - - /** - * Ctor. - */ - @SuppressWarnings("unchecked") - public ParsingTrain() { - this(ParsingTrain.SHEETS); - } - - /** - * Ctor. - * @param sheets Sheets - */ - ParsingTrain(final String... sheets) { - super( - new TrLambda( - new TrFast( - new TrLambda( - new TrLogged( - new TrJoined<>( - new TrDefault<>( - new StEndless( - new StLambda( - "stars-to-tuples", - ParsingTrain.TUPLES::transform - ) - ) - ), - new TrClasspath<>(sheets).back() - ), - ParsingTrain.class, - Level.FINEST - ), - StEoLogged::new - ), - TrFast.class, - 500L - ), - shift -> new StSequence( - shift.uid(), - xml -> xml.nodes("//error[@severity='critical']").isEmpty(), - new StAfter( - shift, - new StLambda( - shift::uid, - (pos, xml) -> ParsingTrain.EACH.with("step", pos) - .with("sheet", shift.uid()) - .transform(xml) - ) - ) - ) - ) - ); - } -} diff --git a/eo-parser/src/main/java/org/eolang/parser/TrParsing.java b/eo-parser/src/main/java/org/eolang/parser/TrParsing.java new file mode 100644 index 0000000000..cc27b07912 --- /dev/null +++ b/eo-parser/src/main/java/org/eolang/parser/TrParsing.java @@ -0,0 +1,126 @@ +/* + * 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. + */ +package org.eolang.parser; + +import com.jcabi.xml.ClasspathSources; +import com.jcabi.xml.XSL; +import com.jcabi.xml.XSLDocument; +import com.yegor256.xsline.StEndless; +import com.yegor256.xsline.StLambda; +import com.yegor256.xsline.TrClasspath; +import com.yegor256.xsline.TrDefault; +import com.yegor256.xsline.TrEnvelope; +import com.yegor256.xsline.TrFast; +import com.yegor256.xsline.TrJoined; +import com.yegor256.xsline.TrLambda; +import com.yegor256.xsline.TrLogged; +import java.util.logging.Level; + +/** + * Train of XSL shifts. + * + * @since 0.1 + */ +public final class TrParsing extends TrEnvelope { + + /** + * Transform stars to tuples. + */ + private static final XSL TUPLES = new XSLDocument( + TrParsing.class.getResourceAsStream("stars-to-tuples.xsl"), + "stars-to-tuples.xsl" + ).with(new ClasspathSources(TrParsing.class)); + + /** + * Ctor. + */ + public TrParsing() { + super( + new TrStepped( + new TrFast( + new TrLambda( + new TrLogged( + new TrJoined<>( + new TrDefault<>( + new StEndless( + new StLambda( + "stars-to-tuples", + TrParsing.TUPLES::transform + ) + ) + ), + new TrClasspath<>( + "/org/eolang/parser/errors/not-empty-atoms.xsl", + "/org/eolang/parser/critical-errors/duplicate-names.xsl", + "/org/eolang/parser/errors/broken-aliases.xsl", + "/org/eolang/parser/errors/duplicate-aliases.xsl", + "/org/eolang/parser/errors/global-nonames.xsl", + "/org/eolang/parser/errors/same-line-names.xsl", + "/org/eolang/parser/errors/self-naming.xsl", + "/org/eolang/parser/cti/cti-adds-errors.xsl", + "/org/eolang/parser/add-refs.xsl", + "/org/eolang/parser/wrap-method-calls.xsl", + "/org/eolang/parser/expand-qqs.xsl", + "/org/eolang/parser/add-probes.xsl", + "/org/eolang/parser/vars-float-up.xsl", + "/org/eolang/parser/add-refs.xsl", + "/org/eolang/parser/warnings/sparse-decoration.xsl", + "/org/eolang/parser/warnings/unsorted-metas.xsl", + "/org/eolang/parser/warnings/incorrect-architect.xsl", + "/org/eolang/parser/warnings/incorrect-home.xsl", + "/org/eolang/parser/warnings/incorrect-version.xsl", + "/org/eolang/parser/expand-aliases.xsl", + "/org/eolang/parser/resolve-aliases.xsl", + "/org/eolang/parser/add-refs.xsl", + "/org/eolang/parser/add-default-package.xsl", + "/org/eolang/parser/errors/broken-refs.xsl", + "/org/eolang/parser/errors/unknown-names.xsl", + "/org/eolang/parser/errors/noname-attributes.xsl", + "/org/eolang/parser/critical-errors/duplicate-names.xsl", + "/org/eolang/parser/warnings/duplicate-metas.xsl", + "/org/eolang/parser/warnings/mandatory-package-meta.xsl", + "/org/eolang/parser/warnings/mandatory-home-meta.xsl", + "/org/eolang/parser/warnings/mandatory-version-meta.xsl", + "/org/eolang/parser/warnings/correct-package-meta.xsl", + "/org/eolang/parser/warnings/prohibited-package.xsl", + "/org/eolang/parser/errors/external-weak-typed-atoms.xsl", + "/org/eolang/parser/errors/unused-aliases.xsl", + "/org/eolang/parser/warnings/unit-test-without-phi.xsl", + "/org/eolang/parser/explicit-data.xsl", + "/org/eolang/parser/const-to-dataized.xsl", + "/org/eolang/parser/set-locators.xsl" + ).back() + ), + TrParsing.class, + Level.FINEST + ), + StEoLogged::new + ), + TrFast.class, + 500L + ) + ) + ); + } +} diff --git a/eo-parser/src/main/java/org/eolang/parser/TrStepped.java b/eo-parser/src/main/java/org/eolang/parser/TrStepped.java new file mode 100644 index 0000000000..18d2823181 --- /dev/null +++ b/eo-parser/src/main/java/org/eolang/parser/TrStepped.java @@ -0,0 +1,76 @@ +/* + * 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. + */ +package org.eolang.parser; + +import com.jcabi.xml.ClasspathSources; +import com.jcabi.xml.XSL; +import com.jcabi.xml.XSLDocument; +import com.yegor256.xsline.Shift; +import com.yegor256.xsline.StAfter; +import com.yegor256.xsline.StLambda; +import com.yegor256.xsline.StSequence; +import com.yegor256.xsline.TrEnvelope; +import com.yegor256.xsline.TrLambda; +import com.yegor256.xsline.Train; + +/** + * Trains that adds sheet names that were processed. + * + * @since 0.1 + */ +public final class TrStepped extends TrEnvelope { + + /** + * Apply changes to each XML after processing. + */ + private static final XSL EACH = new XSLDocument( + TrStepped.class.getResourceAsStream("_each.xsl"), + "each.xsl" + ).with(new ClasspathSources(TrStepped.class)); + + /** + * Ctor. + * @param train Original train + */ + public TrStepped(final Train train) { + super( + new TrLambda( + train, + shift -> new StSequence( + shift.uid(), + xml -> xml.nodes("//error[@severity='critical']").isEmpty(), + new StAfter( + shift, + new StLambda( + shift::uid, + (pos, xml) -> TrStepped.EACH.with("step", pos) + .with("sheet", shift.uid()) + .transform(xml) + ) + ) + ) + ) + ); + } +} diff --git a/eo-parser/src/main/resources/org/eolang/parser/add-refs.xsl b/eo-parser/src/main/resources/org/eolang/parser/add-refs.xsl index ae2a15f8c6..9fb88555aa 100644 --- a/eo-parser/src/main/resources/org/eolang/parser/add-refs.xsl +++ b/eo-parser/src/main/resources/org/eolang/parser/add-refs.xsl @@ -30,12 +30,21 @@ SOFTWARE. which are not getting @ref attributes after this transformation are not visible in the current scope. Maybe they are global or just a mistake. + + We must not add "ref" attributes to objects that refer to + "bytes" if such objects are inside the "org.eolang.bytes". Such + a reference would be misleading: instead of referring to the + global "org.eolang.bytes" they will lead to local "bytes" + defined in this particular file. --> - + + + + - + diff --git a/eo-parser/src/test/java/org/eolang/parser/ParsingTrainTest.java b/eo-parser/src/test/java/org/eolang/parser/TrParsingTest.java similarity index 93% rename from eo-parser/src/test/java/org/eolang/parser/ParsingTrainTest.java rename to eo-parser/src/test/java/org/eolang/parser/TrParsingTest.java index 2f83771121..ab8dfda08f 100644 --- a/eo-parser/src/test/java/org/eolang/parser/ParsingTrainTest.java +++ b/eo-parser/src/test/java/org/eolang/parser/TrParsingTest.java @@ -26,6 +26,7 @@ import com.jcabi.matchers.XhtmlMatchers; import com.jcabi.xml.XML; import com.jcabi.xml.XMLDocument; +import com.yegor256.xsline.TrClasspath; import com.yegor256.xsline.Xsline; import org.eolang.jucs.ClasspathSource; import org.eolang.xax.XaxStory; @@ -37,17 +38,17 @@ import org.junit.jupiter.params.provider.CsvSource; /** - * Test case for {@link ParsingTrain}. + * Test case for {@link TrParsing}. * * @since 0.23 */ -final class ParsingTrainTest { +final class TrParsingTest { @Test void buildsList() { MatcherAssert.assertThat( "ParsingTrain is not iterable with more than 1 item, but it must be", - new ParsingTrain(), + new TrParsing(), Matchers.iterableWithSize(Matchers.greaterThan(1)) ); } @@ -72,7 +73,7 @@ void stopsPipeline() { MatcherAssert.assertThat( "XSL transformation don't work properly.", new Xsline( - new ParsingTrain() + new TrParsing() ).pass(xml), XhtmlMatchers.hasXPaths( "/program/sheets[count(sheet)=3]", @@ -101,7 +102,7 @@ void runsXslFunction(final String bytes, final String num) { MatcherAssert.assertThat( "Failed to convert byte to int using the apply-func.xsl transformation", new Xsline( - new ParsingTrain("/org/eolang/parser/apply-func.xsl") + new TrClasspath<>("/org/eolang/parser/apply-func.xsl").back() ).pass(new XMLDocument(String.format("%s", bytes))), XhtmlMatchers.hasXPath( String.format("/o[text()='%s']", num) @@ -120,7 +121,7 @@ void parsesPacks(final String pack) throws Exception { } MatcherAssert.assertThat( String.format( - "The %s check pack is failed.", + "The check pack has failed: %n%s", pack ), check.failures(), diff --git a/eo-parser/src/test/resources/log4j.properties b/eo-parser/src/test/resources/log4j.properties index 6152923b42..263eb6d9a7 100644 --- a/eo-parser/src/test/resources/log4j.properties +++ b/eo-parser/src/test/resources/log4j.properties @@ -29,3 +29,4 @@ log4j.appender.CONSOLE.layout.ConversionPattern=%d{HH:mm:ss} [%color{%p}] %c: %m log4j.logger.com.jcabi.log=WARN log4j.logger.org.eolang=WARN log4j.logger.org.eolang.parser.xmir.XmirTest=WARN +log4j.logger.org.eolang.parser.CheckPack=INFO diff --git a/eo-parser/src/test/resources/org/eolang/parser/packs/no-ref-to-bytes.yaml b/eo-parser/src/test/resources/org/eolang/parser/packs/no-ref-to-bytes.yaml new file mode 100644 index 0000000000..a4353b9f83 --- /dev/null +++ b/eo-parser/src/test/resources/org/eolang/parser/packs/no-ref-to-bytes.yaml @@ -0,0 +1,33 @@ +# 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. +--- +xsls: + - /org/eolang/parser/add-refs.xsl +tests: + - /program/errors[count(*)=0] + - /program/objects[count(.//o[@ref])=0] +eo: | + +package org.eolang + + # This is the default 64+ symbols comment in front of abstract object. + [] > bytes + $.eq 01- > yes