public static bool ShowErrorTo(this ITokenErrLog self, Show.PrintFunc show) { string errStr = self.GetErrorString(); if (string.IsNullOrEmpty(errStr)) { return(false); } show.Invoke(errStr); return(true); }
public void ParseCommand(Instruction instruction, Show.PrintFunc print, out Tokenizer tokenizer) { tokenizer = null; string trimmed = instruction.text?.Trim(); if (string.IsNullOrEmpty(trimmed)) { return; } //Tokenizer tok = new Tokenizer(); //CodeConvert.TryParseArgs(trimmed, out List<object> parsedCommand, instruction.source, tok); //Show.Log(trimmed+":::"+parsedCommand.Stringify()); string firstWord = Tokenizer.FirstWord(trimmed); if (firstWord == null) { firstWord = trimmed; } //Show.Log("1stword " + firstWord.StringifySmall()); Command command = GetCommand(firstWord); if (command != null) { tokenizer = command.Tokenize(trimmed); //Show.Log(tokenizer); if (tokenizer.HasError()) { return; } command.handler.Invoke(new Command.Exec(command, tokenizer, instruction.source, print)); } else { print.Invoke("unknown command \'" + firstWord + "\'\n"); tokenizer = new Tokenizer(); tokenizer.Tokenize(trimmed, Command.BaseArgumentParseRules); } if (tokenizer.HasError()) { return; } Instruction next = NextInstruction(tokenizer, instruction.source); if (next == null) { return; } ParseCommand(next, print, out tokenizer); // make this a do-while loop instead of tail recursion? }