Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(#3842): no alpha bindings in formations #3844

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,12 @@ SOFTWARE.
<xsl:param name="name"/>
<xsl:param name="rho"/>
<xsl:variable name="method" select="substring-after(@base, '.')"/>
<xsl:if test="starts-with(@base, concat('.', $ALPHA))">
<xsl:message terminate="yes">
<xsl:text>Dispatching alpha attributes is not supported in EO yet, found: </xsl:text>
<xsl:value-of select="@base"/>
</xsl:message>
</xsl:if>
<xsl:apply-templates select="o[1]">
<xsl:with-param name="name">
<xsl:value-of select="$name"/>
Expand Down
15 changes: 12 additions & 3 deletions eo-parser/src/main/antlr4/org/eolang/parser/Phi.g4
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ tauBinding
| attribute voids ARROW formation
;

applicationTauBinding
: fullAttribute ARROW object
| fullAttribute voids ARROW formation
;

voids
: LB (void? | void (COMMA void)+) RB
;
Expand All @@ -77,6 +82,10 @@ attribute
: PHI
| RHO
| LABEL
;

fullAttribute
: attribute
| ALPHA
;

Expand All @@ -101,8 +110,8 @@ application
;

applicationBindings
: tauBinding?
| tauBinding (COMMA tauBinding)*
: applicationTauBinding?
| applicationTauBinding (COMMA applicationTauBinding)*
;

applicationObjects
Expand All @@ -114,7 +123,7 @@ justObject
: object
;

dispatch: DOT attribute
dispatch: DOT fullAttribute
;

applicationsOrDispatches
Expand Down
12 changes: 4 additions & 8 deletions eo-parser/src/main/java/org/eolang/parser/TrFull.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.yegor256.xsline.TrDefault;
import com.yegor256.xsline.TrEnvelope;
import com.yegor256.xsline.TrFast;
import com.yegor256.xsline.TrLambda;
import com.yegor256.xsline.TrLogged;
import com.yegor256.xsline.Train;
import java.util.logging.Level;
Expand All @@ -52,13 +51,10 @@ public TrFull(final Train<Shift> train) {
super(
new TrStepped(
new TrFast(
new TrLambda(
new TrLogged(
train,
TrFull.class,
Level.FINEST
),
StEoLogged::new
new TrLogged(
train,
TrFull.class,
Level.FINEST
),
TrFull.class,
500L
Expand Down
24 changes: 23 additions & 1 deletion eo-parser/src/main/java/org/eolang/parser/XePhiListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,16 @@ public void exitTauBinding(final PhiParser.TauBindingContext ctx) {
this.exitObjectBinding();
}

@Override
public void enterApplicationTauBinding(final PhiParser.ApplicationTauBindingContext ctx) {
this.startObject(ctx);
}

@Override
public void exitApplicationTauBinding(final PhiParser.ApplicationTauBindingContext ctx) {
this.exitObjectBinding();
}

@Override
public void enterVoids(final PhiParser.VoidsContext ctx) {
// Nothing here
Expand Down Expand Up @@ -267,7 +277,7 @@ public void enterAttribute(final PhiParser.AttributeContext ctx) {
attr = "@";
} else if (ctx.RHO() != null) {
attr = "^";
} else if (ctx.LABEL() != null || ctx.ALPHA() != null) {
} else if (ctx.LABEL() != null) {
attr = ctx.getText();
} else {
attr = "";
Expand All @@ -280,6 +290,18 @@ public void exitAttribute(final PhiParser.AttributeContext ctx) {
// Nothing here
}

@Override
public void enterFullAttribute(final PhiParser.FullAttributeContext ctx) {
if (ctx.attribute() == null) {
this.attributes.push(ctx.getText());
}
}

@Override
public void exitFullAttribute(final PhiParser.FullAttributeContext ctx) {
// Nothing here
}

@Override
public void enterEmptyBinding(final PhiParser.EmptyBindingContext ctx) {
this.addVoidAttribute(ctx);
Expand Down
2 changes: 1 addition & 1 deletion eo-parser/src/main/java/org/eolang/parser/Xmir.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public String toSaltyPhi() {
* @return XMIR in other representation as {@link String}.
*/
private String converted(final Train<Shift> train, final String xsl, final String xpath) {
return this.converted(new TrJoined<>(train.with(new StClasspath(xsl))), xpath);
return this.converted(train.with(new StClasspath(xsl)), xpath);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ SOFTWARE.
<xsl:template match="o[@base and not(eo:has-data(.))]" mode="head">
<xsl:choose>
<xsl:when test="starts-with(@base,'.')">
<xsl:if test="starts-with(@base, concat('.', $alpha))">
<xsl:message terminate="yes">
<xsl:text>Dispatching alpha attributes is not supported in EO yet, found: </xsl:text>
<xsl:value-of select="@base"/>
</xsl:message>
</xsl:if>
<xsl:value-of select="substring(@base,2)"/>
<xsl:text>.</xsl:text>
</xsl:when>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ SOFTWARE.
<xsl:choose>
<!-- METHOD -->
<xsl:when test="starts-with(@base,'.')">
<xsl:if test="starts-with(@base, concat('.', $alpha))">
<xsl:message terminate="yes">
<xsl:text>Dispatching alpha attributes is not supported in EO yet, found: </xsl:text>
<xsl:value-of select="@base"/>
</xsl:message>
</xsl:if>
<xsl:apply-templates select="o[position()=1]">
<xsl:with-param name="indent" select="$indent"/>
</xsl:apply-templates>
Expand Down
24 changes: 24 additions & 0 deletions eo-parser/src/test/java/org/eolang/parser/XmirTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import com.jcabi.matchers.XhtmlMatchers;
import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
import java.io.IOException;
import org.cactoos.io.InputOf;
import org.eolang.jucs.ClasspathSource;
Expand All @@ -33,7 +34,11 @@
import org.eolang.xax.Xtory;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.xembly.Directives;
import org.xembly.Xembler;

/**
* Test case for {@link Xmir}.
Expand All @@ -42,6 +47,25 @@
*/
final class XmirTest {

@Test
void failsOnDispatchingAlphaAttributes() {
Assertions.assertThrows(
IllegalArgumentException.class,
new Xmir(
new XMLDocument(
new Xembler(
new Directives(new DrProgram("foo"))
.add("objects")
.add("o").attr("name", "foo")
.add("o").attr("base", ".α0").attr("name", "self")
.add("o").attr("base", "$")
).xmlQuietly()
)
)::toEO,
"XMIR with alpha dispatch should fail on converting to EO"
);
}

@ParameterizedTest
@ClasspathSource(value = "org/eolang/parser/print-packs/yaml", glob = "**.yaml")
void printsToEoStraight(final String pack) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
error-on-purpose ↦ ⊥,
the-атрибут ↦ Φ.ρ,
hi-大家 ↦ ⟦ ⟧,
α0 ↦ Φ () () (),
α65536 ↦ Φ.r,
k ↦ ⟦ λ ⤍ Function_Name_i64, α0 ↦ ⟦ λ ⤍ FunctionName, Δ ⤍ 42- ⟧ ⟧,
triple ↦ Φ () () (),
sss ↦ Φ.r,
alpha-dispatch ↦ ξ.x.α0.α1.y,
k ↦ ⟦ λ ⤍ Function_Name_i64, first ↦ ⟦ λ ⤍ FunctionName, Δ ⤍ 42- ⟧ ⟧,
terminator-application ↦ ⊥ (t ↦ ξ.t),
terminator-dispatch ↦ ⊥.t,
string ↦ "Hello",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{⟦ α0 ↦ ξ.t ⟧}
Loading