forked from objectionary/eo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(objectionary#2437): allow using data object directly
- Loading branch information
1 parent
c3f0ddb
commit fa03245
Showing
6 changed files
with
76 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
eo-parser/src/main/resources/org/eolang/parser/explicit-data.xsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
10 changes: 10 additions & 0 deletions
10
eo-parser/src/test/resources/org/eolang/parser/packs/explicit-data.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |