Skip to content

Commit

Permalink
#157: clean
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Nov 15, 2020
1 parent cc1506b commit 39b20e1
Show file tree
Hide file tree
Showing 24 changed files with 499 additions and 47 deletions.
3 changes: 3 additions & 0 deletions eo-compiler/src/main/antlr4/org/eolang/compiler/Program.g4
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ has

data
:
BOOL
|
STRING
|
INTEGER
Expand Down Expand Up @@ -210,6 +212,7 @@ EOL

NAME: LO (LETTER | DIGIT)*;

BOOL: 'true' | 'false';
CHAR: '\'' (LETTER | DIGIT) '\'';
STRING: '"' ('\\"' | ~'"')* '"';
INTEGER: (PLUS | MINUS)? DIGIT+;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@ public void exitHtail(final ProgramParser.HtailContext ctx) {
public void enterData(final ProgramParser.DataContext ctx) {
final String type;
final String data;
if (ctx.CHAR() != null) {
if (ctx.BOOL() != null) {
type = "bool";
data = Boolean.toString(Boolean.parseBoolean(ctx.getText()));
} else if (ctx.CHAR() != null) {
type = "char";
data = ctx.getText().substring(1, 1);
} else if (ctx.FLOAT() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ eo: |
[x] > first
second > hello
third:foo > x
f 12
(((t 22) r:t 8.54 "yes").print 88):hey > !a
f 12 false
(((t 22) r:t 8.54 "yes" 'e').print 88):hey true > !a
kid
f:u
z
Expand Down
2 changes: 2 additions & 0 deletions eo-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ SOFTWARE.
<artifactId>qulice-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>checkstyle:/src/it/.*</exclude>
<exclude>pmd:/src/it/.*</exclude>
<exclude>duplicatefinder:.*</exclude>
<exclude>xml:/src/test/resources/META-INF/maven/plugin.xml</exclude>
</excludes>
Expand Down
1 change: 1 addition & 0 deletions eo-maven-plugin/src/it/fibonacci/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals = clean
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

package org.eolang.examples;

import org.eolang.Array;
import java.util.Arrays;
import org.eolang.ArgsOf;
import org.eolang.Entry;

/**
* Eo entry point.
Expand All @@ -39,7 +41,11 @@ public final class Main {
* @throws Exception In case of failure
*/
public static void main(final String... args) throws Exception {
new app(new Array(args)).call();
new app(
new ArgsOf(
new Entry("args", Arrays.asList(args))
)
).call();
}

}
28 changes: 28 additions & 0 deletions eo-maven-plugin/src/it/fibonacci/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2020 Yegor Bugayenko
*
* 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.
*/

// assert new File(basedir, 'target/generated-sources/eo/pixel.java').exists()
// assert new File(basedir, 'target/generated-sources/eo/pixel$hello.java').exists()
// assert new File(basedir, 'target/classes/pixel.class').exists()
// assert new File(basedir, 'target/classes/pixel$hello.class').exists()
26 changes: 13 additions & 13 deletions eo-maven-plugin/src/main/java/org/eolang/maven/CompileMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public final class CompileMojo extends AbstractMojo {
readonly = false,
defaultValue = "${project.build.directory}/generated-sources/eo"
)
private transient File generatedDirectory;
private transient File generatedDir;

/**
* Target directory.
Expand All @@ -87,7 +87,7 @@ public final class CompileMojo extends AbstractMojo {
readonly = false,
defaultValue = "${project.build.directory}"
)
private transient File targetDirectory;
private transient File targetDir;

/**
* Directory in which .eo files are located.
Expand All @@ -103,11 +103,11 @@ public final class CompileMojo extends AbstractMojo {
@Override
public void execute() throws MojoFailureException {
StaticLoggerBinder.getSingleton().setMavenLog(this.getLog());
if (this.generatedDirectory.mkdirs()) {
Logger.info(this, "Directory created: %s", this.generatedDirectory);
if (this.generatedDir.mkdirs()) {
Logger.info(this, "Gen directory created: %s", this.generatedDir);
}
if (this.targetDirectory.mkdirs()) {
Logger.info(this, "Directory created: %s", this.targetDirectory);
if (this.targetDir.mkdirs()) {
Logger.info(this, "Target directory created: %s", this.targetDir);
}
try {
Files.walk(this.sourcesDirectory.toPath())
Expand All @@ -125,11 +125,11 @@ public void execute() throws MojoFailureException {
);
}
this.project.addCompileSourceRoot(
this.generatedDirectory.getAbsolutePath()
this.generatedDir.getAbsolutePath()
);
Logger.info(
this, "Directory added to sources: %s",
this.generatedDirectory
this.generatedDir
);
}

Expand All @@ -152,7 +152,7 @@ private void compile(final Path file) {
new TeeInput(
new InputOf(baos.toString()),
new OutputTo(
this.targetDirectory.toPath()
this.targetDir.toPath()
.resolve("eo-compiler")
.resolve(
String.format(
Expand All @@ -166,21 +166,21 @@ private void compile(final Path file) {
).value();
new ToJava(
new XMLDocument(baos.toString()),
this.generatedDirectory.toPath(),
this.targetDirectory.toPath().resolve("eo-to-java")
this.generatedDir.toPath(),
this.targetDir.toPath().resolve("eo-to-java")
).compile();
} catch (final IOException ex) {
throw new IllegalStateException(
new UncheckedText(
new FormattedText(
"Can't compile %s into %s",
file, this.generatedDirectory
file, this.generatedDir
)
).asString(),
ex
);
}
Logger.info(this, "%s compiled to %s", file, this.generatedDirectory);
Logger.info(this, "%s compiled to %s", file, this.generatedDir);
}

}
1 change: 1 addition & 0 deletions eo-maven-plugin/src/main/java/org/eolang/maven/ToJava.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public final class ToJava {
*
* @param input Input text
* @param file The file to write the XML to
* @param tmp Temp dir
*/
public ToJava(final XML input, final Path file, final Path tmp) {
this.xml = input;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ SOFTWARE.
<xsl:value-of select="text()"/>
<xsl:text>'</xsl:text>
</xsl:template>
<xsl:template match="o[text() and @base='org.eolang.Bool']">
<xsl:value-of select="text()"/>
</xsl:template>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ public void testSimpleCompilation() throws Exception {
).value();
final Path target = this.temp.resolve("target");
this.setVariableValueToObject(
mojo, "targetDirectory", target.toFile()
mojo, "targetDir", target.toFile()
);
final Path generated = this.temp.resolve("generated");
this.setVariableValueToObject(
mojo, "generatedDirectory", generated.toFile()
mojo, "generatedDir", generated.toFile()
);
this.setVariableValueToObject(mojo, "project", new MavenProjectStub());
mojo.execute();
Expand All @@ -88,10 +88,10 @@ public void testCrashOnInvalidSyntax() throws Exception {
final Path src = this.temp.resolve("src");
this.setVariableValueToObject(mojo, "sourcesDirectory", src.toFile());
this.setVariableValueToObject(
mojo, "generatedDirectory", this.temp.resolve("generated").toFile()
mojo, "generatedDir", this.temp.resolve("generated").toFile()
);
this.setVariableValueToObject(
mojo, "targetDirectory", this.temp.resolve("target").toFile()
mojo, "targetDir", this.temp.resolve("target").toFile()
);
new LengthOf(
new TeeInput(
Expand Down
18 changes: 18 additions & 0 deletions eo-runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,22 @@ SOFTWARE.
<artifactId>cactoos</artifactId>
</dependency>
</dependencies>
<!--
<build>
<plugins>
<plugin>
<groupId>org.eolang</groupId>
<artifactId>eo-maven-plugin</artifactId>
<version>0.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
-->
</project>
6 changes: 6 additions & 0 deletions eo-runtime/src/main/eo/org/eolang/not.eo
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Returns TRUE if argument is FALSE and the other way around

+package org.eolang

[x] > not
if x false true
8 changes: 8 additions & 0 deletions eo-runtime/src/main/eo/org/eolang/sub.eo
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Calculates algebraic difference between x and y

+package org.eolang

[x y] > sub
add
x
mul y -1
5 changes: 5 additions & 0 deletions eo-runtime/src/main/java/org/eolang/Add.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ public Object call() {
}
}
}
if (result == null) {
throw new ArgsException(
"At least one argument required by ADD"
);
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,23 @@
package org.eolang;

/**
* NOT.
* Args Exception.
*
* @since 0.1
*/
public final class Not implements Phi {
public final class ArgsException extends RuntimeException {

/**
* Args.
* Serial ID.
*/
private final Args args;
private static final long serialVersionUID = -6643350804302660951L;

/**
* Ctor.
* @param arg Args
* @param reason The reason
*/
public Not(final Args arg) {
this.args = arg;
public ArgsException(final String reason) {
super(reason);
}

@Override
public Object call() {
return !this.args.get("01").equals(Boolean.TRUE);
}
}
8 changes: 7 additions & 1 deletion eo-runtime/src/main/java/org/eolang/ArgsOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ private ArgsOf(final Map<String, Object> args) {

@Override
public Object get(final String key) {
return this.map.get(key);
final Object result = this.map.get(key);
if (result == null) {
throw new ArgsException(
String.format("The argument \"%s\" is absent", key)
);
}
return result;
}

@Override
Expand Down
57 changes: 57 additions & 0 deletions eo-runtime/src/main/java/org/eolang/If.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2020 Yegor Bugayenko
*
* 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.
*/

package org.eolang;

/**
* IF.
*
* @since 0.2
*/
public final class If implements Phi {

/**
* Args.
*/
private final Args args;

/**
* Ctor.
* @param arg Args
*/
public If(final Args arg) {
this.args = arg;
}

@Override
public Object call() {
Object result = false;
if (this.args.get("01").equals(Boolean.TRUE)) {
result = this.args.get("02");
} else if (this.args.has("03")) {
result = this.args.get("03");
}
return result;
}
}
Loading

0 comments on commit 39b20e1

Please sign in to comment.