Skip to content

Commit

Permalink
#3257 this.measured()
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Nov 5, 2024
1 parent 289cde9 commit eb316c0
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
import com.yegor256.xsline.Shift;
import com.yegor256.xsline.TrLambda;
import com.yegor256.xsline.Train;
import java.nio.file.Path;
import java.util.Collection;
Expand All @@ -45,7 +44,6 @@
import org.eolang.maven.tojos.ForeignTojo;
import org.eolang.maven.tojos.TojoHash;
import org.eolang.parser.ParsingTrain;
import org.eolang.parser.StMeasured;

/**
* Optimize XML files.
Expand Down Expand Up @@ -143,13 +141,7 @@ private int optimized(final ForeignTojo tojo, final Optimization optimization)
*/
private Optimization optimization() {
final Optimization opt;
final Train<Shift> train = new TrLambda(
new ParsingTrain(),
shift -> new StMeasured(
shift,
this.targetDir.toPath().resolve("xsl-measures.csv")
)
);
final Train<Shift> train = this.measured(new ParsingTrain());
if (this.trackOptimizationSteps) {
opt = new OptSpy(
train,
Expand Down
8 changes: 1 addition & 7 deletions eo-maven-plugin/src/main/java/org/eolang/maven/PhiMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.yegor256.xsline.TrClasspath;
import com.yegor256.xsline.TrDefault;
import com.yegor256.xsline.TrJoined;
import com.yegor256.xsline.TrLambda;
import com.yegor256.xsline.Train;
import com.yegor256.xsline.Xsline;
import java.io.File;
Expand All @@ -51,7 +50,6 @@
import org.eolang.maven.util.Walk;
import org.eolang.parser.ParsingTrain;
import org.eolang.parser.Schema;
import org.eolang.parser.StMeasured;

/**
* Read XMIR files and translate them to the phi-calculus expression.
Expand Down Expand Up @@ -236,14 +234,10 @@ private Train<Shift> train() {
dependent.add("/org/eolang/parser/fail-on-critical.xsl");
}
dependent.add("/org/eolang/maven/phi/to-phi.xsl");
return new TrLambda(
return this.measured(
new TrJoined<>(
train,
new TrClasspath<>(dependent.toArray(new String[0])).back()
),
shift -> new StMeasured(
shift,
this.targetDir.toPath().resolve("xsl-measures.csv")
)
);
}
Expand Down
19 changes: 19 additions & 0 deletions eo-maven-plugin/src/main/java/org/eolang/maven/SafeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
package org.eolang.maven;

import com.jcabi.log.Logger;
import com.yegor256.xsline.Shift;
import com.yegor256.xsline.TrLambda;
import com.yegor256.xsline.Train;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -52,6 +55,7 @@
import org.eolang.maven.tojos.ForeignTojos;
import org.eolang.maven.tojos.PlacedTojos;
import org.eolang.maven.tojos.TranspiledTojos;
import org.eolang.parser.StMeasured;
import org.slf4j.impl.StaticLoggerBinder;

/**
Expand Down Expand Up @@ -349,6 +353,21 @@ protected final ForeignTojos scopedTojos() {
return this.tojos;
}

/**
* Make a measured train from another train.
* @param train The train
* @return Measured train
*/
protected final Train<Shift> measured(final Train<Shift> train) {
return new TrLambda(
train,
shift -> new StMeasured(
shift,
this.targetDir.toPath().resolve("xsl-measures.csv")
)
);
}

/**
* Exec it.
* @throws IOException If fails
Expand Down
10 changes: 5 additions & 5 deletions eo-maven-plugin/src/main/java/org/eolang/maven/SodgMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,8 @@ private int render(final Path xmir, final Path sodg) throws IOException {
if (Logger.isTraceEnabled(this)) {
Logger.trace(this, "XML before translating to SODG:\n%s", before);
}
final XML after = new Xsline(SodgMojo.TRAIN).pass(before);
final String instructions = new Xsline(SodgMojo.TO_TEXT)
final XML after = new Xsline(this.measured(SodgMojo.TRAIN)).pass(before);
final String instructions = new Xsline(this.measured(SodgMojo.TO_TEXT))
.pass(after)
.xpath("/text/text()")
.get(0);
Expand All @@ -465,7 +465,7 @@ private int render(final Path xmir, final Path sodg) throws IOException {
);
}
if (this.generateXemblyFiles) {
final String xembly = new Xsline(SodgMojo.TO_XEMBLY)
final String xembly = new Xsline(this.measured(SodgMojo.TO_XEMBLY))
.pass(after)
.xpath("/xembly/text()").get(0);
final Path sibling = sodg.resolveSibling(String.format("%s.xe", sodg.getFileName()));
Expand Down Expand Up @@ -493,7 +493,7 @@ private void makeGraph(final String xembly, final Path sodg) throws IOException
);
final ListOf<Directive> directives = new ListOf<>(all);
final Directive comment = directives.remove(0);
final XML graph = new Xsline(SodgMojo.FINISH).pass(
final XML graph = new Xsline(this.measured(SodgMojo.FINISH)).pass(
new XMLDocument(
new Xembler(
new Directives()
Expand Down Expand Up @@ -526,7 +526,7 @@ private void makeGraph(final String xembly, final Path sodg) throws IOException
*/
private void makeDot(final XML graph, final Path sodg) throws IOException {
if (this.generateDotFiles) {
final String dot = new Xsline(SodgMojo.TO_DOT)
final String dot = new Xsline(this.measured(SodgMojo.TO_DOT))
.pass(graph).xpath("//dot/text()").get(0);
if (Logger.isTraceEnabled(this)) {
Logger.trace(this, "Dot:\n%s", dot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import com.yegor256.xsline.TrClasspath;
import com.yegor256.xsline.TrDefault;
import com.yegor256.xsline.TrJoined;
import com.yegor256.xsline.TrLambda;
import com.yegor256.xsline.Train;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -64,7 +63,6 @@
import org.eolang.maven.tojos.AttributeNotFoundException;
import org.eolang.maven.tojos.ForeignTojo;
import org.eolang.maven.tojos.TojoHash;
import org.eolang.parser.StMeasured;

/**
* Transpile.
Expand Down Expand Up @@ -235,13 +233,7 @@ private long transpiled(final ForeignTojo tojo, final Optimization transpilation
*/
private Optimization transpilation() {
return new OptSpy(
new TrLambda(
TranspileMojo.TRAIN,
shift -> new StMeasured(
shift,
this.targetDir.toPath().resolve("xsl-measures.csv")
)
),
this.measured(TranspileMojo.TRAIN),
this.targetDir.toPath().resolve(TranspileMojo.PRE)
);
}
Expand Down
29 changes: 15 additions & 14 deletions eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

import com.jcabi.log.Logger;
import com.jcabi.xml.XML;
import com.yegor256.xsline.Shift;
import com.yegor256.xsline.TrClasspath;
import com.yegor256.xsline.Train;
import com.yegor256.xsline.Xsline;
import java.io.File;
import java.nio.file.Path;
Expand Down Expand Up @@ -63,13 +65,11 @@ public final class UnphiMojo extends SafeMojo {
/**
* Unphi transformations.
*/
private static final Xsline TRANSFORMATIONS = new Xsline(
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<Shift> 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();

/**
* The directory where to take phi files for parsing from.
Expand Down Expand Up @@ -118,13 +118,14 @@ public void exec() {
String.format(".%s", AssembleMojo.XMIR)
)
);
final XML result = UnphiMojo.TRANSFORMATIONS.pass(
new PhiSyntax(
phi.getFileName().toString().replace(".phi", ""),
new TextOf(phi),
metas
).parsed()
);
final XML result = new Xsline(this.measured(UnphiMojo.TRANSFORMATIONS))
.pass(
new PhiSyntax(
phi.getFileName().toString().replace(".phi", ""),
new TextOf(phi),
metas
).parsed()
);
home.save(result.toString(), xmir);
Logger.info(
this,
Expand Down

0 comments on commit eb316c0

Please sign in to comment.