Skip to content

Commit

Permalink
fix(objectionary#3569): prohibit numbers in attribute-name in XSD
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon committed Dec 8, 2024
1 parent c0b8fba commit d5ab000
Show file tree
Hide file tree
Showing 19 changed files with 146 additions and 55 deletions.
48 changes: 25 additions & 23 deletions eo-maven-plugin/src/main/resources/org/eolang/maven/phi/to-phi.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ SOFTWARE.
<xsl:output encoding="UTF-8" method="text"/>
<!-- Variables -->
<xsl:variable name="aliases" select="program/metas/meta/part[last()]"/>
<xsl:variable name="number-pattern">
<xsl:value-of select="'^[0-9][1-9]*$'"/>
</xsl:variable>
<xsl:variable name="number-pattern" select="'^[0-9][1-9]*$'"/>
<xsl:variable name="xi">
<select>ξ</select>
</xsl:variable>
Expand Down Expand Up @@ -214,34 +212,38 @@ SOFTWARE.
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<!--
Try to get @as attribute from the object and convert to number, if @as is absent - return position
-->
<xsl:function name="eo:element-binding">
<xsl:param name="object"/>
<xsl:param name="position"/>
<xsl:choose>
<xsl:when test="$object/@as">
<xsl:choose>
<xsl:when test="starts-with($object/@as, $alpha)">
<xsl:value-of select="number(substring-after($object/@as, $alpha))"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$object/@as"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$position"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<!--
CHECKS IF APPLICATION ARGUMENTS IS RIGHT ORDER WITH ALPHAS, e.g.
α0 -> a, α1 -> b, ..., αN -> z
-->
<xsl:function name="eo:is-ordered">
<xsl:param name="current"/>
<xsl:param name="position"/>
<xsl:variable name="current-pos">
<xsl:choose>
<xsl:when test="$current/@as">
<xsl:value-of select="$current/@as"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$position - 1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="current-pos" select="eo:element-binding($current, $position - 1)"/>
<xsl:variable name="next" select="$current/following-sibling::o[1]"/>
<xsl:variable name="next-pos">
<xsl:choose>
<xsl:when test="$next/@as">
<xsl:value-of select="$next/@as"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$position"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="next-pos" select="eo:element-binding($next, $position)"/>
<xsl:choose>
<xsl:when test="matches($current-pos, $number-pattern)">
<xsl:choose>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ SOFTWARE.
<xsl:variable name="PHI">
<xsl:text>φ</xsl:text>
</xsl:variable>
<xsl:variable name="ALPHA">
<xsl:text>α</xsl:text>
</xsl:variable>
<!-- FUNCTIONS -->
<!-- EOL -->
<xsl:function name="eo:eol">
Expand Down Expand Up @@ -453,8 +456,8 @@ SOFTWARE.
<xsl:choose>
<xsl:when test="@as">
<xsl:choose>
<xsl:when test="matches(@as,'^[0-9]+$')">
<xsl:value-of select="eo:attr-name(@as)"/>
<xsl:when test="starts-with(@as, $ALPHA)">
<xsl:value-of select="eo:attr-name(substring-after(@as, $ALPHA))"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>"</xsl:text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ SOFTWARE.
-->
<xsl:import href="/org/eolang/parser/_funcs.xsl"/>
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:template match="o[eo:abstract(.) and @as='0' and eo:has-data(.)]">
<xsl:template match="o[eo:abstract(.) and @as='α0' and eo:has-data(.)]">
<xsl:value-of select="text()"/>
</xsl:template>
<xsl:template match="node()|@*">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ SOFTWARE.
<xsl:attribute name="base">org.eolang.bytes</xsl:attribute>
<xsl:attribute name="name" select="@name"/>
<xsl:element name="o">
<xsl:attribute name="as" select="0"/>
<xsl:attribute name="as" select="'α0'"/>
<xsl:value-of select="text()"/>
</xsl:element>
</xsl:element>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ input: |
[z]:abs
w > @
5:five
"hello":3
phi: |-
{
Expand All @@ -35,7 +36,8 @@ phi: |-
z ↦ ∅,
φ ↦ Φ̇.w
⟧,
five ↦ 5
five ↦ 5,
α3 ↦ "hello"
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2024 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.
---
input: |
x > xyz
"f":0
"s":1
"t":2
phi: |-
{
xyz ↦ Φ̇.x("f", "s", "t")
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ asserts:
- //o[@base='.x' and @name='xyz']/o[not(@base) and @as='abs']/o[@name='z' and @base='∅']
- //o[@base='.x' and @name='xyz']/o[not(@base) and @as='abs']/o[@base='.w' and @name='@']/o[@base='.eolang']/o[@base='.org']/o[@base='Q']
- //o[@base='.x' and @name='xyz']/o[@base='.int' and @as='five']/o[@base='.eolang']/o[@base='.org']/o[@base='Q']
- //o[@base='.x' and @name='xyz']/o[@base='.int' and @as='five']/o[@as='0' and @base='.bytes']/o[@base='.eolang']/o[@base='.org']/o[@base='Q']
- //o[@base='.x' and @name='xyz']/o[@base='.int' and @as='five']/o[@as='0' and @base='.bytes' and text()!='']
- //o[@base='.x' and @name='xyz']/o[@base='.int' and @as='five']/o[@as='α0' and @base='.bytes']/o[@base='.eolang']/o[@base='.org']/o[@base='Q']
- //o[@base='.x' and @name='xyz']/o[@base='.int' and @as='five']/o[@as='α0' and @base='.bytes' and text()!='']
phi: |-
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
---
asserts:
- //o[@base='.foo' and @name='xyz']/o[1][@base='Q']
- //o[@base='.foo' and @name='xyz']/o[@as='0' and @base='org.eolang.string']/o[@base='org.eolang.bytes' and text()='48-65-6C-6C-6F']
- //o[@base='.foo' and @name='xyz']/o[@as='1' and @base='org.eolang.string']/o[@base='org.eolang.bytes' and text()='77-6F-72-6C-64']
- //o[@base='.foo' and @name='xyz']/o[@as='2' and @base='.plus']/o[1][@base='org.eolang.number' and not(@as)]/o[@base='org.eolang.bytes' and text()='40-45-00-00-00-00-00-00']
- //o[@base='.foo' and @name='xyz']/o[@as='2' and @base='.plus']/o[@base='org.eolang.number' and @as='0']/o[@base='org.eolang.bytes' and text()='40-41-80-00-00-00-00-00']
- //o[@base='.foo' and @name='xyz']/o[@as='3' and @base='.some']/o[1][@base='org.eolang.number' and not(@as)]/o[@base='org.eolang.bytes' and text()='40-3F-19-99-99-99-99-9A']
- //o[@base='.foo' and @name='xyz']/o[@as='3' and @base='.some']/o[@base='.y' and @as='0']/o[1][@base='Q']
- //o[@base='.foo' and @name='xyz']/o[@as='3' and @base='.some']/o[@base='.y' and @as='0']/o[@base='org.eolang.number' and @as='0']/o[@base='org.eolang.bytes' and text()='40-26-00-00-00-00-00-00']
- //o[@base='.foo' and @name='xyz']/o[@as='α0' and @base='org.eolang.string']/o[@base='org.eolang.bytes' and text()='48-65-6C-6C-6F']
- //o[@base='.foo' and @name='xyz']/o[@as='α1' and @base='org.eolang.string']/o[@base='org.eolang.bytes' and text()='77-6F-72-6C-64']
- //o[@base='.foo' and @name='xyz']/o[@as='α2' and @base='.plus']/o[1][@base='org.eolang.number' and not(@as)]/o[@base='org.eolang.bytes' and text()='40-45-00-00-00-00-00-00']
- //o[@base='.foo' and @name='xyz']/o[@as='α2' and @base='.plus']/o[@base='org.eolang.number' and @as='α0']/o[@base='org.eolang.bytes' and text()='40-41-80-00-00-00-00-00']
- //o[@base='.foo' and @name='xyz']/o[@as='α3' and @base='.some']/o[1][@base='org.eolang.number' and not(@as)]/o[@base='org.eolang.bytes' and text()='40-3F-19-99-99-99-99-9A']
- //o[@base='.foo' and @name='xyz']/o[@as='α3' and @base='.some']/o[@base='.y' and @as='α0']/o[1][@base='Q']
- //o[@base='.foo' and @name='xyz']/o[@as='α3' and @base='.some']/o[@base='.y' and @as='α0']/o[@base='org.eolang.number' and @as='α0']/o[@base='org.eolang.bytes' and text()='40-26-00-00-00-00-00-00']
phi: |-
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
---
asserts:
- /program/objects/o[@base='.m' and @name='x']/o[@base='org.eolang.error']
- /program/objects/o[@base='org.eolang.error' and @name='y']/o[@as='0' and @base='.x']/o[@base='$']
- /program/objects/o[@base='org.eolang.error' and @name='y']/o[@as='α0' and @base='.x']/o[@base='$']
phi: |
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
---
asserts:
- //o[@name='test' and not(@base)]/o[@base='.plus' and @name='s']/o[position()=1 and not(@base) and not(@name)]
- //o[@name='test' and not(@base)]/o[@base='.plus' and @name='s']/o[position()>1 and @as='0' and @base='.int']/o[@base='.eolang']/o[@base='.org']/o[@base='Q']
- //o[@name='test' and not(@base)]/o[@base='.plus' and @name='s']/o[position()>1 and @as='α0' and @base='.int']/o[@base='.eolang']/o[@base='.org']/o[@base='Q']
phi: |-
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
---
asserts:
- //o[@name='five' and @base='.int']/o[@base='.eolang']
- //o[@name='five' and @base='.int']/o[@base='.bytes' and @as='0']
- //o[@name='five' and @base='.int']/o[@base='.bytes' and @as='α0']
phi: "{⟦five ↦ Φ.org.eolang.int(α0 ↦ Φ.org.eolang.bytes(α0 ↦ ⟦Δ ⤍ 00-00-00-00-00-00-00-05⟧))⟧}"
4 changes: 1 addition & 3 deletions eo-parser/src/main/java/org/eolang/parser/XeEoListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -1142,10 +1142,8 @@ public void enterAs(final EoParser.AsContext ctx) {
final String has;
if (ctx.NAME() != null) {
has = ctx.NAME().getText();
} else if (ctx.INT() != null) {
has = ctx.INT().getText();
} else {
has = "^";
has = String.format("α%s", ctx.INT().getText());
}
this.objects.prop("as", has);
}
Expand Down
8 changes: 3 additions & 5 deletions eo-parser/src/main/java/org/eolang/parser/XePhiListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,8 @@ public void enterAttribute(final PhiParser.AttributeContext ctx) {
attr = "@";
} else if (ctx.RHO() != null) {
attr = "^";
} else if (ctx.LABEL() != null) {
attr = ctx.LABEL().getText();
} else if (ctx.ALPHA() != null) {
attr = ctx.ALPHA().getText().substring(1);
} else if (ctx.LABEL() != null || ctx.ALPHA() != null) {
attr = ctx.getText();
} else {
attr = "";
}
Expand Down Expand Up @@ -335,7 +333,7 @@ public void enterJustObject(final PhiParser.JustObjectContext ctx) {
final int index = this.alphas.peek();
this.alphas.pop();
this.alphas.push(index + 1);
this.attributes.push(String.valueOf(index));
this.attributes.push(String.format("α%d", index));
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion eo-parser/src/main/resources/XMIR.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ SOFTWARE.
</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]+|@|[a-z][^ \n\t\r]*"/>
<xs:pattern value="α[0-9]+|@|[a-z][^ \n\t\r]*"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="fqn">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ SOFTWARE.
-->
<xsl:import href="/org/eolang/parser/_funcs.xsl"/>
<xsl:variable name="eol" select="'&#10;'"/>
<xsl:variable name="alpha" select="'α'"/>
<xsl:variable name="comment">
<xsl:text># No comments.</xsl:text>
<xsl:value-of select="$eol"/>
Expand Down Expand Up @@ -125,7 +126,14 @@ SOFTWARE.
<xsl:template match="o" mode="tail">
<xsl:if test="@as">
<xsl:text>:</xsl:text>
<xsl:value-of select="@as"/>
<xsl:choose>
<xsl:when test="starts-with(@as, $alpha)">
<xsl:value-of select="substring-after(@as, $alpha)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@as"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<xsl:if test="@name">
<xsl:text> &gt; </xsl:text>
Expand Down
10 changes: 9 additions & 1 deletion eo-parser/src/main/resources/org/eolang/parser/xmir-to-eo.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ SOFTWARE.
-->
<xsl:import href="/org/eolang/parser/_funcs.xsl"/>
<xsl:variable name="eol" select="'&#10;'"/>
<xsl:variable name="alpha" select="'α'"/>
<xsl:variable name="comment">
<xsl:text># No comments.</xsl:text>
<xsl:value-of select="$eol"/>
Expand Down Expand Up @@ -141,7 +142,14 @@ SOFTWARE.
<xsl:template match="o" mode="tail">
<xsl:if test="@as">
<xsl:text>:</xsl:text>
<xsl:value-of select="@as"/>
<xsl:choose>
<xsl:when test="starts-with(@as, $alpha)">
<xsl:value-of select="substring-after(@as, $alpha)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@as"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<xsl:if test="@name">
<xsl:text> &gt; </xsl:text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ asserts:
- //o[@base='string']
- //o[@name='hello' and @const]
- //o[@as='i']
- //o[@as='1']
- //o[@as='0']
- //o[@as='α1']
- //o[@as='α0']
- //o[@base='.five']
- //objects[not(.//o[@name=''])]
- //o[@atom and @name='atom' and count(o)=2 and o[@name='a']]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
sheets: [ ]
asserts:
- /program[not(errors)]
- //o[@base='.if' and o[@base='string' and @as='0']]
- //o[@base='.if' and o[@base='string' and @as='1']]
- //o[@base='.if' and o[@base='string' and @as='α0']]
- //o[@base='.if' and o[@base='string' and @as='α1']]
- //o[@base='.if' and o[@base='number' and @as='a']]
- //o[@base='.if' and o[@base='number' and @as='b']]
input: |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2024 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.
---
origin: |
sprintf
"Hello %d, %f":text
42:1
12.3:2
straight: |
sprintf
"Hello %d, %f":text
42:1
12.3:2
reversed: |
sprintf
"Hello %d, %f":text
42:1
12.3:2

0 comments on commit d5ab000

Please sign in to comment.