public CommandExample ParseExample(CommandFileReader reader, CommandsFile commandsFile, out int skip) { CommandExample result = new CommandExample(); string line = reader.NextLine(); if (Regex.IsMatch(line, RegexExample)) { string[] used = Regex.Match(line, @"\(" + CreateMulitpleRegex(RegexVariable) + @"\)").Value .Trim('(', ')').Split(',').Select(s => s.Trim()).ToArray(); if (used.Length > 0 && used[0] != string.Empty) { commandsFile.Add(result, used); } } while (!reader.IsDone) { line = reader.NextLine(); if (Regex.IsMatch(line, RegexExampleExplanation)) { string value = line.Substring(line.IndexOf(':') + 1).Trim(); result.AddExplanation(value); } else if (Regex.IsMatch(line, RegexExampleLine)) { string value = line.Substring(line.IndexOf(':') + 1).Trim(); result.AddLine(value); } else if (EndsBlock(line)) { break; } else { throw new Exception(); } } skip = reader.Position - reader.Start - 1; return(result); }
public Parameter ParseParameter(CommandFileReader reader, CommandsFile commandsFile, out int skip) { Parameter result = new Parameter(); string line = reader.NextLine(); if (Regex.IsMatch(line, RegexParameter)) { result.Names = Regex.Match(line, @"\(" + CreateMulitpleRegex(RegexVariable) + @"\)").Value .Trim('(', ')').Split(',').Select(s => s.Trim()).ToArray(); } while (!reader.IsDone) { line = reader.NextLine(); if (Regex.IsMatch(line, RegexParameterType)) { string value = line.Substring(line.IndexOf(':') + 1).Trim(); switch (value) { case "bool": result.Type = ParameterType.Boolean; break; case "string": result.Type = ParameterType.String; break; case "file": result.Type = ParameterType.File; break; case "int": result.Type = ParameterType.Integer; break; case "float": result.Type = ParameterType.Float; break; case "command": result.Type = ParameterType.Command; break; default: throw new Exception("Can't happen because of Regex above."); } } else if (Regex.IsMatch(line, RegexParameterFlags)) { string[] values = line.Substring(line.IndexOf(':') + 1).Trim().Split(',').Select(v => v.Trim()).ToArray(); foreach (var value in values) { switch (value) { case "short": result.HasShort = true; break; case "exclusive": result.SetOthers(null); break; case "meta": result.IsMeta = true; break; default: throw new NotImplementedException("No Flag with this name known: " + value); } } } else if (Regex.IsMatch(line, RegexParameterOthers)) { string[] others = line.Substring(line.IndexOf(':') + 1).Trim().Split(',').Select(o => o.Trim()).ToArray(); commandsFile.Add(result, others); } else if (EndsBlock(line)) { break; } else { throw new Exception(); } } skip = reader.Position - reader.Start - 1; return(result); }