using System.Drawing; using System.Text.RegularExpressions; namespace Day18; public partial class Parser { [GeneratedRegex(@"([UDLR])\s+(\d+)\s+\((.*)\)")] private partial Regex LineMatch(); public IEnumerable Parse(string inputFile) { using var reader = File.OpenText(inputFile); var colorConverter = new ColorConverter(); while (!reader.EndOfStream) { var line = reader.ReadLine()!; var match = LineMatch().Match(line); if (!match.Success) { throw new Exception($"Invalid instruction: {line}"); } yield return new Instruction( match.Groups[1].Value[0], int.Parse(match.Groups[2].Value), Convert.FromHexString(match.Groups[3].Value.Substring(1))); } } }