static void ParseGroup(ref List <SettingsTriplet> triplets, List <string> lines) { if (lines.Count == 0) { return; } if (lines[0].StartsWith("pattern-group")) { var triplet = new SettingsTriplet(); ParsePatternGroup(triplet, lines[0]); string item = null, solution = null, document = null; Color? maybeColor = null; foreach (var line in lines.Skip(1)) { ParsePattern(ref item, ref solution, ref document, ref maybeColor, line); } // solution/document override item solution = solution ?? item ?? ""; document = document ?? item ?? ""; var drawColor = maybeColor.NullOr(c => Color.FromRgb(c.R, c.G, c.B)); triplet.FormatIfNothingOpened = new TitleBarFormat(null, drawColor); triplet.FormatIfDocumentOpened = new TitleBarFormat(document, drawColor); triplet.FormatIfSolutionOpened = new TitleBarFormat(solution, drawColor); triplets.Add(triplet); } }
static void ParsePatternGroup(SettingsTriplet triplet, string line) { var m = Regex.Match(line, "^pattern-group(\\[(.+)\\])?\\s*:"); if (m.Success) { if (m.Groups.Count > 1) { var filter = m.Groups[2].Value; ParseFilter(triplet, filter); } } }
static void ParseFilter(SettingsTriplet triplet, string filterString) { var filters = filterString .Split(new char[] { ',' }) .Select(x => x.Trim()); foreach (var filter in filters) { if (RegexMatch(out Match match, filter, @"([a-z-]+)\s*=~\s*(.+)")) { var tag = match.Groups[1].Value; var expr = match.Groups[2].Value; triplet.PatternDependencies.Add(Tuple.Create(tag, expr)); } else if (!string.IsNullOrEmpty(filter)) { triplet.PatternDependencies.Add(Tuple.Create(filter, "")); } } }