Skip to content

Commit

Permalink
#3585: parser clean
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Dec 2, 2024
1 parent 85429fe commit a23741d
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 9 deletions.
17 changes: 14 additions & 3 deletions eo-parser/src/main/java/org/eolang/parser/DrProgram.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ public Iterator<Directive> iterator() {
)
)
.add("program")
.attr("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
.attr("xsi:noNamespaceSchemaLocation", DrProgram.schema())
.attr(
"noNamespaceSchemaLocation xsi http://www.w3.org/2001/XMLSchema-instance",
DrProgram.schema()
)
.attr("name", this.name)
.attr("version", Manifests.read("EO-Version"))
.attr("revision", Manifests.read("EO-Revision"))
Expand All @@ -91,7 +93,16 @@ public Iterator<Directive> iterator() {

/**
* Find the location of XSD schema.
* @return The location of XSD schema
*
* <p>In production, the XSD is located online at the eolang.org
* website, were we deploy it on every release cycle (see the {@code .rultor.yml}
* file. However, during testing cycle, we must use the local file,
* allowing its most recent changes to be visible to the code. However,
* we don't know exactly where from the tests are being executed
* (what is the current directory). Because of this, we try to find the
* file using a number of options.</p>
*
* @return The location of the XSD schema file/URL
*/
private static String schema() {
String schema = String.format(
Expand Down
3 changes: 2 additions & 1 deletion eo-parser/src/main/java/org/eolang/parser/TrParsing.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public TrParsing() {
"/org/eolang/parser/add-default-package.xsl",
"/org/eolang/parser/explicit-data.xsl",
"/org/eolang/parser/const-to-dataized.xsl",
"/org/eolang/parser/set-locators.xsl"
"/org/eolang/parser/set-locators.xsl",
"/org/eolang/parser/clean-up.xsl"
).back()
),
TrParsing.class,
Expand Down
39 changes: 39 additions & 0 deletions eo-parser/src/main/resources/org/eolang/parser/clean-up.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" id="add-default-package" version="2.0">
<!--
Here, we remove all the temporary information XMIR
that doesn't match the requirements of XSD schema.
-->
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:template match="@ancestors | @original-name | @parent">
<!-- nothing -->
</xsl:template>
<xsl:template match="node()|@*" mode="#all">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ void parsesAndChecksSimpleCode() throws Exception {
).failures(),
Matchers.emptyIterable()
);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ xsls:
- /org/eolang/parser/optimize/abstracts-float-up.xsl
- /org/eolang/parser/optimize/remove-levels.xsl
- /org/eolang/parser/add-refs.xsl
- /org/eolang/parser/clean-up.xsl
tests:
- /program[count(.//o[@base='build' and not(@ref)])=2]
- /program/objects[count(o[@original-name='build'])=2]
eo: |
# This is the default 64+ symbols comment in front of abstract object.
[] > hello
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ xsls:
- /org/eolang/parser/optimize/abstracts-float-up.xsl
- /org/eolang/parser/optimize/remove-levels.xsl
- /org/eolang/parser/add-refs.xsl
- /org/eolang/parser/clean-up.xsl
tests:
- /program/objects[count(o)=9]
- /program[not(errors)]
Expand All @@ -33,7 +34,7 @@ tests:
- //o[@base='first$t2$native']
- //o[@name='first' and not(@ancestors)]
- //o[@name='first']/o[@base='test']
- //o[@name='first$t2$second' and @ancestors='1' and @parent='first']
- //o[@name='first$t2$second']
- //o[@name='first$t2$second$third']
- //o[@name='first$t2$second$third']/o[@base='stdout']/o[@base='a']
- //o[@line and @name='aa']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ xsls:
- /org/eolang/parser/optimize/remove-levels.xsl
- /org/eolang/parser/add-refs.xsl
- /org/eolang/parser/optimize/fix-missed-names.xsl
- /org/eolang/parser/clean-up.xsl
tests:
- //o[@base='first$second' and @line='6']
eo: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
xsls:
- /org/eolang/parser/add-refs.xsl
- /org/eolang/parser/optimize/abstracts-float-up.xsl
- /org/eolang/parser/clean-up.xsl
tests:
- /program[not(errors)]
- //o[@name='a$m$t2$a0' and @parent='a$m']
- //o[@name='a$m$t2$a0']
eo: |
# This is the default 64+ symbols comment in front of abstract object.
[] > a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
xsls:
- /org/eolang/parser/optimize/abstracts-float-up.xsl
- /org/eolang/parser/optimize/remove-levels.xsl
- /org/eolang/parser/clean-up.xsl
tests:
- /program[not(errors)]
# 'first' object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
xsls:
- /org/eolang/parser/optimize/abstracts-float-up.xsl
- /org/eolang/parser/optimize/remove-levels.xsl
- /org/eolang/parser/clean-up.xsl
tests:
- /program[not(errors)]
# 'main' object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
xsls:
- /org/eolang/parser/optimize/abstracts-float-up.xsl
- /org/eolang/parser/optimize/remove-levels.xsl
- /org/eolang/parser/clean-up.xsl
tests:
- /program[not(errors)]
# 'main' object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ xsls:
- /org/eolang/parser/wrap-method-calls.xsl
- /org/eolang/parser/optimize/abstracts-float-up.xsl
- /org/eolang/parser/optimize/remove-levels.xsl
- /org/eolang/parser/clean-up.xsl
tests:
- /program[not(errors)]
# 'main' object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
xsls:
- /org/eolang/parser/optimize/abstracts-float-up.xsl
- /org/eolang/parser/optimize/remove-levels.xsl
- /org/eolang/parser/clean-up.xsl
tests:
- /program[not(errors)]
# 'main' object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
xsls:
- /org/eolang/parser/optimize/abstracts-float-up.xsl
- /org/eolang/parser/optimize/remove-levels.xsl
- /org/eolang/parser/clean-up.xsl
tests:
- /program[not(errors)]
# 'another' object
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ SOFTWARE.
<dependency>
<groupId>com.jcabi.incubator</groupId>
<artifactId>xembly</artifactId>
<version>0.31.1</version>
<version>0.32.1</version>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
Expand Down

0 comments on commit a23741d

Please sign in to comment.