/// <summary> /// Get an integer tag relevant to the specified input, erroring on the command system if invalid input is given (Returns 0 in that case). /// Never null! /// </summary> /// <param name="err">Error call if something goes wrong.</param> /// <param name="input">The input text to create a integer from.</param> /// <returns>The integer tag.</returns> public static IntegerTag For(TemplateObject input, Action <string> err) { return(input switch { IntegerTag itag => itag, IIntegerTagForm itf => new IntegerTag(itf.IntegerForm), DynamicTag dtag => For(dtag.Internal, err), _ => For(err, input.ToString()), });
/// <summary>Returns a FunctionTag for the given text.</summary> /// <param name="data">The data.</param> /// <param name="input">The input text.</param> /// <returns>A TagTypeTag.</returns> public static FunctionTag For(TagData data, string input) { if (!input.Contains('|')) { CommandScript script = data.Engine.GetFunction(input); if (script == null) { throw data.Error($"Unknown script name '{TextStyle.Separate}{input}{TextStyle.Base}'."); } return(new FunctionTag(script)); } ListTag list = ListTag.For(input); if (list.Internal.Count < 2) { throw data.Error("Cannot construct FunctionTag with empty input."); } string type = list.Internal[0].ToString(); if (type == "anon") { if (list.Internal.Count < 4) { throw data.Error("Cannot construct FunctionTag without start line, name, and commandlist input."); } string name = list.Internal[1].ToString(); int startLine = (int)IntegerTag.For(list.Internal[2], data).Internal; string commands = list.Internal[3].ToString(); CommandScript script = ScriptParser.SeparateCommands(name, commands, data.Engine, startLine, data.DBMode); if (script == null) { throw data.Error("Anonymous function failed to generate."); } script.TypeName = CommandScript.TYPE_NAME_ANONYMOUS; script.IsAnonymous = true; script.AnonymousString = input["anon|".Length..];