-
Notifications
You must be signed in to change notification settings - Fork 4
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
11 changed files
with
470 additions
and
120 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2022 Objectionary | ||
* | ||
* 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.speco; | ||
|
||
import com.jcabi.xml.XML; | ||
import com.yegor256.xsline.Shift; | ||
import com.yegor256.xsline.StClasspath; | ||
import com.yegor256.xsline.TrDefault; | ||
import com.yegor256.xsline.Xsline; | ||
import java.io.IOException; | ||
|
||
/** | ||
* The class encapsulating specialization logic with the clearing of the resulting xmir. | ||
* | ||
* @since 0.0.3 | ||
*/ | ||
final class ClearXmirSpeco implements Speco { | ||
|
||
/** | ||
* Encapsulated speco. | ||
*/ | ||
private final Speco origin; | ||
|
||
/** | ||
* Ctor. | ||
* | ||
* @param origin Encapsulated speco. | ||
*/ | ||
ClearXmirSpeco(final Speco origin) { | ||
this.origin = origin; | ||
} | ||
|
||
@Override | ||
public XML transform(final XML xml) throws IOException { | ||
return new Xsline( | ||
new TrDefault<>(new StClasspath("/org/eolang/speco/clear.xsl")) | ||
).pass( | ||
new Xsline( | ||
new TrDefault<Shift>().with( | ||
new StClasspath("/org/eolang/parser/wrap-method-calls.xsl") | ||
) | ||
).pass(this.origin.transform(xml)) | ||
); | ||
} | ||
} |
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,72 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2022 Objectionary | ||
* | ||
* 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.speco; | ||
|
||
import com.jcabi.xml.XML; | ||
import com.jcabi.xml.XMLDocument; | ||
import com.yegor256.xsline.Shift; | ||
import com.yegor256.xsline.StClasspath; | ||
import com.yegor256.xsline.StEndless; | ||
import com.yegor256.xsline.TrDefault; | ||
import com.yegor256.xsline.Train; | ||
import com.yegor256.xsline.Xsline; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import org.apache.commons.io.FileUtils; | ||
import org.cactoos.io.InputOf; | ||
import org.cactoos.io.OutputTo; | ||
import org.eolang.parser.Syntax; | ||
import org.eolang.parser.XMIR; | ||
import org.objectionary.aoi.launch.LauncherKt; | ||
|
||
/** | ||
* The class encapsulating specialization logic for xmir programs. | ||
* | ||
* @since 0.0.3 | ||
*/ | ||
final class DefaultSpeco implements Speco { | ||
|
||
@Override | ||
public XML transform(final XML xml) throws IOException { | ||
return new Xsline(new TrDefault<Shift>() | ||
.with(new StClasspath("/org/eolang/speco/1-1-coping.xsl")) | ||
.with(new StEndless(new StClasspath("/org/eolang/speco/1-2-specialization.xsl"))) | ||
.with(new StClasspath("/org/eolang/speco/1-3-extension.xsl")) | ||
.with(new StClasspath("/org/eolang/speco/2-1-substitute-applications.xsl")) | ||
.with(new StClasspath("/org/eolang/speco/3-1-add-with.xsl")) | ||
.with(new StClasspath("/org/eolang/speco/4-1-fence-tuples.xsl")) | ||
.with(new StClasspath("/org/eolang/speco/5-1-substitute-fence.xsl")) | ||
.with(new StClasspath("/org/eolang/speco/6-1-substitute-dominant.xsl")) | ||
.with(new StClasspath("/org/eolang/speco/7-1-substitute-returned.xsl")) | ||
).pass( | ||
new Xsline( | ||
new TrDefault<Shift>().with( | ||
new StClasspath("/org/eolang/parser/wrap-method-calls.xsl") | ||
) | ||
).pass(xml) | ||
); | ||
} | ||
} |
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,107 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2022 Objectionary | ||
* | ||
* 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.speco; | ||
|
||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import org.apache.commons.io.FileUtils; | ||
import org.cactoos.io.InputOf; | ||
import org.cactoos.io.OutputTo; | ||
import org.eolang.parser.Syntax; | ||
import org.eolang.parser.XMIR; | ||
import org.objectionary.aoi.launch.LauncherKt; | ||
|
||
/** | ||
* The class encapsulating applying of specialization to EO. | ||
* | ||
* @since 0.0.3 | ||
*/ | ||
public final class EoWalk implements Walk { | ||
/** | ||
* Absolute path to the directory with input files. | ||
*/ | ||
private final Path input; | ||
|
||
/** | ||
* Absolute path to the directory with output files. | ||
*/ | ||
private final Path output; | ||
|
||
/** | ||
* Origin speco. | ||
*/ | ||
private final Speco speco; | ||
|
||
/** | ||
* Ctor. | ||
* | ||
* @param input Absolute path to the directory with input files | ||
* @param output Absolute path to the directory with output files | ||
* @param speco Origin speco | ||
*/ | ||
public EoWalk( | ||
final Path input, | ||
final Path output, | ||
final Speco speco | ||
) { | ||
this.input = input; | ||
this.output = output; | ||
this.speco = speco; | ||
} | ||
|
||
@Override | ||
public void exec() throws IOException { | ||
Files.createDirectories(this.output); | ||
for (final Path path : Files.newDirectoryStream(EoWalk.parse(this.input))) { | ||
Files.write( | ||
this.output.resolve(path.getFileName()), | ||
new XMIR(this.speco.transform(Walk.toXml(path))).toEO().getBytes() | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Takes source codes on EO, converts to xmir and applies the AOI tool. | ||
* | ||
* @param input Path of the source directory | ||
* @return Path to the directory with the parsed files | ||
* @throws IOException When Parsing EO fails | ||
*/ | ||
private static Path parse(final Path input) throws IOException { | ||
final StringBuilder name = new StringBuilder(input.toString()); | ||
final Path source = Path.of(name.append("_prs").toString()); | ||
FileUtils.copyDirectory(input.toFile(), source.toFile()); | ||
for (final Path path : Files.newDirectoryStream(source)) { | ||
new Syntax( | ||
"scenario", | ||
new InputOf(String.format("%s%n", Files.readString(path))), | ||
new OutputTo(new FileOutputStream(path.toFile())) | ||
).parse(); | ||
} | ||
LauncherKt.launch(source.toString()); | ||
return Path.of(name.append("_aoi").toString()); | ||
} | ||
} |
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
Oops, something went wrong.
7ad77c1
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
39-efbdd83b
discovered insrc/main/java/org/eolang/speco/Walk.java
) and submitted as #109. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.