Enforce label and function statements to end with ':' and update syntax checks

This commit is contained in:
Stone_Red
2026-03-04 14:33:47 +01:00
parent 299558df70
commit 317bca84d3
2 changed files with 32 additions and 6 deletions
@@ -63,10 +63,23 @@ internal class CodeFlowStatements : StatementRuntimeInformation
}
}
[Statement("label", SearchMode.StartOfLine, SpaceAround.End, ConsoleColor.Green, ExecuteInSearchMode = true)]
[Statement("label", SearchMode.StartOfLine, SpaceAround.End, ConsoleColor.Green, ExecuteInSearchMode = true, Separator = ":")]
public void FindLabel(string args)
{
string key = NormalizeBlockName(args);
string labelDeclaration = args.Trim();
if (!labelDeclaration.EndsWith(':'))
{
RuntimeInfo.Exit("Invalid syntax. Statement must end with ':'", true);
return;
}
string key = NormalizeBlockName(labelDeclaration);
if (string.IsNullOrWhiteSpace(key))
{
RuntimeInfo.Exit("Invalid syntax", true);
return;
}
if (RuntimeInfo.Labels.ContainsKey(key))
{
RuntimeInfo.Labels[key] = RuntimeInfo.LineNumber;
@@ -146,7 +159,7 @@ internal class CodeFlowStatements : StatementRuntimeInformation
args = args.Trim();
if (!args.EndsWith(':'))
{
RuntimeInfo.Exit("Invalid syntax", true);
RuntimeInfo.Exit("Invalid syntax. Statement must end with ':'", true);
return;
}
@@ -198,7 +211,7 @@ internal class CodeFlowStatements : StatementRuntimeInformation
args = args.Trim();
if (!args.EndsWith(':'))
{
RuntimeInfo.Exit("Invalid syntax", true);
RuntimeInfo.Exit("Invalid syntax. Statement must end with ':'", true);
return;
}
@@ -10,7 +10,7 @@ namespace YesNt.Interpreter.Statements;
internal class FunctionStatements : StatementRuntimeInformation
{
[Statement("func", SearchMode.StartOfLine, SpaceAround.End, ConsoleColor.DarkYellow, ExecuteInSearchMode = true)]
[Statement("func", SearchMode.StartOfLine, SpaceAround.End, ConsoleColor.DarkYellow, ExecuteInSearchMode = true, Separator = ":")]
public void FindFunction(string args)
{
if (RuntimeInfo.InternalIsInFunction)
@@ -19,7 +19,20 @@ internal class FunctionStatements : StatementRuntimeInformation
return;
}
string key = NormalizeBlockName(args);
string functionDeclaration = args.Trim();
if (!functionDeclaration.EndsWith(':'))
{
RuntimeInfo.Exit("Invalid syntax. Statement must end with ':'", true);
return;
}
string key = NormalizeBlockName(functionDeclaration);
if (string.IsNullOrWhiteSpace(key))
{
RuntimeInfo.Exit("Invalid syntax", true);
return;
}
if (RuntimeInfo.Functions.ContainsKey(key))
{
RuntimeInfo.Functions[key] = RuntimeInfo.LineNumber;