Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6bff264

Browse files
committed
fix(#2758): xmir
1 parent ba51a0d commit 6bff264

File tree

11 files changed

+316
-116
lines changed

11 files changed

+316
-116
lines changed

eo-maven-plugin/src/main/java/org/eolang/maven/PrintMojo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.eolang.maven.util.Home;
4040
import org.eolang.maven.util.Walk;
4141
import org.eolang.parser.XMIR;
42+
import org.eolang.parser.xmir.Xmir;
4243

4344
/**
4445
* Print XMIR to EO.
@@ -84,7 +85,7 @@ void exec() throws IOException {
8485
this.printSourcesDir.toPath().relativize(source).toString()
8586
.replace(".xmir", ".eo")
8687
);
87-
home.save(new XMIR(new TextOf(source)).toEO(), relative);
88+
home.save(new Xmir(new TextOf(source)).toEO(), relative);
8889
Logger.info(
8990
this,
9091
"Printed: %s => %s", source, this.printOutputDir.toPath().resolve(relative)

eo-parser/src/main/java/org/eolang/parser/StEoLogged.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.jcabi.xml.XML;
2828
import com.yegor256.xsline.Shift;
2929
import java.util.function.Consumer;
30+
import org.eolang.parser.xmir.Xmir;
3031

3132
/**
3233
* Shift that logs the EO representation of the XML before throwing an exception.
@@ -78,7 +79,7 @@ public XML apply(final int position, final XML xml) {
7879
this.logger.accept(
7980
String.format(
8081
"Eo representation of the parsed xml: %n%s",
81-
new XMIR(xml).toEO()
82+
new Xmir.Default(xml).toEO()
8283
)
8384
);
8485
throw new IllegalStateException(

eo-parser/src/main/java/org/eolang/parser/XMIR.java

Lines changed: 0 additions & 111 deletions
This file was deleted.

eo-parser/src/main/java/org/eolang/parser/XeEoListener.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.commons.text.StringEscapeUtils;
3838
import org.cactoos.iterable.Mapped;
3939
import org.cactoos.text.Joined;
40+
import org.eolang.parser.xmir.XmirInfo;
4041
import org.xembly.Directive;
4142
import org.xembly.Directives;
4243

eo-parser/src/main/java/org/eolang/parser/XePhiListener.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.antlr.v4.runtime.tree.ErrorNode;
3737
import org.antlr.v4.runtime.tree.TerminalNode;
3838
import org.cactoos.list.ListOf;
39+
import org.eolang.parser.xmir.XmirInfo;
3940
import org.xembly.Directive;
4041
import org.xembly.Directives;
4142

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2016-2023 Objectionary.com
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included
14+
* in all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package org.eolang.parser.xmir;
25+
26+
import com.jcabi.xml.XML;
27+
import com.jcabi.xml.XMLDocument;
28+
import com.yegor256.xsline.TrClasspath;
29+
import com.yegor256.xsline.TrDefault;
30+
import com.yegor256.xsline.TrJoined;
31+
import com.yegor256.xsline.Xsline;
32+
import org.cactoos.Text;
33+
import org.cactoos.scalar.Unchecked;
34+
import org.eolang.parser.StUnhex;
35+
36+
/**
37+
* Prints XMIR to EO.
38+
*
39+
* @since 0.35.0
40+
*/
41+
public interface Xmir {
42+
/**
43+
* Converts XMIR to EO.
44+
* @return EO representation as {@code String}
45+
*/
46+
String toEO();
47+
48+
/**
49+
* Default Xmir that prints EO with strait vertical methods.
50+
*
51+
* This class will help you turn XMIR (XML document) into EOLANG
52+
* plain text source code. It's as simple as this:
53+
*
54+
* <pre> String eo = new Xmir.Default(xml).toEO();</pre>
55+
*
56+
* Here, the {@code xml} is a {@code String} or an instance
57+
* of {@code XML} from the jcabi-xml package.
58+
* @link <a href="https://xml.jcabi.com">xml.jcabi.com</a>
59+
* @since 0.35.5
60+
*/
61+
final class Default implements Xmir {
62+
/**
63+
* Wrap method calls XSL.
64+
*/
65+
private static final String WRAP = "/org/eolang/parser/wrap-method-calls.xsl";
66+
67+
/**
68+
* Default xmir-to-eo XSL transformation.
69+
*/
70+
private static final String TO_EO = "/org/eolang/parser/xmir-to-eo.xsl";
71+
72+
/**
73+
* The XML content.
74+
*/
75+
private final Unchecked<String> content;
76+
77+
/**
78+
* XSL transformation sheets.
79+
*/
80+
private final String[] sheets;
81+
82+
/**
83+
* Ctor.
84+
* @param src The source
85+
*/
86+
public Default(final String src) {
87+
this(new XMLDocument(src));
88+
}
89+
90+
/**
91+
* Ctor.
92+
* @param src The source
93+
*/
94+
public Default(final Text src) {
95+
this(new Unchecked<>(src::asString), Xmir.Default.TO_EO);
96+
}
97+
98+
/**
99+
* Ctor.
100+
* @param src The source
101+
* @param xsl To-EO transformation
102+
*/
103+
public Default(final Text src, final String xsl) {
104+
this(new Unchecked<>(src::asString), xsl);
105+
}
106+
107+
/**
108+
* Ctor.
109+
* @param src The source
110+
*/
111+
public Default(final XML src, final String xsl) {
112+
this(new Unchecked<>(src::toString), xsl);
113+
}
114+
115+
/**
116+
* Ctor.
117+
* @param src The source
118+
*/
119+
public Default(final XML src) {
120+
this(new Unchecked<>(src::toString), Xmir.Default.TO_EO);
121+
}
122+
123+
/**
124+
* Ctor.
125+
* @param src The source
126+
* @param xsl To-EO transformation
127+
*/
128+
Default(final Unchecked<String> src, final String xsl) {
129+
this(src, new String[] { Xmir.Default.WRAP, xsl });
130+
}
131+
132+
/**
133+
* Ctor.
134+
* @param src The source
135+
*/
136+
private Default(final Unchecked<String> src, final String[] sheets) {
137+
this.content = src;
138+
this.sheets = sheets;
139+
}
140+
141+
@Override
142+
public String toEO() {
143+
return new Xsline(
144+
new TrJoined<>(
145+
new TrDefault<>(new StUnhex()),
146+
new TrClasspath<>(this.sheets).back()
147+
)
148+
)
149+
.pass(new XMLDocument(this.content.value()))
150+
.xpath("eo/text()")
151+
.get(0);
152+
}
153+
}
154+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2016-2023 Objectionary.com
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included
14+
* in all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package org.eolang.parser.xmir;
25+
26+
/**
27+
* Envelope for {@link Xmir}.
28+
* @since 0.35.0
29+
*/
30+
class XmirEnvelope implements Xmir {
31+
/**
32+
* Original XMIR.
33+
*/
34+
private final Xmir origin;
35+
36+
/**
37+
* Ctor.
38+
* @param xmir Original XMIR
39+
*/
40+
XmirEnvelope(final Xmir xmir) {
41+
this.origin = xmir;
42+
}
43+
44+
@Override
45+
public String toEO() {
46+
return this.origin.toEO();
47+
}
48+
}

eo-parser/src/main/java/org/eolang/parser/XmirInfo.java renamed to eo-parser/src/main/java/org/eolang/parser/xmir/XmirInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24-
package org.eolang.parser;
24+
package org.eolang.parser.xmir;
2525

2626
/**
2727
* Info about XMIR.

0 commit comments

Comments
 (0)