public DependencyRuleGroup Combine([NotNull] DependencyRuleGroup other, bool ignoreCase) { return(new DependencyRuleGroup(_groupMarker, _groupPattern + "+" + other._groupPattern, _groupMatchOrNullForMainGroup, _allowed.Union(other._allowed), _questionable.Union(other._questionable), _forbidden.Union(other._forbidden))); }
protected override DependencyRuleSet CreateConfigurationFromText([NotNull] GlobalContext globalContext, string fullConfigFileName, int startLineNo, TextReader tr, bool ignoreCase, string fileIncludeStack, bool forceReloadConfiguration, Dictionary <string, string> configValueCollector, ValuesFrame localVars) { ItemType usingItemType = null; ItemType usedItemType = null; string ruleSourceName = fullConfigFileName; string previousRawUsingPattern = ""; var ruleGroups = new List <DependencyRuleGroup>(); var children = new List <DependencyRuleSet>(); DependencyRuleGroup mainRuleGroup = new DependencyRuleGroup("", globalContext.IgnoreCase, null, null, "global"); DependencyRuleGroup currentGroup = mainRuleGroup; ruleGroups.Add(currentGroup); ProcessTextInner(globalContext, fullConfigFileName, startLineNo, tr, ignoreCase, fileIncludeStack, forceReloadConfiguration, onIncludedConfiguration: (e, n) => children.Add(e), onLineWithLineNo: (line, lineNo) => { if (line.StartsWith("$")) { if (currentGroup != null && currentGroup.GroupMarker != "") { return("$ inside '{{ ... }}' not allowed"); } else { string typeLine = line.Substring(1).Trim(); int i = typeLine.IndexOf(MAY_USE, StringComparison.Ordinal); if (i < 0) { Log.WriteError($"$-line '{line}' must contain " + MAY_USE, ruleSourceName, lineNo); throw new ApplicationException($"$-line '{line}' must contain " + MAY_USE_TAIL); } usingItemType = ItemType.New(typeLine.Substring(0, i).Trim(), globalContext.IgnoreCase); usedItemType = ItemType.New(typeLine.Substring(i + MAY_USE.Length).Trim(), globalContext.IgnoreCase); return(null); } } else if (line.EndsWith("{")) { if (currentGroup == null || usingItemType == null) { return($"Itemtypes not defined - $ line is missing in {ruleSourceName}, dependency rules are ignored"); } else if (currentGroup.GroupMarker != "") { return("Nested '{{ ... {{' not possible"); } else { string groupPattern = line.TrimEnd('{').Trim(); currentGroup = new DependencyRuleGroup(groupPattern, globalContext.IgnoreCase, usingItemType, usedItemType, ruleSourceName + "_" + lineNo); ruleGroups.Add(currentGroup); return(null); } } else if (line == "}") { if (currentGroup != null && currentGroup.GroupMarker != "") { currentGroup = mainRuleGroup; return(null); } else { return("'}}' without corresponding '... {{'"); } } else { string currentRawUsingPattern; bool ok = currentGroup.AddDependencyRules(usingItemType, usedItemType, ruleSourceName, lineNo, line, ignoreCase, previousRawUsingPattern, out currentRawUsingPattern); if (!ok) { return("Could not add dependency rule"); } else { previousRawUsingPattern = currentRawUsingPattern; return(null); } } }, configValueCollector: configValueCollector, localVars: localVars); return(new DependencyRuleSet(ruleGroups, children)); }