From 482ecc64680234f26b651a0730af5ef7725cbec7 Mon Sep 17 00:00:00 2001 From: Brychan Dempsey Date: Mon, 15 Mar 2021 13:46:54 +1300 Subject: [PATCH] Fixed bad command continued parsing (Closes #1) --- Assignment 1/Program.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Assignment 1/Program.cs b/Assignment 1/Program.cs index 24c0177..d25c459 100644 --- a/Assignment 1/Program.cs +++ b/Assignment 1/Program.cs @@ -77,7 +77,8 @@ namespace Assignment_1 printwordcount, set, reverse, - h + h, + writeout } public void StartParsing(Stream source, bool dynamicInput = false) { @@ -97,6 +98,7 @@ namespace Assignment_1 // parse the statement or list of statements; // This is done by reading the next word SkipWhitespace(source); + long initPos = source.Position; long position = FindNextWord(source, out string word); object statementType; if (Enum.TryParse(typeof(statements), word, out statementType)) @@ -138,9 +140,20 @@ namespace Assignment_1 Console.WriteLine("\t{0}", ((statements)item).ToString()); } break; + case statements.writeout: + // Writes the full command history to the stream. + Console.WriteLine("Writing input commands to {0}..."); + break; } } - else Console.WriteLine("Failed parsing statement"); + else + { + // Statement parse failed, + // Ensure stream gets trimmed back to the correct position + Console.WriteLine("Failed parsing statement"); + source.Position = initPos; + source.SetLength(initPos); + } } }