protected IEnumerable<Actor> GetActorsFromFile(DecorateFileInfo file) { Console.WriteLine(" Parsing file " + file.FileInfo.FullName); //// if(cached && cacheValid){ //// load from cache //// } //// else //// { string text = string.Empty; using (var reader = file.FileInfo.OpenText()) { text = reader.ReadToEnd(); } // remove comments text = Regex.Replace(text, "//(.*?)\\n", Environment.NewLine, RegexOptions.Singleline | RegexOptions.IgnoreCase); text = Regex.Replace(text, "/\\*(.*?)\\*/", string.Empty, RegexOptions.Singleline | RegexOptions.IgnoreCase); // remove action and const definitions if (file.Origin == DecorateFileType.Native) { text = Regex.Replace(text, "(action)?\\s*(native|const)?(.*?);", string.Empty, RegexOptions.IgnoreCase); } string actorPattern = @" actor\s+ ([A-Za-z0-9_]+|"".*?"") # actor name (with or without quotes) \s* (:\s*([A-Za-z0-9_]+|"".*?"")\s*)? # parent name (with or without quotes) (replaces\s*([A-Za-z0-9_]+|"".*?"")\s*)? # replaced actor name (with or without quotes) (\d*\s*)? # doomEdNum (native\s*)? # native yes/no { (.*?) # properties and flags (states\s*{(.*?)}\s*)? # state machine } "; var matches = Regex.Matches(text, actorPattern, RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace); foreach (Match match in matches) { string fullText = match.Groups[0].Value; string name = match.Groups[1].Value; string parent = match.Groups[3].Value; string replaces = match.Groups[5].Value; string doomednum = match.Groups[6].Value; string native = match.Groups[7].Value; string content = match.Groups[8].Value; string statesContent = match.Groups[10].Value; Actor actor = null; actor = new Actor() { File = file.FileInfo, Name = name, ParentName = parent == string.Empty ? (name.ToLower() == "actor" ? string.Empty : "actor") : parent, ReplacesName = replaces, IsNative = native != string.Empty, IsFromNativeFile = file.Origin == DecorateFileType.Native, DoomEdNum = doomednum != string.Empty ? Int32.Parse(doomednum) : 0, PropertiesAndFlagsText = content, StatesText = statesContent, OriginalText = fullText }; yield return actor; } }
protected IEnumerable <Actor> GetActorsFromFile(DecorateFileInfo file) { Console.WriteLine(" Parsing file " + file.FileInfo.FullName); //// if(cached && cacheValid){ //// load from cache //// } //// else //// { string text = string.Empty; using (var reader = file.FileInfo.OpenText()) { text = reader.ReadToEnd(); } // remove comments text = Regex.Replace(text, "//(.*?)\\n", Environment.NewLine, RegexOptions.Singleline | RegexOptions.IgnoreCase); text = Regex.Replace(text, "/\\*(.*?)\\*/", string.Empty, RegexOptions.Singleline | RegexOptions.IgnoreCase); // remove action and const definitions if (file.Origin == DecorateFileType.Native) { text = Regex.Replace(text, "(action)?\\s*(native|const)?(.*?);", string.Empty, RegexOptions.IgnoreCase); } string actorPattern = @" actor\s+ ([A-Za-z0-9_]+|"".*?"") # actor name (with or without quotes) \s* (:\s*([A-Za-z0-9_]+|"".*?"")\s*)? # parent name (with or without quotes) (replaces\s*([A-Za-z0-9_]+|"".*?"")\s*)? # replaced actor name (with or without quotes) (\d*\s*)? # doomEdNum (native\s*)? # native yes/no { (.*?) # properties and flags (states\s*{(.*?)}\s*)? # state machine } "; var matches = Regex.Matches(text, actorPattern, RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace); foreach (Match match in matches) { string fullText = match.Groups[0].Value; string name = match.Groups[1].Value; string parent = match.Groups[3].Value; string replaces = match.Groups[5].Value; string doomednum = match.Groups[6].Value; string native = match.Groups[7].Value; string content = match.Groups[8].Value; string statesContent = match.Groups[10].Value; Actor actor = null; actor = new Actor() { File = file.FileInfo, Name = name, ParentName = parent == string.Empty ? (name.ToLower() == "actor" ? string.Empty : "actor") : parent, ReplacesName = replaces, IsNative = native != string.Empty, IsFromNativeFile = file.Origin == DecorateFileType.Native, DoomEdNum = doomednum != string.Empty ? Int32.Parse(doomednum) : 0, PropertiesAndFlagsText = content, StatesText = statesContent, OriginalText = fullText }; yield return(actor); } }