diff --git a/YesNt.Interpreter/Statements/CodeFlowStatements.cs b/YesNt.Interpreter/Statements/CodeFlowStatements.cs index 38aee20..1000b84 100644 --- a/YesNt.Interpreter/Statements/CodeFlowStatements.cs +++ b/YesNt.Interpreter/Statements/CodeFlowStatements.cs @@ -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; } diff --git a/YesNt.Interpreter/Statements/FunctionStatements.cs b/YesNt.Interpreter/Statements/FunctionStatements.cs index 7e50ec4..d975a35 100644 --- a/YesNt.Interpreter/Statements/FunctionStatements.cs +++ b/YesNt.Interpreter/Statements/FunctionStatements.cs @@ -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;