private static void ValidateExampleStructure(CommandStructure parent, string[] example) { ParameterStructure[] usedParameters = new ParameterStructure[example.Length]; for (int i = 0; i < example.Length; i++) { if (!parent.HasParameter(example[i])) { throw new ParameterDoesNotExistException(example, example[i]); } usedParameters[i] = parent.GetParameterByName(example[i]); } foreach (var usedParameter in usedParameters) { foreach (var otherParameter in usedParameters) { if (usedParameter == otherParameter) { continue; } if (!usedParameter.Allows(otherParameter)) { throw new ParameterNotAllowedException(usedParameter, otherParameter); } if (!otherParameter.Allows(usedParameter)) { throw new ParameterNotAllowedException(otherParameter, usedParameter); } } } }
public bool Allows(ParameterStructure parameter) { if (IsExclusive) { return(false); } foreach (var name in parameter.Names) { if (Others.Contains(name)) { return(true); } } return(false); }
private static void ValidateParameterStructure(ParameterStructure parameter) { if (parameter.IsExclusive || parameter.Others == null) { return; } foreach (var other in parameter.Others) { if (!parameter.Parent.HasParameter(other)) { throw new ParameterDoesNotExistException(parameter, other); } var otherParameter = parameter.Parent.GetParameterByName(other); if (!otherParameter.Allows(parameter)) { throw new ParameterNotAllowedException(otherParameter, parameter); } } }
private static ParameterStructure CollectParameterStructure(CommandFileReader reader, CommandStructure parent, out int skip) { ParameterStructure result = null; string line = reader.NextLine(); if (Regex.IsMatch(line, @"\(" + RegexVariable + @"(\s*,\s*" + RegexVariable + @")*\)")) { string[] names = Regex.Match(line, @"\(" + RegexVariable + @"(\s*,\s*" + RegexVariable + @")*\)").Value .Trim('(', ')').Split(',').Select(n => n.Trim()).ToArray(); result = new ParameterStructure(parent, names); } else { throw new PositionException(reader.GetLineObject(), new MalformedCodeException(@"\(" + RegexVariable + @"(\s*,\s*" + RegexVariable + @")*\)")); } while (!reader.IsDone) { line = reader.NextLine(); if (line.StartsWith("flags:")) { string[] values = line.Substring(line.IndexOf(':') + 1).Trim().Split(',').Select(v => v.Trim()).ToArray(); foreach (var value in values) { result.FlagsPosition(reader.GetLineObject()); switch (value) { case "short": result.SetShort(); break; case "exclusive": result.SetExclusive(); break; case "meta": //result.IsMeta = true; throw new NotImplementedException(); break; default: throw new PositionException(reader.GetLineObject(), new WrongValueException(value, new string[] { "short", "exclusive", "meta" })); } } } else if (line.StartsWith("type:")) { string value = line.Substring(line.IndexOf(':') + 1).Trim(); if (!Regex.IsMatch(line, RegexParameterType)) { throw new PositionException(reader.GetLineObject(), new WrongValueException(value, new string[] { "string", "file", "command", "bool", "int", "float" })); } } else if (Regex.IsMatch(line, RegexParameterOthers)) { if (result.IsExclusive) { throw new PositionException(reader.GetLineObject(), new ExclusiveParameterException(result)); } result.SetOther(line.Split(':')[1].Split(',').Select(o => o.Trim()).ToArray()); } else if (EndsBlock(line)) { break; } else { throw new PositionException(reader.GetLineObject(), new MalformedCodeException(RegexParameterFlags, RegexParameterOthers, RegexParameterType)); } } skip = reader.Position - reader.Start - 1; return(result); }
public void Add(ParameterStructure parameter) { parameters.Add(parameter); }