summaryrefslogtreecommitdiff
path: root/dice-lang/src/bjc/dicelang/scl/StreamControlConsole.java
blob: 8ace8ad9ecb5e134e6f2650875327dbd11d6cf42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package bjc.dicelang.scl;

import bjc.utils.funcdata.FunctionalList;
import bjc.utils.funcdata.IList;

import java.util.Iterator;
import java.util.Scanner;

import java.util.function.Supplier;

public class StreamControlConsole {
	public static void main(String[] args) {
		/* Initialize vars. */
		/* We're not using the DiceLangEngine in the streams yet. */
		StreamEngine sengine = new StreamEngine(null);
		StreamControlEngine sclengine = new StreamControlEngine(sengine);
		Scanner scn = new Scanner(System.in);

		/* Get input from the user. */
		System.out.print("Enter a SCL command string (blank to exit): ");

		while (scn.hasNextLine()) {
			String ln = scn.nextLine();

			if (ln.trim().equals("")) {
				break;
			}

			/* Break the token into strings. */
			IList<String> res = new FunctionalList<>();
			String[] tokens   = ln.split(" ");

			/* Run the stream engine on the tokens. */
			boolean succ = sengine.doStreams(tokens, res);

			if (!succ) {
				continue;
			}

			/* Run the command through SCL. */
			tokens = res.toArray(new String[res.getSize()]);
			succ   = sclengine.runProgram(tokens);

			if (!succ) {
				continue;
			}

			/* Prompt again. */
			System.out.print("Command string executed succesfully.\n\n");
			System.out.print("Enter a SCL command string (blank to exit): ");
		}
	}
}