-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
1,489 additions
and
535 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016-2023 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.maven; | ||
|
||
import com.jcabi.log.Logger; | ||
import java.io.File; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
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; | ||
import org.eolang.maven.util.Walk; | ||
import org.eolang.parser.PhiSyntax; | ||
|
||
/** | ||
* Read PHI files and parse them to the XMIR. | ||
* @since 0.34.0 | ||
*/ | ||
@Mojo( | ||
name = "phi-to-xmir", | ||
defaultPhase = LifecyclePhase.PROCESS_SOURCES, | ||
threadSafe = true | ||
) | ||
public final class UnphiMojo extends SafeMojo { | ||
/** | ||
* The directory where to take phi files for parsing from. | ||
* @checkstyle MemberNameCheck (10 lines) | ||
*/ | ||
@Parameter( | ||
property = "unphiInputDir", | ||
required = true, | ||
defaultValue = "${project.build.directory}/eo/phi" | ||
) | ||
private File unphiInputDir; | ||
|
||
/** | ||
* The directory where to save xmir files to. | ||
* @checkstyle MemberNameCheck (10 lines) | ||
*/ | ||
@Parameter( | ||
property = "unphiOutputDir", | ||
required = true, | ||
defaultValue = "${project.build.directory}/eo/1-parse" | ||
) | ||
private File unphiOutputDir; | ||
|
||
@Override | ||
public void exec() { | ||
final Home home = new HmBase(this.unphiOutputDir); | ||
final int count = new SumOf( | ||
new Threads<>( | ||
Runtime.getRuntime().availableProcessors(), | ||
new Mapped<>( | ||
phi -> () -> { | ||
final Path relative = Paths.get( | ||
this.unphiInputDir.toPath().relativize(phi).toString().replace( | ||
String.format(".%s", PhiMojo.EXT), | ||
String.format(".%s", TranspileMojo.EXT) | ||
) | ||
); | ||
home.save( | ||
new PhiSyntax( | ||
phi.getFileName().toString(), | ||
new TextOf(phi) | ||
).parsed().toString(), | ||
relative | ||
); | ||
Logger.info( | ||
this, | ||
"Parsed to xmir: %s -> %s", | ||
phi, this.unphiOutputDir.toPath().resolve(relative) | ||
); | ||
return 1; | ||
}, | ||
new Walk(this.unphiInputDir.toPath()) | ||
) | ||
) | ||
).intValue(); | ||
Logger.info(this, "Parsed %d phi files to xmir", count); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016-2023 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.maven; | ||
|
||
import com.jcabi.xml.XML; | ||
import com.jcabi.xml.XMLDocument; | ||
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.list.ListOf; | ||
import org.cactoos.text.TextOf; | ||
import org.eolang.jucs.ClasspathSource; | ||
import org.eolang.maven.util.HmBase; | ||
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; | ||
import org.yaml.snakeyaml.Yaml; | ||
|
||
/** | ||
* Test cases for {@link UnphiMojo}. | ||
* @since 0.34.0 | ||
* @todo #2642:30min Create test packs for {@link UnphiMojo}. UnphiMojo seems to work correctly. | ||
* We need to create yaml packs and enable {@link UnphiMojoTest#checksUnphiPacks(String, Path)} | ||
* and make sure all of them are passed. Don't forget to remove the puzzle. | ||
*/ | ||
class UnphiMojoTest { | ||
@Test | ||
void createsFile(@TempDir final Path temp) throws Exception { | ||
new HmBase(temp).save( | ||
"{std ↦ Φ.org.eolang.io.stdout, y ↦ Φ.org.eolang.x}", | ||
Paths.get("target/phi/std.phi") | ||
); | ||
MatcherAssert.assertThat( | ||
String.format( | ||
"There should be file with .%s extension after parsing phi to XMIR, but there isn't", | ||
TranspileMojo.EXT | ||
), | ||
new FakeMaven(temp) | ||
.execute(UnphiMojo.class) | ||
.result(), | ||
Matchers.hasKey(String.format("target/%s/std.xmir", ParseMojo.DIR)) | ||
); | ||
} | ||
|
||
@ParameterizedTest | ||
@Disabled | ||
@ClasspathSource(value = "org/eolang/maven/unphi", glob = "**.yaml") | ||
void checksUnphiPacks(final String pack, @TempDir final Path temp) throws Exception { | ||
final Map<String, Object> map = new Yaml().load(pack); | ||
final String phi = map.get("phi").toString(); | ||
new HmBase(temp).save(phi, Paths.get("target/phi/main.phi")); | ||
final List<String> failures = new ListOf<>(); | ||
new FakeMaven(temp).execute(UnphiMojo.class); | ||
for (final String xpath : (Iterable<String>) map.get("tests")) { | ||
final List<XML> nodes = new XMLDocument( | ||
new TextOf( | ||
Paths.get(String.format("target/%s/main.xmir", ParseMojo.DIR)) | ||
).asString() | ||
).nodes(xpath); | ||
if (nodes.isEmpty()) { | ||
failures.add(xpath); | ||
} | ||
} | ||
MatcherAssert.assertThat( | ||
String.format( | ||
"Failed to parse phi expression: %s; failed tests: %s", | ||
phi, Arrays.toString(failures.toArray()) | ||
), | ||
failures, | ||
Matchers.empty() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../main/antlr4/org/eolang/parser/Program.g4 → ...r/src/main/antlr4/org/eolang/parser/Eo.g4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
grammar Program; | ||
grammar Eo; | ||
|
||
tokens { TAB, UNTAB } | ||
|
||
|
Oops, something went wrong.
eafd274
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
2642-02dbe2cd
discovered ineo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java
) and submitted as #2682. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.