Skip to content

Commit

Permalink
fix(#2778): jeo test + train fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon committed Jan 16, 2024
1 parent ec87153 commit 9d2277b
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 56 deletions.
20 changes: 17 additions & 3 deletions eo-maven-plugin/src/main/java/org/eolang/maven/PhiMojo.java
Expand Up @@ -28,6 +28,8 @@
import com.jcabi.xml.XMLDocument;
import com.yegor256.xsline.Shift;
import com.yegor256.xsline.StClasspath;
import com.yegor256.xsline.StSequence;
import com.yegor256.xsline.TrLambda;
import com.yegor256.xsline.Train;
import com.yegor256.xsline.Xsline;
import java.io.File;
Expand Down Expand Up @@ -60,7 +62,16 @@ public final class PhiMojo extends SafeMojo {
/**
* Transformations train.
*/
private static final Train<Shift> TRAIN = new ParsingTrain();
private static final Train<Shift> TRAIN = new TrLambda(
new ParsingTrain(),
shift -> new StSequence(
shift.uid(),
xml -> xml.nodes(
String.format("/program/sheets/sheet[text()='%s']", shift.uid())
).isEmpty(),
shift
)
);

/**
* Extension of the file where we put phi-calculus expression (.phi).
Expand Down Expand Up @@ -137,11 +148,14 @@ count, new Rel(this.phiInputDir), new Rel(this.phiOutputDir)
* @param xmir Text of xmir
* @return Translated xmir
*/
private static String translated(final XML xmir) {
private static String translated(final XML xmir) throws Exception {
return new Xsline(
PhiMojo.TRAIN.with(
new StClasspath("/org/eolang/maven/phi/to-phi.xsl")
)
).pass(xmir).toString();
)
.pass(xmir)
.xpath("phi/text()")
.get(0);
}
}
52 changes: 27 additions & 25 deletions eo-maven-plugin/src/main/resources/org/eolang/maven/phi/to-phi.xsl
Expand Up @@ -167,30 +167,32 @@ SOFTWARE.
</xsl:function>
<!-- Program -->
<xsl:template match="program">
<xsl:text>{</xsl:text>
<xsl:variable name="has-package" select="metas/meta/head[text()='package']"/>
<xsl:variable name="parts" select="tokenize(metas/meta[head[text()='package']]/tail[1], '\.')"/>
<xsl:choose>
<xsl:when test="$has-package">
<xsl:for-each select="$parts">
<xsl:value-of select="."/>
<xsl:value-of select="$arrow"/>
<xsl:value-of select="$lb"/>
</xsl:for-each>
<xsl:apply-templates select="objects"/>
<xsl:for-each select="$parts">
<xsl:value-of select="eo:comma(2)"/>
<xsl:value-of select="$lambda"/>
<xsl:value-of select="$dashed-arrow"/>
<xsl:text>Package</xsl:text>
<xsl:value-of select="$rb"/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="objects"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text>}</xsl:text>
<phi>
<xsl:text>{</xsl:text>
<xsl:variable name="has-package" select="metas/meta/head[text()='package']"/>
<xsl:variable name="parts" select="tokenize(metas/meta[head[text()='package']]/tail[1], '\.')"/>
<xsl:choose>
<xsl:when test="$has-package">
<xsl:for-each select="$parts">
<xsl:value-of select="."/>
<xsl:value-of select="$arrow"/>
<xsl:value-of select="$lb"/>
</xsl:for-each>
<xsl:apply-templates select="objects"/>
<xsl:for-each select="$parts">
<xsl:value-of select="eo:comma(2)"/>
<xsl:value-of select="$lambda"/>
<xsl:value-of select="$dashed-arrow"/>
<xsl:text>Package</xsl:text>
<xsl:value-of select="$rb"/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="objects"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text>}</xsl:text>
</phi>
</xsl:template>
<!-- Objects -->
<xsl:template match="objects">
Expand Down Expand Up @@ -277,7 +279,7 @@ SOFTWARE.
</xsl:choose>
<!-- Data -->
<xsl:if test="@data">
<xsl:if test="$literal-objects/text()!=concat('org.eolang.',@data)">
<xsl:if test="not(concat('org.eolang.',@data)=$literal-objects/text())">
<xsl:message terminate="yes">
<xsl:text>Invalid value in data attribute: </xsl:text>
<xsl:value-of select="@data"/>
Expand Down
@@ -0,0 +1,40 @@
eo: |
+package org.eolang.benchmark
[] > j$A
32 > access
"java/lang/Object" > supername
* > interfaces
"org/eolang/benchmark/F"
phi: |
{
org ↦ ⟦
eolang ↦ ⟦
benchmark ↦ ⟦
j$A ↦ ⟦
access ↦ Φ.org.eolang.int(
α0 ↦ Φ.org.eolang.bytes(
Δ ⤍ 00-00-00-00-00-00-00-20
)
),
supername ↦ Φ.org.eolang.string(
α0 ↦ Φ.org.eolang.bytes(
Δ ⤍ 6A-61-76-61-2F-6C-61-6E-67-2F-4F-62-6A-65-63-74
)
),
interfaces ↦ Φ.org.eolang.tuple(
α0 ↦ Φ.org.eolang.tuple.emtpy,
α1 ↦ Φ.org.eolang.string(
α0 ↦ Φ.org.eolang.bytes(
Δ ⤍ 6F-72-67-2F-65-6F-6C-61-6E-67-2F-62-65-6E-63-68-6D-61-72-6B-2F-46
)
)
)
⟧,
λ ⤍ Package
⟧,
λ ⤍ Package
⟧,
λ ⤍ Package
}
57 changes: 30 additions & 27 deletions eo-parser/src/main/java/org/eolang/parser/ParsingTrain.java
Expand Up @@ -121,36 +121,39 @@ public ParsingTrain() {
*/
ParsingTrain(final String... sheets) {
super(
new TrJoined<>(
new TrDefault<>(
new StEndless(
new StLambda(ParsingTrain.TUPLES::transform)
)
),
new TrLambda(
new TrFast(
new TrLambda(
new TrLogged(
new TrClasspath<>(sheets).back(),
ParsingTrain.class,
Level.FINEST
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()
),
StEoLogged::new
ParsingTrain.class,
Level.FINEST
),
TrFast.class,
500L
StEoLogged::new
),
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)
)
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)
)
)
)
Expand Down
Expand Up @@ -298,7 +298,7 @@ public void exitDeltaBidning(final PhiParser.DeltaBidningContext ctx) {
@Override
public void enterLambdaBidning(final PhiParser.LambdaBidningContext ctx) {
if (!ctx.FUNCTION().getText().equals(XePhiListener.LAMBDA_PACKAGE)) {
this.objects().prop("atom");
this.objects().prop("atom", "?");
}
}

Expand Down
4 changes: 4 additions & 0 deletions eo-parser/src/main/resources/XMIR.xsd
Expand Up @@ -68,6 +68,7 @@ SOFTWARE.
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="check"/>
<xs:attribute name="line" use="required"/>
<xs:attribute name="severity" use="required">
<xs:simpleType>
Expand All @@ -78,6 +79,8 @@ SOFTWARE.
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="sheet"/>
<xs:attribute name="step"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand All @@ -104,6 +107,7 @@ SOFTWARE.
<xs:element name="part" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="line" type="xs:decimal"/>
<xs:attribute name="expanded"/>
</xs:complexType>
</xs:element>
</xs:sequence>
Expand Down

0 comments on commit 9d2277b

Please sign in to comment.