public static RulesSet FromLines(string[] strings) {
var id = strings[0].Trim();
if (!Regex.IsMatch(id, @"^\w+$")) {
throw new InvalidDataException();
}
var regex = new Regex(@"\s{2,}", RegexOptions.Compiled);
var list = new List<Rule>(strings.Length);
string filename = null, section = null;
foreach (var raw in strings.Skip(1)) {
var splitted = regex.Split(raw.Trim());
if (splitted.Length == 0 || splitted[0].Length == 0) continue;
var path = splitted[0].Split(new [] { '/' }, 3);
var type = RuleTypeFromString(splitted.Length == 1 ? "number" : splitted[1]);
if (type == RuleType.File) {
throw new NotImplementedException();
} else {
var property = path[path.Length - 1];
if (path.Length > 1) {
section = path[path.Length - 2];
}
if (path.Length > 2) {
filename = path[path.Length - 3];
}
if (filename == null || section == null) {
Console.Error.WriteLine("invalid field '{0}/{1}/{2}'", filename, section, property);
continue;
}
list.Add(new Rule {
Type = type,
Filename = filename,
Section = section,
Property = property,
Params = splitted.Skip(2).ToArray()
});
}
}
return new RulesSet(id, list.ToArray());
}