startRepl and runSerene method have been added

This commit is contained in:
Sameer Rahmani 2019-12-10 00:02:24 +00:00
parent 53b2cd7fdb
commit 53cd9560a3
4 changed files with 55 additions and 35 deletions

View File

@ -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'
}
}

View File

@ -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());
}
}

View File

@ -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<Node> nodes = Reader.read(inputStream);
...
}
}
private static void runSerene(String filePath) throws IOException {
Environment rootEnv = Environment.getBaseEnvironment();
ListNode<Node> nodes = Reader.read(new FileInputStream(filePath));
for (Node n : nodes) {
n.eval(rootEnv);
}
}
}

View File

@ -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();
}
}