mirror of
https://github.com/Stone-Red-Code/YesNt-Interpreter.git
synced 2026-09-09 16:06:08 +02:00
Fix error when loading empty file
This commit is contained in:
@@ -94,8 +94,10 @@ namespace YesNt.Interpreter.Runtime
|
|||||||
{
|
{
|
||||||
runtimeInfo.Reset();
|
runtimeInfo.Reset();
|
||||||
runtimeInfo.IsDebugMode = isDebugMode;
|
runtimeInfo.IsDebugMode = isDebugMode;
|
||||||
LoadFile(path);
|
if (LoadFile(path))
|
||||||
Execute();
|
{
|
||||||
|
Execute();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Execute(List<string> lines, bool isDebugMode = false)
|
public void Execute(List<string> lines, bool isDebugMode = false)
|
||||||
@@ -205,14 +207,7 @@ namespace YesNt.Interpreter.Runtime
|
|||||||
statement.Value.Invoke(copyLine);
|
statement.Value.Invoke(copyLine);
|
||||||
statementFound = true;
|
statementFound = true;
|
||||||
|
|
||||||
if (!leadingWhitespace)
|
runtimeInfo.CurrentLine = !leadingWhitespace ? runtimeInfo.CurrentLine.Trim() : runtimeInfo.CurrentLine.TrimEnd();
|
||||||
{
|
|
||||||
runtimeInfo.CurrentLine = runtimeInfo.CurrentLine.Trim();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
runtimeInfo.CurrentLine = runtimeInfo.CurrentLine.TrimEnd();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (statementAttribute.SearchMode == SearchMode.EndOfLine && runtimeInfo.CurrentLine.EndsWith(name))
|
else if (statementAttribute.SearchMode == SearchMode.EndOfLine && runtimeInfo.CurrentLine.EndsWith(name))
|
||||||
{
|
{
|
||||||
@@ -261,20 +256,28 @@ namespace YesNt.Interpreter.Runtime
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadFile(string path)
|
private bool LoadFile(string path)
|
||||||
{
|
{
|
||||||
if (!File.Exists(path))
|
if (!File.Exists(path))
|
||||||
{
|
{
|
||||||
runtimeInfo.Exit($"File \"{path}\" not found!", true);
|
Console.WriteLine($"File \"{path}\" not found!");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] lines = File.ReadAllLines(path);
|
string[] lines = File.ReadAllLines(path);
|
||||||
|
|
||||||
|
if (lines.Length <= 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"File \"{path}\" is empty!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < lines.Length; i++)
|
for (int i = 0; i < lines.Length; i++)
|
||||||
{
|
{
|
||||||
runtimeInfo.Lines.Add(new Line(lines[i], Path.GetFileName(path), i));
|
runtimeInfo.Lines.Add(new Line(lines[i], Path.GetFileName(path), i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user