From d5ab00079e008d5c8ab17eacfa5b81822c2d24e3 Mon Sep 17 00:00:00 2001 From: maxonfjvipon Date: Sun, 8 Dec 2024 23:55:28 +0300 Subject: [PATCH] fix(#3569): prohibit numbers in attribute-name in XSD --- .../resources/org/eolang/maven/phi/to-phi.xsl | 48 ++++++++++--------- .../org/eolang/maven/pre/to-java.xsl | 7 ++- .../eolang/maven/unphi/normalize-bytes.xsl | 2 +- .../org/eolang/maven/unphi/wrap-bytes.xsl | 2 +- .../org/eolang/maven/phi/yaml/bindings.yaml | 4 +- .../maven/phi/yaml/inline-bindings.yaml | 33 +++++++++++++ .../org/eolang/maven/unphi/bindings.yaml | 4 +- .../maven/unphi/inline-application.yaml | 14 +++--- .../maven/unphi/termination-with-tail.yaml | 2 +- .../maven/unphi/with-anonym-abstract.yaml | 2 +- .../org/eolang/maven/unphi/with-data.yaml | 2 +- .../java/org/eolang/parser/XeEoListener.java | 4 +- .../java/org/eolang/parser/XePhiListener.java | 8 ++-- eo-parser/src/main/resources/XMIR.xsd | 2 +- .../org/eolang/parser/xmir-to-eo-reversed.xsl | 10 +++- .../org/eolang/parser/xmir-to-eo.xsl | 10 +++- .../org/eolang/parser/packs/full-syntax.yaml | 4 +- .../syntax/bound-reversed-application.yaml | 4 +- .../parser/samples/explicit-bindings.yaml | 39 +++++++++++++++ 19 files changed, 146 insertions(+), 55 deletions(-) create mode 100644 eo-maven-plugin/src/test/resources/org/eolang/maven/phi/yaml/inline-bindings.yaml create mode 100644 eo-parser/src/test/resources/org/eolang/parser/samples/explicit-bindings.yaml diff --git a/eo-maven-plugin/src/main/resources/org/eolang/maven/phi/to-phi.xsl b/eo-maven-plugin/src/main/resources/org/eolang/maven/phi/to-phi.xsl index 95f79fc28d..ed66e29d96 100644 --- a/eo-maven-plugin/src/main/resources/org/eolang/maven/phi/to-phi.xsl +++ b/eo-maven-plugin/src/main/resources/org/eolang/maven/phi/to-phi.xsl @@ -27,9 +27,7 @@ SOFTWARE. - - - + @@ -214,6 +212,28 @@ SOFTWARE. + + + + + + + + + + + + + + + + + + + + @@ -453,8 +456,8 @@ SOFTWARE. - - + + " diff --git a/eo-maven-plugin/src/main/resources/org/eolang/maven/unphi/normalize-bytes.xsl b/eo-maven-plugin/src/main/resources/org/eolang/maven/unphi/normalize-bytes.xsl index 19c08d4ede..16b868cb6b 100644 --- a/eo-maven-plugin/src/main/resources/org/eolang/maven/unphi/normalize-bytes.xsl +++ b/eo-maven-plugin/src/main/resources/org/eolang/maven/unphi/normalize-bytes.xsl @@ -35,7 +35,7 @@ SOFTWARE. --> - + diff --git a/eo-maven-plugin/src/main/resources/org/eolang/maven/unphi/wrap-bytes.xsl b/eo-maven-plugin/src/main/resources/org/eolang/maven/unphi/wrap-bytes.xsl index 4c99409d76..44b8c3672b 100644 --- a/eo-maven-plugin/src/main/resources/org/eolang/maven/unphi/wrap-bytes.xsl +++ b/eo-maven-plugin/src/main/resources/org/eolang/maven/unphi/wrap-bytes.xsl @@ -36,7 +36,7 @@ SOFTWARE. org.eolang.bytes - + diff --git a/eo-maven-plugin/src/test/resources/org/eolang/maven/phi/yaml/bindings.yaml b/eo-maven-plugin/src/test/resources/org/eolang/maven/phi/yaml/bindings.yaml index 6c5958e205..33f2c29bf2 100644 --- a/eo-maven-plugin/src/test/resources/org/eolang/maven/phi/yaml/bindings.yaml +++ b/eo-maven-plugin/src/test/resources/org/eolang/maven/phi/yaml/bindings.yaml @@ -26,6 +26,7 @@ input: | [z]:abs w > @ 5:five + "hello":3 phi: |- { ⟦ @@ -35,7 +36,8 @@ phi: |- z ↦ ∅, φ ↦ Φ̇.w ⟧, - five ↦ 5 + five ↦ 5, + α3 ↦ "hello" ) ⟧ } diff --git a/eo-maven-plugin/src/test/resources/org/eolang/maven/phi/yaml/inline-bindings.yaml b/eo-maven-plugin/src/test/resources/org/eolang/maven/phi/yaml/inline-bindings.yaml new file mode 100644 index 0000000000..d324a8290e --- /dev/null +++ b/eo-maven-plugin/src/test/resources/org/eolang/maven/phi/yaml/inline-bindings.yaml @@ -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") + ⟧ + } diff --git a/eo-maven-plugin/src/test/resources/org/eolang/maven/unphi/bindings.yaml b/eo-maven-plugin/src/test/resources/org/eolang/maven/unphi/bindings.yaml index 93f52ddd3f..4a86fb4d74 100644 --- a/eo-maven-plugin/src/test/resources/org/eolang/maven/unphi/bindings.yaml +++ b/eo-maven-plugin/src/test/resources/org/eolang/maven/unphi/bindings.yaml @@ -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: |- { ⟦ diff --git a/eo-maven-plugin/src/test/resources/org/eolang/maven/unphi/inline-application.yaml b/eo-maven-plugin/src/test/resources/org/eolang/maven/unphi/inline-application.yaml index 09d81984ce..2ab97c9b4e 100644 --- a/eo-maven-plugin/src/test/resources/org/eolang/maven/unphi/inline-application.yaml +++ b/eo-maven-plugin/src/test/resources/org/eolang/maven/unphi/inline-application.yaml @@ -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: |- { ⟦ diff --git a/eo-maven-plugin/src/test/resources/org/eolang/maven/unphi/termination-with-tail.yaml b/eo-maven-plugin/src/test/resources/org/eolang/maven/unphi/termination-with-tail.yaml index 215b4f8135..724712c02d 100644 --- a/eo-maven-plugin/src/test/resources/org/eolang/maven/unphi/termination-with-tail.yaml +++ b/eo-maven-plugin/src/test/resources/org/eolang/maven/unphi/termination-with-tail.yaml @@ -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: | { ⟦ diff --git a/eo-maven-plugin/src/test/resources/org/eolang/maven/unphi/with-anonym-abstract.yaml b/eo-maven-plugin/src/test/resources/org/eolang/maven/unphi/with-anonym-abstract.yaml index ae32135081..6fb5f7048d 100644 --- a/eo-maven-plugin/src/test/resources/org/eolang/maven/unphi/with-anonym-abstract.yaml +++ b/eo-maven-plugin/src/test/resources/org/eolang/maven/unphi/with-anonym-abstract.yaml @@ -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: |- { ⟦ diff --git a/eo-maven-plugin/src/test/resources/org/eolang/maven/unphi/with-data.yaml b/eo-maven-plugin/src/test/resources/org/eolang/maven/unphi/with-data.yaml index 12dc8cba56..309df70268 100644 --- a/eo-maven-plugin/src/test/resources/org/eolang/maven/unphi/with-data.yaml +++ b/eo-maven-plugin/src/test/resources/org/eolang/maven/unphi/with-data.yaml @@ -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⟧))⟧}" diff --git a/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java b/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java index 907913093c..d80d91974f 100644 --- a/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java +++ b/eo-parser/src/main/java/org/eolang/parser/XeEoListener.java @@ -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); } diff --git a/eo-parser/src/main/java/org/eolang/parser/XePhiListener.java b/eo-parser/src/main/java/org/eolang/parser/XePhiListener.java index 8c60f92aae..249f632e2f 100644 --- a/eo-parser/src/main/java/org/eolang/parser/XePhiListener.java +++ b/eo-parser/src/main/java/org/eolang/parser/XePhiListener.java @@ -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 = ""; } @@ -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 diff --git a/eo-parser/src/main/resources/XMIR.xsd b/eo-parser/src/main/resources/XMIR.xsd index 8096ca8842..592eef3120 100644 --- a/eo-parser/src/main/resources/XMIR.xsd +++ b/eo-parser/src/main/resources/XMIR.xsd @@ -83,7 +83,7 @@ SOFTWARE. - + diff --git a/eo-parser/src/main/resources/org/eolang/parser/xmir-to-eo-reversed.xsl b/eo-parser/src/main/resources/org/eolang/parser/xmir-to-eo-reversed.xsl index 797660259b..99f36c1967 100644 --- a/eo-parser/src/main/resources/org/eolang/parser/xmir-to-eo-reversed.xsl +++ b/eo-parser/src/main/resources/org/eolang/parser/xmir-to-eo-reversed.xsl @@ -29,6 +29,7 @@ SOFTWARE. --> + # No comments. @@ -125,7 +126,14 @@ SOFTWARE. : - + + + + + + + + > diff --git a/eo-parser/src/main/resources/org/eolang/parser/xmir-to-eo.xsl b/eo-parser/src/main/resources/org/eolang/parser/xmir-to-eo.xsl index 05479efa6c..6249751de5 100644 --- a/eo-parser/src/main/resources/org/eolang/parser/xmir-to-eo.xsl +++ b/eo-parser/src/main/resources/org/eolang/parser/xmir-to-eo.xsl @@ -29,6 +29,7 @@ SOFTWARE. --> + # No comments. @@ -141,7 +142,14 @@ SOFTWARE. : - + + + + + + + + > diff --git a/eo-parser/src/test/resources/org/eolang/parser/packs/full-syntax.yaml b/eo-parser/src/test/resources/org/eolang/parser/packs/full-syntax.yaml index 0ec8e22959..224e8a5d7e 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/packs/full-syntax.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/packs/full-syntax.yaml @@ -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']] diff --git a/eo-parser/src/test/resources/org/eolang/parser/packs/syntax/bound-reversed-application.yaml b/eo-parser/src/test/resources/org/eolang/parser/packs/syntax/bound-reversed-application.yaml index 0f3d25fba0..7624d2a118 100644 --- a/eo-parser/src/test/resources/org/eolang/parser/packs/syntax/bound-reversed-application.yaml +++ b/eo-parser/src/test/resources/org/eolang/parser/packs/syntax/bound-reversed-application.yaml @@ -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: | diff --git a/eo-parser/src/test/resources/org/eolang/parser/samples/explicit-bindings.yaml b/eo-parser/src/test/resources/org/eolang/parser/samples/explicit-bindings.yaml new file mode 100644 index 0000000000..bf1328917d --- /dev/null +++ b/eo-parser/src/test/resources/org/eolang/parser/samples/explicit-bindings.yaml @@ -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