void CheckSaturation(Option option) { bool minimalSaturation = option.ArgumentsCount >= option.Arity.MinimalOccurs; if (!minimalSaturation) { throw new RequiredArgumentIsMissingException(option.Switches.First()); } }
void ParseOption(Token token) { lastOption = GetOptionByToken(token); Token nextToken = tokens.NextToken(); if (nextToken == null) { CheckSaturation(lastOption); lastOption.AddArgumentValue("true"); ParsedOption.Add(lastOption); } else if (nextToken is OptionToken) { CheckSaturation(lastOption); lastOption.AddArgumentValue("true"); ParsedOption.Add(lastOption); ParseOption(nextToken); } else if (nextToken is ArgumentToken) { if (IsFullSaturated(lastOption)) { ParseOptionArguments(nextToken); } else { lastOption.AddArgumentValue("true"); ParsedOption.Add(lastOption); ParseParameters(nextToken); } } else if (nextToken is TreatAsArgumentToken) { CheckSaturation(lastOption); lastOption.AddArgumentValue("true"); ParsedOption.Add(lastOption); ParseParameters(tokens.NextToken()); } }
bool IsFullSaturated(Option option) { bool minimalSaturation = lastOption.ArgumentsCount >= lastOption.Arity.MinimalOccurs; bool maximalSaturation = lastOption.ArgumentsCount >= lastOption.Arity.MaximalOccurs; return (!minimalSaturation || (minimalSaturation && !maximalSaturation)); }
public void Option(Option option) { _options.Add(option); }