private static IEnumerable <SectionBlock> ParseGlobal(TextReader reader) { if (reader.Peek() == -1) { return(Enumerable.Empty <SectionBlock>()); } if (GetNextNonEmptyLine(reader) != "Global") { throw new Exception(); } List <SectionBlock> globalSectionBlocks = new List <SectionBlock>(); // The blocks inside here are indented while (reader.Peek() != -1 && char.IsWhiteSpace((char)reader.Peek())) { globalSectionBlocks.Add(SectionBlock.Parse(reader)); } if (GetNextNonEmptyLine(reader) != "EndGlobal") { throw new Exception(); } // Consume potential empty lines at the end of the global block while (reader.Peek() != -1 && "\r\n".Contains((char)reader.Peek())) { reader.ReadLine(); } return(globalSectionBlocks); }
internal static ProjectBlock Parse(TextReader reader) { string startLine = reader.ReadLine().TrimStart(null); LineScanner scanner = new LineScanner(startLine); if (scanner.ReadUpToAndEat("(\"") != "Project") { throw new Exception(); } Guid projectTypeGuid = Guid.Parse(scanner.ReadUpToAndEat("\")")); // Read chars up to next quote, must contain "=" with optional leading/trailing whitespaces. if (scanner.ReadUpToAndEat("\"").Trim() != "=") { throw new Exception(); } string projectName = scanner.ReadUpToAndEat("\""); // Read chars up to next quote, must contain "," with optional leading/trailing whitespaces. if (scanner.ReadUpToAndEat("\"").Trim() != ",") { throw new Exception(); } string projectPath = scanner.ReadUpToAndEat("\""); // Read chars up to next quote, must contain "," with optional leading/trailing whitespaces. if (scanner.ReadUpToAndEat("\"").Trim() != ",") { throw new Exception(); } Guid projectGuid = Guid.Parse(scanner.ReadUpToAndEat("\"")); List <SectionBlock> projectSections = new List <SectionBlock>(); while (char.IsWhiteSpace((char)reader.Peek())) { projectSections.Add(SectionBlock.Parse(reader)); } // Expect to see "EndProject" but be tolerant with missing tags as in Dev12. // Instead, we may see either P' for "Project" or 'G' for "Global", which will be handled next. if (reader.Peek() != 'P' && reader.Peek() != 'G') { if (reader.ReadLine() != "EndProject") { throw new Exception(); } } return(new ProjectBlock(projectTypeGuid, projectName, projectPath, projectGuid, projectSections)); }