Implemented the 'list all;' functionality.
All checks were successful
continuous-integration/appveyor/branch AppVeyor build succeeded

Fixed an issue with parsing multiple lines
This commit is contained in:
Brychan Dempsey 2021-03-19 12:12:56 +13:00
parent e72371bf34
commit 9e68ca1fcd

View File

@ -153,7 +153,16 @@ namespace Assignment_1
result = AppendSet(source);
break;
case statements.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
}
}
/// <summary>
/// Creates and prints a list of all defined variables
/// Creates and prints a nicely formatted table of all values
/// </summary>
/// <param name="printUnprint">List values normally excluded from printing</param>
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)));