internal Directive ParseDirective(string line) { DirectiveComponents components; DirectiveHandler handler; Directive directive; if (DirectiveComponents.TryParse(line, out components) && _directiveParsers.TryGetValue(components.Key, out handler) && handler.TryParse(components, out directive)) { if (directive is StartOfTabDirective) { _isInTab = true; } if (directive is EndOfTabDirective) { _isInTab = false; } return(directive); } else { throw new FormatException($"Invalid directive at line {_lineNumber}."); } }
public static bool TryParse(string s, out DirectiveComponents components) { Match match = _directiveRegex.Match(s); if (match == null || string.IsNullOrWhiteSpace(match.Groups["key"].Value)) { components = null; return(false); } components = new DirectiveComponents( key: match.Groups["key"]?.Value.ToLower().Trim(), subKey: match.Groups["subkey"]?.Value.Trim(), value: match.Groups["value"]?.Value.Trim()); return(true); }