Skip to content

Commit

Permalink
feat(objectionary#2437): allow using data object directly
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon committed Sep 7, 2023
1 parent c3f0ddb commit fa03245
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,11 @@ SOFTWARE.
<xsl:value-of select="$name"/>
<xsl:text> = </xsl:text>
<xsl:choose>
<xsl:when test="@primitive and @base">
<xsl:text>new </xsl:text>
<xsl:value-of select="eo:class-name(@base, eo:suffix(@line, @pos))"/>
<xsl:text>(Phi.Φ)</xsl:text>
</xsl:when>
<!-- <xsl:when test="@primitive and @base">-->
<!-- <xsl:text>new </xsl:text>-->
<!-- <xsl:value-of select="eo:class-name(@base, eo:suffix(@line, @pos))"/>-->
<!-- <xsl:text>(Phi.Φ)</xsl:text>-->
<!-- </xsl:when>-->
<xsl:when test="@base='$'">
<xsl:text>rho</xsl:text>
</xsl:when>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ xsls:
- /org/eolang/parser/add-default-package.xsl
- /org/eolang/parser/wrap-method-calls.xsl
- /org/eolang/parser/set-locators.xsl
- /org/eolang/parser/explicit-data.xsl
- /org/eolang/maven/pre/classes.xsl
- /org/eolang/maven/pre/attrs.xsl
- /org/eolang/maven/pre/data.xsl
Expand All @@ -15,11 +16,13 @@ tests:
- //java[contains(text(), 'new PhLocated(ret_base, 7, 2, "Φ.bar.φ.ρ")')]
- //java[contains(text(), 'new PhLocated(ret, 7, 4, "Φ.bar.φ")')]
- //java[contains(text(), 'new PhLocated(ret_1, 7, 10, "Φ.bar.φ.α0")')]
- //java[contains(text(), 'new PhLocated(ret, 8, 2, "Φ.bar.five")')]
eo: |
[] > foo
42 > @
[y] > other
43.plus y > @
[] > bar
42.plus 43 > @
42.plus 43 > @
int 5 > five
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ xsls:
- /org/eolang/maven/pre/to-java.xsl
tests:
- /program/errors[count(*)=0]
- //java[contains(text(), 'Phi ret_a2_a1 = new EOorg.EOeolang.EOint(')]
- //java[contains(text(), 'Phi ret_a2_a1 = Phi.Φ.attr("org").get().attr("eolang").get().attr("int").get()')]
- //java[contains(text(), 'Phi[] ret_2_a = new Phi[0]')]
- //java[contains(text(), 'new String(new byte[]')]
eo: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ public final class ParsingTrain extends TrEnvelope {
"/org/eolang/parser/warnings/correct-package-meta.xsl",
"/org/eolang/parser/warnings/prohibited-package.xsl",
"/org/eolang/parser/errors/unused-aliases.xsl",
"/org/eolang/parser/errors/data-objects.xsl",
"/org/eolang/parser/warnings/unit-test-without-phi.xsl",
"/org/eolang/parser/set-locators.xsl",
"/org/eolang/parser/explicit-data.xsl"
};

/**
Expand Down
55 changes: 55 additions & 0 deletions eo-parser/src/main/resources/org/eolang/parser/explicit-data.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License (MIT)
Copyright (c) 2016-2023 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.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" id="sparse-decoration" version="2.0">
<!--
Here we transform just data into application
- 5 -> org.eolang.int 5
- "Hello world" -> org.eolang.string "Hello world"
- org.eolang.float 42.1 -> org.eolang.float 42.1
-->
<xsl:import href="/org/eolang/parser/_datas.xsl"/>
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:template match="//o[o[@data and @base=../@base]]">
<xsl:variable name="base" select="@base"/>
<xsl:if test="$literal-objects[text()=$base]">
<o>
<xsl:for-each select="@*">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:attribute name="data">
<xsl:value-of select="o/@data"/>
</xsl:attribute>
<xsl:value-of select="o"/>
</o>
</xsl:if>
</xsl:template>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
xsls:
- /org/eolang/parser/add-default-package.xsl
- /org/eolang/parser/explicit-data.xsl
tests:
- /program/errors[count(*)=0]
- //o[@base='org.eolang.int' and @name='first' and @line='1' and @pos='0' and @data]
- //o[@base='org.eolang.float' and @name='second' and @line='2' and @pos='0' and @data and count(o)=0]
eo: |
42 > first
float 22.2 > second

0 comments on commit fa03245

Please sign in to comment.