Skip to content

Commit

Permalink
FEATURE: translation folders
Browse files Browse the repository at this point in the history
  • Loading branch information
egorklementev committed Mar 1, 2022
1 parent a257a21 commit 6250aee
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<br>

[![Gradle Build](https://github.com/polystat/j2eo/actions/workflows/gradle-build.yml/badge.svg)](https://github.com/polystat/j2eo/actions/workflows/gradle-build.yml)
![LINE](https://img.shields.io/badge/line--coverage-35,45%25-red.svg)
![BRANCH](https://img.shields.io/badge/branch--coverage-25,44%25-red.svg)
![COMPLEXITY](https://img.shields.io/badge/complexity-6,02-brightgreen.svg)
![LINE](https://img.shields.io/badge/line--coverage-41,67%25-orange.svg)
![BRANCH](https://img.shields.io/badge/branch--coverage-33,81%25-red.svg)
![COMPLEXITY](https://img.shields.io/badge/complexity-5,17-brightgreen.svg)

This is a translator of **Java** programming language to [EOLANG](https://www.eolang.org) programming language.

Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ set -e

echo "Building J2EO..."
./gradlew fatJar -x test
cp build/libs/J2EO-0.2.0.jar j2eo.jar
cp build/libs/* ./
echo "Build completed"
26 changes: 20 additions & 6 deletions src/main/java/main/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ import parser.JavaParser
import translator.Translator
import tree.Compilation.CompilationUnit
import tree.Entity
import util.logger
import java.io.File
import java.io.FileNotFoundException
import java.io.PrintWriter
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import kotlin.io.path.createDirectories
import kotlin.system.exitProcess

object Main {
Expand Down Expand Up @@ -98,11 +102,21 @@ object Main {

translatedFiles.forEach { (file, eoProgram) ->
val targetText = eoProgram.generateEO(0)
val outputPath = (cmd.getOptionValue("o") + "/" + file.path.replace(cmd.argList[0], ""))
.replace("//", "/").replace(".java", ".eo")
println("Printing output to file $outputPath")
File(outputPath.substringBeforeLast("/")).mkdirs()
PrintWriter(outputPath).use { writer -> writer.println(targetText) }
val outputPath = Paths.get(
cmd.getOptionValue('o'),
if (sourceFile.isDirectory)
file.parentFile.toRelativeString(File(cmd.args[0]))
else
file.toRelativeString(File(cmd.args[0]))
)
val outputFile = Paths.get(
outputPath.toString(),
file.name.replace(".java", ".eo")
)

println("Printing output to file $outputFile")
outputPath.createDirectories()
Files.writeString(Files.createFile(outputFile), targetText)
}

// Resource
Expand Down

0 comments on commit 6250aee

Please sign in to comment.