//internal static IEnumerable<Instruction> ReadData(string filePath) //{ // return readlines(filePath).Select(ParseLine); //} internal bool ParseLine(string line) { var regexResult = messageRule.Match(line); if (!regexResult.Success) { return(false); } if (regexResult.Groups.ContainsKey("messageRule") && regexResult.Groups["messageRule"].Success) { var ruleId = Convert.ToInt32(regexResult.Groups["id"].Value); if (regexResult.Groups.ContainsKey("char") && regexResult.Groups["char"].Success) { Rules.AddConstantRule(ruleId, regexResult.Groups["char"].Value[1]); } else if (regexResult.Groups.ContainsKey("rule") && regexResult.Groups["rule"].Success) { Rules.AddFollowingRule(ruleId, regexResult.Groups["rule"].Captures.Select(c => Convert.ToInt32(c.Value)).ToArray()); } else if (regexResult.Groups.ContainsKey("orRule1") && regexResult.Groups["orRule1"].Success) { var or1Arguments = regexResult.Groups["orRule1"].Captures.Select(c => Convert.ToInt32(c.Value)).ToArray(); var or2Arguments = regexResult.Groups["orRule2"].Captures.Select(c => Convert.ToInt32(c.Value)).ToArray(); Rules.AddFollowingOrRule(ruleId, or1Arguments, or2Arguments); } } else if (regexResult.Groups.ContainsKey("message") && regexResult.Groups["message"].Success) { Messages.Add(regexResult.Groups["message"].Value); } return(regexResult.Success); }