Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Nov 10, 2022
2 parents 8f02eec + 578af15 commit f32a3ce
Show file tree
Hide file tree
Showing 15 changed files with 151 additions and 29 deletions.
10 changes: 7 additions & 3 deletions eo-maven-plugin/src/main/java/org/eolang/maven/OptimizeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.yegor256.xsline.Shift;
import com.yegor256.xsline.StClasspath;
import com.yegor256.xsline.TrClasspath;
import com.yegor256.xsline.TrDefault;
import com.yegor256.xsline.TrFast;
import com.yegor256.xsline.Train;
import com.yegor256.xsline.Xsline;
Expand Down Expand Up @@ -248,10 +249,10 @@ private XML optimize(final Path file) throws FileNotFoundException {
final String name = new XMLDocument(file).xpath("/program/@name").get(0);
Train<Shift> trn = OptimizeMojo.TRAIN.value();
if (this.failOnWarning) {
trn = trn.with(new StClasspath("/org/eolang/parser/errors/fail-on-warnings.xsl"));
trn = trn.with(new StClasspath("/org/eolang/parser/fail-on-warnings.xsl"));
}
if (this.failOnError) {
trn = trn.with(new StClasspath("/org/eolang/parser/errors/fail-on-errors.xsl"));
trn = trn.with(new StClasspath("/org/eolang/parser/fail-on-errors.xsl"));
}
if (this.trackOptimizationSteps) {
final Place place = new Place(name);
Expand All @@ -264,7 +265,10 @@ private XML optimize(final Path file) throws FileNotFoundException {
new Rel(dir)
);
}
return new Xsline(trn).pass(new XMLDocument(file));
return new Xsline(
new TrDefault<Shift>()
.with(new StClasspath("/org/eolang/parser/fail-on-critical.xsl"))
).pass(new Xsline(trn).pass(new XMLDocument(file)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ void testSimpleOptimize(@TempDir final Path temp) throws Exception {
}

@Test
void testOptimizeWithFailOnErrorFlag(@TempDir final Path temp) throws Exception {
void failsOnErrorFlag(@TempDir final Path temp) throws Exception {
final Path src = temp.resolve("foo/main.eo");
new Home(temp).save(
String.join(
Expand Down Expand Up @@ -350,6 +350,42 @@ void testOptimizedFail(@TempDir final Path temp) throws Exception {
);
}

@Test
void stopsOnCritical(@TempDir final Path temp) throws Exception {
final Path src = temp.resolve("foo/main.eo");
new Home(temp).save(
String.join(
"\n",
"+package f\n",
"[args] > main",
" seq > @",
" TRUE > x",
" FALSE > x\n"
),
src
);
final Path target = temp.resolve("target");
final Path foreign = temp.resolve("eo-foreign.csv");
Catalogs.INSTANCE.make(foreign)
.add("foo.main")
.set(AssembleMojo.ATTR_SCOPE, "compile")
.set(AssembleMojo.ATTR_EO, src.toString());
new Moja<>(ParseMojo.class)
.with("targetDir", target.toFile())
.with("foreign", foreign.toFile())
.with("foreignFormat", "csv")
.with("cache", temp.resolve("cache/parsed"))
.execute();
Assertions.assertThrows(
IllegalArgumentException.class,
() -> new Moja<>(OptimizeMojo.class)
.with("targetDir", target.toFile())
.with("foreign", foreign.toFile())
.with("foreignFormat", "csv")
.execute()
);
}

@Test
void testFailOnWarning(@TempDir final Path temp) throws Exception {
final Path src = temp.resolve("foo.src.eo");
Expand Down
34 changes: 19 additions & 15 deletions eo-parser/src/main/java/org/eolang/parser/ParsingTrain.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import com.jcabi.xml.XSLDocument;
import com.yegor256.xsline.StAfter;
import com.yegor256.xsline.StLambda;
import com.yegor256.xsline.TrBulk;
import com.yegor256.xsline.StSequence;
import com.yegor256.xsline.TrClasspath;
import com.yegor256.xsline.TrDefault;
import com.yegor256.xsline.TrEnvelope;
Expand Down Expand Up @@ -56,7 +56,7 @@ public final class ParsingTrain extends TrEnvelope {
private static final String[] SHEETS = {
"/org/eolang/parser/errors/not-empty-atoms.xsl",
"/org/eolang/parser/errors/middle-varargs.xsl",
"/org/eolang/parser/errors/duplicate-names.xsl",
"/org/eolang/parser/critical-errors/duplicate-names.xsl",
"/org/eolang/parser/errors/many-free-attributes.xsl",
"/org/eolang/parser/errors/broken-aliases.xsl",
"/org/eolang/parser/errors/duplicate-aliases.xsl",
Expand All @@ -78,7 +78,7 @@ public final class ParsingTrain extends TrEnvelope {
"/org/eolang/parser/errors/broken-refs.xsl",
"/org/eolang/parser/errors/unknown-names.xsl",
"/org/eolang/parser/errors/noname-attributes.xsl",
"/org/eolang/parser/errors/duplicate-names.xsl",
"/org/eolang/parser/critical-errors/duplicate-names.xsl",
"/org/eolang/parser/warnings/duplicate-metas.xsl",
"/org/eolang/parser/warnings/mandatory-package-meta.xsl",
"/org/eolang/parser/warnings/correct-package-meta.xsl",
Expand All @@ -93,15 +93,20 @@ public final class ParsingTrain extends TrEnvelope {
@SuppressWarnings("unchecked")
public ParsingTrain() {
super(
new TrBulk<>(
new TrClasspath<>(
new TrLambda(
new TrFast(
new TrLogged(
new TrDefault<>()
)
),
shift -> new StAfter(
new TrLambda(
new TrFast(
new TrLogged(
new TrClasspath<>(
new TrDefault<>(),
ParsingTrain.SHEETS
).back()
)
),
shift -> new StLambda(
shift::uid,
(position, out) -> new StSequence(
xml -> xml.nodes("//error[@severity='critical']").isEmpty(),
new StAfter(
shift,
new StLambda(
shift::uid,
Expand All @@ -110,10 +115,9 @@ public ParsingTrain() {
.transform(xml)
)
)
),
ParsingTrain.SHEETS
).apply(position, out)
)
).back().back()
)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ SOFTWARE.
<xsl:value-of select="@line"/>
</xsl:attribute>
<xsl:attribute name="severity">
<xsl:text>error</xsl:text>
<xsl:text>critical</xsl:text>
</xsl:attribute>
<xsl:text>The name "</xsl:text>
<xsl:value-of select="@name"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License (MIT)
Copyright (c) 2016-2022 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.
-->
<!--
Raise an error if errors are found within program
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:eo="https://www.eolang.org" xmlns:xs="http://www.w3.org/2001/XMLSchema" id="fail-on-critical" version="2.0">
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:template match="/program/errors/error[@severity='critical']">
<xsl:message terminate="yes">
<xsl:text>Critical error identified: </xsl:text>
<xsl:for-each select="/program/errors/error[@severity='critical']">
<xsl:value-of select="concat(text(), '; ')"/>
</xsl:for-each>
</xsl:message>
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
32 changes: 32 additions & 0 deletions eo-parser/src/test/java/org/eolang/parser/ParsingTrainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
*/
package org.eolang.parser;

import com.jcabi.matchers.XhtmlMatchers;
import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
import com.yegor256.xsline.Xsline;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
Expand All @@ -42,4 +46,32 @@ void buildsList() {
);
}

@Test
void stopsPipeline() {
final XML xml = new XMLDocument(
String.join(
"\n",
"<program>",
" <errors/>",
" <sheets/>",
" <objects>",
" <o abstract=\"\" line=\"1\" name=\"main\" pos=\"0\">",
" <o base=\"bool\" data=\"bytes\" line=\"2\" name=\"x\" pos=\"2\">01</o>",
" <o base=\"bool\" data=\"bytes\" line=\"3\" name=\"x\" pos=\"2\">00</o>",
" </o>",
" </objects>",
"</program>"
)
);
MatcherAssert.assertThat(
new Xsline(
new ParsingTrain()
).pass(xml),
XhtmlMatchers.hasXPaths(
"/program/sheets[count(sheet)=3]",
"/program/errors/error[@severity='critical']"
)
);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
xsls:
- /org/eolang/parser/errors/duplicate-names.xsl
- /org/eolang/parser/critical-errors/duplicate-names.xsl
- /org/eolang/parser/errors/self-naming.xsl
- /org/eolang/parser/errors/same-line-names.xsl
- /org/eolang/parser/add-refs.xsl
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
xsls:
- /org/eolang/parser/errors/duplicate-names.xsl
- /org/eolang/parser/critical-errors/duplicate-names.xsl
tests:
- /program/errors[count(error[@severity='error'])=1]
- /program/errors[count(error[@severity='critical'])=1]
eo: |
foo
1 > name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
xsls:
- /org/eolang/parser/errors/duplicate-names.xsl
- /org/eolang/parser/critical-errors/duplicate-names.xsl
tests:
- /program/errors[count(error[@severity='error'])=2]
- /program/errors[count(error[@severity='critical'])=2]
- /program/errors/error[@line='2']
- /program/objects/o[@name='first']/o[@name='x']
eo: |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
xsls:
- /org/eolang/parser/errors/duplicate-names.xsl
- /org/eolang/parser/critical-errors/duplicate-names.xsl
- /org/eolang/parser/errors/duplicate-aliases.xsl
- /org/eolang/parser/expand-aliases.xsl
- /org/eolang/parser/resolve-aliases.xsl
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
xsls:
- /org/eolang/parser/add-refs.xsl
- /org/eolang/parser/vars-float-up.xsl
- /org/eolang/parser/errors/duplicate-names.xsl
- /org/eolang/parser/critical-errors/duplicate-names.xsl
tests:
- /program/errors[count(*)=0]
- /program/objects[count(o)=3]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ xsls:
- /org/eolang/parser/optimize/remove-levels.xsl
- /org/eolang/parser/add-refs.xsl
- /org/eolang/parser/errors/same-line-names.xsl
- /org/eolang/parser/errors/duplicate-names.xsl
- /org/eolang/parser/critical-errors/duplicate-names.xsl
- /org/eolang/parser/errors/broken-refs.xsl
tests:
- /program/objects[count(o)=9]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
xsls:
- /org/eolang/parser/optimize/abstracts-float-up.xsl
- /org/eolang/parser/errors/duplicate-names.xsl
- /org/eolang/parser/critical-errors/duplicate-names.xsl
tests:
- /program/errors[count(error)=0]
eo: |
Expand Down

0 comments on commit f32a3ce

Please sign in to comment.