Skip to content

Commit

Permalink
#1 final sets are good
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jun 29, 2021
1 parent e4a6a89 commit 92a201e
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/polystat/far/Reverses.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public Collection<String> errors(final String locator) throws IOException {
)
)
),
xml -> !xml.nodes("//r").isEmpty()
(before, after) -> !after.nodes("//r").isEmpty()
)
.with(Reverses.xsl("remove-input-perps.xsl"))
.with(Reverses.xsl("remove-outsiders.xsl"))
Expand Down
18 changes: 15 additions & 3 deletions src/main/resources/org/polystat/far/build-calc-function.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,22 @@ SOFTWARE.
</xsl:element>
</xsl:element>
<xsl:element name="xsl:choose">
<xsl:apply-templates select="rule"/>
<xsl:element name="xsl:otherwise">
<xsl:element name="xsl:when">
<xsl:attribute name="test">
<xsl:text>$y = '\any'</xsl:text>
</xsl:attribute>
<xsl:element name="v">
<xsl:text>NONE</xsl:text>
<xsl:text>\any</xsl:text>
</xsl:element>
</xsl:element>
<xsl:element name="xsl:otherwise">
<xsl:element name="xsl:choose">
<xsl:apply-templates select="rule"/>
<xsl:element name="xsl:otherwise">
<xsl:element name="v">
<xsl:text>NONE</xsl:text>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:element>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/org/polystat/far/remove-conflicts.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ SOFTWARE.
<xsl:variable name="o" select="."/>
<xsl:variable name="conflicts">
<xsl:for-each select="parent::opts/parent::o/opts[generate-id() != generate-id(current()/parent::opts)]">
<xsl:variable name="opts" select="./opt[$o/@x=@x]"/>
<xsl:variable name="opts" select="./opt[$o/@x=@x or @x='\any' or $o/@x='\any']"/>
<xsl:variable name="cs" select="ps:conflicts($o, $opts)"/>
<xsl:if test="count($cs) = count($opts)">
<xsl:element name="v">
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/org/polystat/far/remove-outsiders.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ 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.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" id="remove-input-perps" version="2.0">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" id="remove-outsiders" version="2.0">
<xsl:strip-space elements="*"/>
<xsl:template match="opt[exists(parent::opts/parent::o/opts[not(exists(opt[@x = current()/@x]))])]">
<xsl:template match="opt[exists(parent::opts/parent::o/opts[not(exists(opt[@x = current()/@x or @x='\any' or current()/@x='\any']))])]">
<!-- remove it -->
</xsl:template>
<xsl:template match="node()|@*">
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/org/polystat/far/rules.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.add(\perp) -> {{ANY \perp} {\perp ANY}}
.add(\perp) -> {{\any \perp} {\perp \any}}
.add(y) -> {{0 y}}
.div(\perp) -> {{ANY \perp} {\perp ANY} {ANY 0}}
.div(\perp) -> {{\any \perp} {\perp \any} {\any 0}}
.div(y) -> {{y 1}}
28 changes: 27 additions & 1 deletion src/test/java/org/polystat/far/CalcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
*/
package org.polystat.far;

import com.jcabi.log.Logger;
import com.jcabi.xml.XSL;
import org.cactoos.io.ResourceOf;
import org.cactoos.text.TextOf;
import org.cactoos.text.UncheckedText;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
Expand All @@ -35,8 +40,29 @@
public final class CalcTest {

@Test
public void buildsRulesXsl() {
public void buildsSimpleRulesXsl() {
final Calc rules = new Calc("add(y) -> {{y 0}}");
final XSL xsl = rules.xsl();
Logger.debug(this, "calc.xsl:%n%s", xsl.toString());
MatcherAssert.assertThat(
rules.xsl(),
Matchers.notNullValue()
);
}

@Test
public void buildsRealRulesXsl() {
final Calc rules = new Calc(
new UncheckedText(
new TextOf(
new ResourceOf(
"org/polystat/far/rules.txt"
)
)
).asString().trim()
);
final XSL xsl = rules.xsl();
Logger.debug(this, "calc.xsl:%n%s", xsl.toString());
MatcherAssert.assertThat(
rules.xsl(),
Matchers.notNullValue()
Expand Down
8 changes: 6 additions & 2 deletions src/test/resources/org/polystat/tests/div-by-zero.eo
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

[a b] > foo
add. > @
div. a b
div.
a
div. b a
b
div.
div.
b
a
a

0 comments on commit 92a201e

Please sign in to comment.