Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Dec 27, 2023
2 parents b24137f + 908a6cc commit bd89421
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 15 deletions.
40 changes: 25 additions & 15 deletions eo-maven-plugin/src/main/java/org/eolang/maven/PrintMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.cactoos.experimental.Threads;
import org.cactoos.iterable.Mapped;
import org.cactoos.number.SumOf;
import org.cactoos.text.TextOf;
import org.eolang.maven.util.HmBase;
import org.eolang.maven.util.Home;
Expand Down Expand Up @@ -72,23 +74,31 @@ public final class PrintMojo extends SafeMojo {

@Override
void exec() throws IOException {
final Collection<Path> sources = new Walk(this.printSourcesDir.toPath());
final Home home = new HmBase(this.printOutputDir);
for (final Path source : sources) {
final Path relative = Paths.get(
this.printSourcesDir.toPath().relativize(source).toString()
.replace(".xmir", ".eo")
);
home.save(new XMIR(new TextOf(source)).toEO(), relative);
Logger.info(
this,
"Printed: %s => %s", source, this.printOutputDir.toPath().resolve(relative)
);
}
if (sources.isEmpty()) {
final int total = new SumOf(
new Threads<>(
Runtime.getRuntime().availableProcessors(),
new Mapped<>(
source -> () -> {
final Path relative = Paths.get(
this.printSourcesDir.toPath().relativize(source).toString()
.replace(".xmir", ".eo")
);
home.save(new XMIR(new TextOf(source)).toEO(), relative);
Logger.info(
this,
"Printed: %s => %s", source, this.printOutputDir.toPath().resolve(relative)
);
return 1;
},
new Walk(this.printSourcesDir.toPath())
)
)
).intValue();
if (total == 0) {
Logger.info(this, "No XMIR sources found");
} else {
Logger.info(this, "Printed %d XMIR sources into EO", sources.size());
Logger.info(this, "Printed %d XMIR sources into EO", total);
}
}
}
38 changes: 38 additions & 0 deletions eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,24 @@
*/
package org.eolang.maven;

import com.jcabi.matchers.XhtmlMatchers;
import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.cactoos.io.InputOf;
import org.cactoos.list.ListOf;
import org.cactoos.text.TextOf;
import org.eolang.jucs.ClasspathSource;
import org.eolang.maven.util.HmBase;
import org.eolang.parser.EoSyntax;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -124,4 +129,37 @@ void convertsToXmirAndBack(final String pack, @TempDir final Path temp) throws E
)
);
}

@Disabled
@Test
void convertsValidXmirAndParsableEO(@TempDir final Path temp) throws IOException {
final Map<String, Path> map = new FakeMaven(temp)
.withProgram(
"[args] > app",
" QQ.io.stdout > @",
" \"Hello, world!\""
)
.with("printSourcesDir", temp.resolve("target/1-parse").toFile())
.with("printOutputDir", temp.resolve("target/generated-sources").toFile())
.execute(ParseMojo.class)
.execute(OptimizeMojo.class)
.execute(PhiMojo.class)
.execute(UnphiMojo.class)
.execute(PrintMojo.class)
.result();
MatcherAssert.assertThat(
"Result EO code should be parsable",
new EoSyntax(
"test",
new InputOf(
new TextOf(
temp.resolve(
map.get("target/generated-sources/foo/x/main.eo")
)
)
)
).parsed(),
XhtmlMatchers.hasXPath("//errors[count(error)=0]")
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# @todo #2729:60min Enable the test when it's possible. Current syntax is not supported now. In our
# EBNF such is understood as vertical application with 3 arguments. But all arguments in
# application must be either all bound or not. But it should not be like that with reversed
# application. Need to extend the grammar and make sure the test works.
# Test UnphiMojoTest#convertsValidXmirAndParsableEO also does not work because of this.
# Don't forget to remove the puzzle.
skip: true
xsls: []
tests:
- /program/errors[count(*)=0]
eo: |
if. > condition
TRUE
"TRUE":0
"FALSE":1

1 comment on commit bd89421

@0pdd
Copy link

@0pdd 0pdd commented on bd89421 Dec 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 2729-a3e8db24 discovered in eo-parser/src/test/resources/org/eolang/parser/packs/syntax/binded-reversed-application.yaml) and submitted as #2737. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.