From 9e68ca1fcd01e1d2857a0398d87f23068f24fde8 Mon Sep 17 00:00:00 2001 From: Brychan Dempsey Date: Fri, 19 Mar 2021 12:12:56 +1300 Subject: [PATCH] Implemented the 'list all;' functionality. Fixed an issue with parsing multiple lines --- Assignment 1/Program.cs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Assignment 1/Program.cs b/Assignment 1/Program.cs index 1f9f0e1..fbf6bc1 100644 --- a/Assignment 1/Program.cs +++ b/Assignment 1/Program.cs @@ -153,7 +153,16 @@ namespace Assignment_1 result = AppendSet(source); break; case statements.list: - result = List(); + long pos = FindNextWord(source, out string nextWord); + if (nextWord == "all") + { + source.Position = pos; + result = List(true); + } + else + { + result = List(); + } break; case statements.print: result = Print(source, 0); @@ -204,9 +213,10 @@ namespace Assignment_1 } result(); } - else if(source.Position != lastLinePos) + else if(source.Position != lastLinePos-1) { // In the case that we expect some more data, we must keep tabs of our current line, and keep accumulating data until we're finished + lastLinePos = source.Position; cont = true; source.WriteByte((byte)' '); Console.Write(">"); @@ -219,11 +229,6 @@ namespace Assignment_1 } else { - // Statement parse failed, - // Ensure stream gets trimmed back to the correct position - //Console.WriteLine("Failed parsing statement"); - Console.WriteLine("Position is " + source.Position); - Console.WriteLine("Length is " + source.Length); throw new ParserException("Failed parsing statement", 0, source.Position); } } @@ -325,14 +330,14 @@ namespace Assignment_1 } } /// - /// Creates and prints a list of all defined variables + /// Creates and prints a nicely formatted table of all values /// /// List values normally excluded from printing Action List(bool printUnprint = false) { - int keyWidth = 10; + int keyWidth = 21; int valueWidth = 50; - int flagWidth = 9; + int flagWidth = 9; // 80 char total StringBuilder consoleOutput = new StringBuilder(); consoleOutput.Append(string.Format("┌" + new string('─', keyWidth) + "┬" + new string('─', valueWidth) + "┬" + new string('─', flagWidth) + "┐\n")); consoleOutput.Append(string.Format("│{0}│{1}│{2}│\n", CenterString("Symbol", keyWidth), CenterString("Value", valueWidth), CenterString("Flags", flagWidth)));