diff --git a/build.gradle b/build.gradle index 8b113a8..c6bd69c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,34 +1,23 @@ -/* - * This file was generated by the Gradle 'init' task. - * - * This generated file contains a sample Java project to get you started. - * For more details take a look at the Java Quickstart chapter in the Gradle - * User Manual available at https://docs.gradle.org/6.0.1/userguide/tutorial_java_projects.html - */ - plugins { - // Apply the java plugin to add support for Java id 'java' - - // Apply the application plugin to add support for building a CLI application. id 'application' } repositories { - // Use jcenter for resolving dependencies. - // You can declare any Maven/Ivy/file repository here. jcenter() } dependencies { - // This dependency is used by the application. implementation 'com.google.guava:guava:28.0-jre' - - // Use JUnit test framework testImplementation 'junit:junit:4.12' } application { - // Define the main class for the application. - mainClassName = 'serene.simple.App' + mainClassName = 'serene.simple.Main' +} + +jar { + manifest { + attributes 'Main-Class': 'serene.simple.Main' + } } diff --git a/src/main/java/serene/simple/App.java b/src/main/java/serene/simple/App.java deleted file mode 100644 index c83116c..0000000 --- a/src/main/java/serene/simple/App.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * This Java source file was generated by the Gradle 'init' task. - */ -package serene.simple; - -public class App { - public String getGreeting() { - return "Hello world."; - } - - public static void main(String[] args) { - System.out.println(new App().getGreeting()); - } -} diff --git a/src/main/java/serene/simple/Main.java b/src/main/java/serene/simple/Main.java new file mode 100644 index 0000000..bfbcfff --- /dev/null +++ b/src/main/java/serene/simple/Main.java @@ -0,0 +1,46 @@ +/* + * This Java source file was generated by the Gradle 'init' task. + */ +package serene.simple; + +import java.io.IOException; +import java.io.ByteArrayInputStream; +import java.io.Console; +import java.io.FileInputStream; + + +public class Main { + public static void main(String[] args) throws IOException { + if (args.length == 0) { + startRepl(); + } + runSerene(args[0]); + } + + private static void startRepl() { + Environment rootEnv = Environment.getBaseEnvironment(); + + Console console = System.console(); + + while(true) { + String inputData = console.readLine("serene-> "); + + if (expr == null) break; + + ByteArrayInputStream inputStream = new ByteArrayInputStream(inputData.getBytes()); + ListNode nodes = Reader.read(inputStream); + ... + } + + } + + private static void runSerene(String filePath) throws IOException { + Environment rootEnv = Environment.getBaseEnvironment(); + + ListNode nodes = Reader.read(new FileInputStream(filePath)); + + for (Node n : nodes) { + n.eval(rootEnv); + } + } +} diff --git a/src/test/java/serene/simple/AppTest.java b/src/test/java/serene/simple/MainTest.java similarity index 58% rename from src/test/java/serene/simple/AppTest.java rename to src/test/java/serene/simple/MainTest.java index d2bcdf4..1b419ea 100644 --- a/src/test/java/serene/simple/AppTest.java +++ b/src/test/java/serene/simple/MainTest.java @@ -6,9 +6,8 @@ package serene.simple; import org.junit.Test; import static org.junit.Assert.*; -public class AppTest { +public class MainTest { @Test public void testAppHasAGreeting() { - App classUnderTest = new App(); - assertNotNull("app should have a greeting", classUnderTest.getGreeting()); + Main classUnderTest = new Main(); } }