Skip to content

Commit

Permalink
Merge pull request #56 from Tetr4/stdio
Browse files Browse the repository at this point in the history
Clean up StdIO output
  • Loading branch information
Mike Klimek authored Dec 8, 2016
2 parents 4358024 + 1005841 commit 5508fcd
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions src/arden/runtime/StdIOExecutionContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
/** Reads and prints queries from/to StdIO. */
public class StdIOExecutionContext extends BaseExecutionContext {
private Scanner sc = new Scanner(System.in);
private boolean verbose;
private static final String PROMPT_SIGN = "> ";

public StdIOExecutionContext(CommandLineOptions options) {
super(options);
this.verbose = options.getVerbose();
}

@Override
public DatabaseQuery createQuery(MedicalLogicModule mlm, String mapping) {
System.out.println(
Expand Down Expand Up @@ -49,31 +51,39 @@ public DatabaseQuery createQuery(MedicalLogicModule mlm, String mapping) {

@Override
public ArdenValue getMessage(MedicalLogicModule mlm, String mapping) {
System.out.println("Message, mapping: " + mapping);
if (verbose) {
System.out.println("Message, mapping: " + mapping);
}
return new ArdenString(mapping);
}

@Override
public ArdenObject getMessageAs(MedicalLogicModule mlm, String mapping, ObjectType type) {
System.out.println("Message, mapping: " + mapping + ", type: " + type.name);
if (verbose) {
System.out.println("Message, mapping: " + mapping + ", type: " + type.name);
}
ArdenObject object = new ArdenObject(type);
if(object.fields.length > 0) {
if (object.fields.length > 0) {
object.fields[0] = new ArdenString(mapping);
}
return object;
}

@Override
public ArdenValue getDestination(MedicalLogicModule mlm, String mapping) {
System.out.println("Destination, mapping: " + mapping);
if (verbose) {
System.out.println("Destination, mapping: " + mapping);
}
return new ArdenString(mapping);
}

@Override
public ArdenObject getDestinationAs(MedicalLogicModule mlm, String mapping, ObjectType type) {
System.out.println("Destination, mapping: " + mapping + ", type: " + type.name);
if (verbose) {
System.out.println("Destination, mapping: " + mapping + ", type: " + type.name);
}
ArdenObject object = new ArdenObject(type);
if(object.fields.length > 0) {
if (object.fields.length > 0) {
object.fields[0] = new ArdenString(mapping);
}
return object;
Expand All @@ -82,18 +92,21 @@ public ArdenObject getDestinationAs(MedicalLogicModule mlm, String mapping, Obje
@Override
public void write(ArdenValue message, ArdenValue destination, double urgency) {
String destString = ArdenString.getStringFromValue(destination);
if (destString != null && "stdout".equalsIgnoreCase(destString)) {
if (destString != null && "stdout".equalsIgnoreCase(destString)) {
// just print string
if (message instanceof ArdenString) {
System.out.println(ArdenString.getStringFromValue(message));
} else {
System.out.println(message);
}
} else {
// prepend destination to printed string
System.out.print("Destination: ");
System.out.print(destination);
System.out.print(" Message: ");
if (destination != null) {
// prepend destination to printed string
System.out.print("Destination: ");
System.out.print(destination);
System.out.print(" ");
}
System.out.print("Message: ");
if (message instanceof ArdenString) {
System.out.println(ArdenString.getStringFromValue(message));
} else {
Expand Down

0 comments on commit 5508fcd

Please sign in to comment.