Added the continued execution logic
Some checks failed
continuous-integration/appveyor/branch AppVeyor build failed

This commit is contained in:
Brychan Dempsey 2021-03-23 11:26:38 +13:00
parent 60d81c6332
commit 8774264207

View File

@ -78,6 +78,7 @@ namespace Assignment_1
parser.StartParsing(sourceStream, dynamicInput); parser.StartParsing(sourceStream, dynamicInput);
Console.WriteLine(Environment.NewLine + new string('─', 40)); Console.WriteLine(Environment.NewLine + new string('─', 40));
// Not strictly required, but could have problems if we try loading a large program immediately after unloading the last // Not strictly required, but could have problems if we try loading a large program immediately after unloading the last
// NB: parser is out-of-scope from now
GC.Collect(); GC.Collect();
Console.WriteLine("\nProgram parsing complete."); Console.WriteLine("\nProgram parsing complete.");
if (dynamicInput == false) if (dynamicInput == false)
@ -85,14 +86,49 @@ namespace Assignment_1
Thread.Sleep(2000); Thread.Sleep(2000);
Environment.Exit(0); Environment.Exit(0);
} }
Console.WriteLine("Would you like to parse more programs?"); ConsoleKeyInfo ck = new();
string answer = Console.ReadLine(); while (ck.Key != ConsoleKey.Y || ck.Key != ConsoleKey.N)
if (answer.ToLower() == "no")
{ {
Environment.Exit(0); Console.WriteLine("\nWould you like to parse more programs? Y/n:");
ck = Console.ReadKey();
} }
Console.WriteLine("Not yet implemented"); if (ck.Key == ConsoleKey.N)
Console.ReadLine(); {
exit = true;
}
else
{
// Need the logic to prep the next source stream
ck = new();
while (ck.Key != ConsoleKey.Y || ck.Key != ConsoleKey.N)
{
Console.WriteLine("\nWould you like to pipe data from source file? Y/n:");
ck = Console.ReadKey();
}
if (ck.Key == ConsoleKey.N)
{
// Set the input to standard input stream
Console.SetIn(Console.In);
}
else
{
Console.WriteLine("Enter the source path:");
string sourcePath = Console.ReadLine();
if (File.Exists(sourcePath))
{
try
{
Console.SetIn(File.OpenText(sourcePath));
}
catch (Exception e)
{
Console.WriteLine("Encountered an error opening the source file: " + e.Message);
}
}
}
}
// GC already done, just loop back to program start
} }
} }