예제 #1
0
        internal static ProjectBlock Parse(SourceTextReader reader)
        {
            var startLine = reader.ReadLine().TrimStart();
            var scanner   = new LineScanner(startLine);

            if (scanner.ReadUpToAndEat("(\"") != "Project")
            {
                throw new Exception(string.Format(WorkspacesResources.InvalidProjectBlockInSolutionFile4, "Project"));
            }

            var projectTypeGuid = scanner.ReadUpToAndEat("\")").Parse(s => Guid.Parse(s));

            // Read chars upto next quote, must contain "=" with optional leading/trailing whitespaces.
            if (scanner.ReadUpToAndEat("\"").Trim() != "=")
            {
                throw new Exception(WorkspacesResources.InvalidProjectBlockInSolutionFile);
            }

            var projectName = scanner.ReadUpToAndEat("\"");

            // Read chars upto next quote, must contain "," with optional leading/trailing whitespaces.
            if (scanner.ReadUpToAndEat("\"").Trim() != ",")
            {
                throw new Exception(WorkspacesResources.InvalidProjectBlockInSolutionFile2);
            }

            var projectPath = scanner.ReadUpToAndEat("\"");

            // Read chars upto next quote, must contain "," with optional leading/trailing whitespaces.
            if (scanner.ReadUpToAndEat("\"").Trim() != ",")
            {
                throw new Exception(WorkspacesResources.InvalidProjectBlockInSolutionFile3);
            }

            var projectGuid = scanner.ReadUpToAndEat("\"").Parse(s => Guid.Parse(s));

            var 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(string.Format(WorkspacesResources.InvalidProjectBlockInSolutionFile4, "EndProject"));
                }
            }

            return(new ProjectBlock(projectTypeGuid, projectName.Parse(), projectPath.Parse(), projectGuid, projectSections));
        }
예제 #2
0
파일: SectionBlock.cs 프로젝트: Ref12/Codex
        internal static SectionBlock Parse(SourceTextReader reader)
        {
            SubText startLine;

            while ((startLine = reader.ReadLine()) != null)
            {
                startLine = startLine.TrimStart();
                if (startLine != string.Empty)
                {
                    break;
                }
            }

            var scanner = new LineScanner(startLine);

            var type = scanner.ReadUpToAndEat("(");
            var parenthesizedName = scanner.ReadUpToAndEat(") = ");
            var sectionValue      = scanner.ReadRest();

            var     keyValuePairs = new List <KeyValuePair <ParsedValue <string>, ParsedValue <string> > >();
            SubText line;

            while ((line = reader.ReadLine()) != null)
            {
                line = line.TrimStart();

                // ignore empty lines
                if (line == string.Empty)
                {
                    continue;
                }

                if (line == "End" + type)
                {
                    break;
                }

                scanner = new LineScanner(line);
                var key   = scanner.ReadUpToAndEat(" = ");
                var value = scanner.ReadRest();

                keyValuePairs.Add(new KeyValuePair <ParsedValue <string>, ParsedValue <string> >(key.Parse(), value.Parse()));
            }

            return(new SectionBlock(type.Parse(), parenthesizedName.Parse(), sectionValue.Parse(), keyValuePairs));
        }