summaryrefslogtreecommitdiff
path: root/dice-lang/src/bjc/dicelang/StreamEngine.java
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2017-03-06 14:15:03 -0500
committerbculkin2442 <bjculkin@mix.wvu.edu>2017-03-06 14:15:03 -0500
commit9139064c95f6c9c4f7ba1d0aea21e2f5233ad188 (patch)
treedd93017bff73e61fec20c58b7baa43d1662c0c5b /dice-lang/src/bjc/dicelang/StreamEngine.java
parentb11f8d2c92aaaf1160e69190559ffadc4774f138 (diff)
Formatting/Documentation
Diffstat (limited to 'dice-lang/src/bjc/dicelang/StreamEngine.java')
-rw-r--r--dice-lang/src/bjc/dicelang/StreamEngine.java134
1 files changed, 95 insertions, 39 deletions
diff --git a/dice-lang/src/bjc/dicelang/StreamEngine.java b/dice-lang/src/bjc/dicelang/StreamEngine.java
index 2971392..5debe00 100644
--- a/dice-lang/src/bjc/dicelang/StreamEngine.java
+++ b/dice-lang/src/bjc/dicelang/StreamEngine.java
@@ -8,37 +8,93 @@ import static bjc.dicelang.Errors.ErrorKey.*;
import bjc.utils.esodata.SingleTape;
import bjc.utils.esodata.Tape;
-
+import bjc.utils.esodata.TapeLibrary;
+
+/**
+ * Implements multiple interleaved parse streams, as well as a command language
+ * for the streams.
+ *
+ * The idea for the interleaved streams came from the language Oozylbub &amp;
+ * Murphy, but the command language was my own idea.
+ *
+ * @author Ben Culkin
+ */
public class StreamEngine {
+ /*
+ * The engine we're attached to.
+ */
private DiceLangEngine eng;
+ /*
+ * Our streams.
+ */
private Tape<IList<String>> streams;
private IList<String> currStream;
+ /*
+ * Saved streams
+ */
+ private TapeLibrary<IList<String>> savedStreams;
+
+ /**
+ * Create a new stream engine.
+ *
+ * @param engine The dice engine we're attached to.
+ */
public StreamEngine(DiceLangEngine engine) {
eng = engine;
+
+ savedStreams = new TapeLibrary<>();
}
private void init() {
+ /*
+ * Reinitialize our list of streams.
+ */
streams = new SingleTape<>();
+ /*
+ * Create an initial stream.
+ */
currStream = new FunctionalList<>();
streams.insertBefore(currStream);
}
+ /**
+ * Process a possibly interleaved set of streams from toks into dest.
+ *
+ * @param toks The raw token to read streams from.
+ * @param dest The list to write the final stream to.
+ *
+ * @return Whether or not the streams were successfully processed.
+ */
public boolean doStreams(String[] toks, IList<String> dest) {
+ /*
+ * Initialize per-run state.
+ */
init();
+ /*
+ * Are we currently quoting things?
+ */
boolean quoteMode = false;
+ /*
+ * Process each token.
+ */
for(String tk : toks) {
+ /*
+ * Process stream commands.
+ */
if(tk.startsWith("{@S") && !quoteMode) {
if(tk.equals("{@SQ}")) {
quoteMode = true;
} else if(!processCommand(tk)) {
return false;
}
- // Command ran correctly, continue
+ /*
+ * Command ran correctly, continue
+ */
} else {
if(tk.equals("{@SU}")) {
quoteMode = false;
@@ -69,47 +125,47 @@ public class StreamEngine {
for(char comm : comms) {
switch(comm) {
- case '+':
- streams.insertAfter(new FunctionalList<>());
- break;
- case '>':
- if(!streams.right()) {
- Errors.inst.printError(EK_STRM_NONEX);
- return false;
- }
+ case '+':
+ streams.insertAfter(new FunctionalList<>());
+ break;
+ case '>':
+ if(!streams.right()) {
+ Errors.inst.printError(EK_STRM_NONEX);
+ return false;
+ }
- currStream = streams.item();
- break;
- case '<':
- if(!streams.left()) {
- Errors.inst.printError(EK_STRM_NONEX);
- return false;
- }
+ currStream = streams.item();
+ break;
+ case '<':
+ if(!streams.left()) {
+ Errors.inst.printError(EK_STRM_NONEX);
+ return false;
+ }
+ currStream = streams.item();
+ break;
+ case '-':
+ if(streams.size() == 1) {
+ Errors.inst.printError(EK_STRM_LAST);
+ return false;
+ } else {
+ streams.remove();
currStream = streams.item();
- break;
- case '-':
- if(streams.size() == 1) {
- Errors.inst.printError(EK_STRM_LAST);
- return false;
- } else {
- streams.remove();
- currStream = streams.item();
- }
- break;
- case 'S':
- if(streams.size() == 1) {
- Errors.inst.printError(EK_STRM_LAST);
- return false;
- } else {
- IList<String> stringLit = streams.remove();
- currStream = streams.item();
- currStream.add(ListUtils.collapseTokens(stringLit, " "));
- }
- break;
- default:
- Errors.inst.printError(EK_STRM_INVCOM, tk);
+ }
+ break;
+ case 'S':
+ if(streams.size() == 1) {
+ Errors.inst.printError(EK_STRM_LAST);
return false;
+ } else {
+ IList<String> stringLit = streams.remove();
+ currStream = streams.item();
+ currStream.add(ListUtils.collapseTokens(stringLit, " "));
+ }
+ break;
+ default:
+ Errors.inst.printError(EK_STRM_INVCOM, tk);
+ return false;
}
}