diff options
| author | Ben Culkin <scorpress@gmail.com> | 2020-12-03 19:15:49 -0500 |
|---|---|---|
| committer | Ben Culkin <scorpress@gmail.com> | 2020-12-03 19:15:49 -0500 |
| commit | ae54e5a84b418c4e4ee54fe5c5136107e4995803 (patch) | |
| tree | 6b2a7444faa46a30efca1ce1c961bfe66979fa01 | |
| parent | a85481412f803f4b70f43e46e87df1ed12e75b73 (diff) | |
Start new version of SCL
| -rw-r--r-- | src/main/java/bjc/dicelang/sclv2/SCLEngine.java | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/main/java/bjc/dicelang/sclv2/SCLEngine.java b/src/main/java/bjc/dicelang/sclv2/SCLEngine.java new file mode 100644 index 0000000..d557a9b --- /dev/null +++ b/src/main/java/bjc/dicelang/sclv2/SCLEngine.java @@ -0,0 +1,89 @@ +package bjc.dicelang.sclv2; + +import java.util.*; + +import bjc.esodata.*; + +/** + * Engine for running SCL. + * + * Not threadsafe. + * + * @author Ben Culkin + */ +public class SCLEngine +{ + private TapeLibrary<Deque<String>> streams; + private Deque<String> currentStream; + + private Map<String, Deque<String>> streamLibrary; + + private boolean inQuoteMode; + + /** + * Create a new SCL engine. + */ + public SCLEngine() + { + reinit(); + } + + /** + * Reinitialize this engine, as if it was newly constructed. + */ + public void reinit() + { + streams = new TapeLibrary<>(); + streams.setAllowAutoCreation(true); + streams.mountTape("default"); + + streamLibrary = new HashMap<>(); + + currentStream = new ArrayDeque<>(); + streams.item(currentStream); + + inQuoteMode = false; + } + + /** + * Run the engine on a given set of input. + * + * @param input + * The source of input to use. + * + * @return The stream that was active at the end of the input. + */ + public Deque<String> run(Iterator<String> input) + { + while (input.hasNext()) + { + String token = input.next(); + + if (inQuoteMode) + { + + if (token.equalsIgnoreCase("{@SQ}")) inQuoteMode = true; + else if (token.equalsIgnoreCase("{@SU}")) inQuoteMode = false; + else currentStream.add(token); + } else + { + if (token.startsWith("{@S") && token.endsWith("}")) + { + String[] commands = token.substring(3, token.length()).split(";"); + for (String command : commands) { + switch (command) + { + default: + // Unknown command; need to handle it + } + } + } else + { + currentStream.add(token); + } + } + } + + return currentStream; + } +}
\ No newline at end of file |
