当前位置: 首页>>代码示例>>C#>>正文


C# ITextSnapshot.ReadToCommentOrLineEndWhile方法代码示例

本文整理汇总了C#中ITextSnapshot.ReadToCommentOrLineEndWhile方法的典型用法代码示例。如果您正苦于以下问题:C# ITextSnapshot.ReadToCommentOrLineEndWhile方法的具体用法?C# ITextSnapshot.ReadToCommentOrLineEndWhile怎么用?C# ITextSnapshot.ReadToCommentOrLineEndWhile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ITextSnapshot的用法示例。


在下文中一共展示了ITextSnapshot.ReadToCommentOrLineEndWhile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Parse

        public SyntaxTree Parse(ITextSnapshot snapshot)
        {
            RegistryDocumentSyntax root = new RegistryDocumentSyntax() { Snapshot = snapshot };

            List<SnapshotToken> leadingTrivia = new List<SnapshotToken>();
            RegistrySectionSyntax section = null;

            foreach (ITextSnapshotLine line in snapshot.Lines)
            {
                SnapshotPoint cursor = line.Start;
                snapshot.ReadWhiteSpace(ref cursor); // skip white space

                // read version
                if (line.LineNumber == 0)
                {
                    SnapshotToken versionToken = new SnapshotToken(snapshot.ReadToCommentOrLineEndWhile(ref cursor, _ => true), _versionType);
                    snapshot.ReadWhiteSpace(ref cursor);
                    root.VersionToken = versionToken;

                    if (snapshot.IsAtExact(cursor, RegistrySyntaxFacts.Comment))
                    {
                        SnapshotToken commentToken = new SnapshotToken(snapshot.ReadComment(ref cursor), _commentType);
                        leadingTrivia.Add(commentToken);
                    }

                    continue;
                }

                // skip blank lines
                if (cursor == line.End)
                    continue;

                char first = cursor.GetChar();

                // comment
                if (first == RegistrySyntaxFacts.Comment)
                {
                    SnapshotToken commentToken = new SnapshotToken(snapshot.ReadComment(ref cursor), _commentType);
                    leadingTrivia.Add(commentToken);
                }

                // section
                else if (first == RegistrySyntaxFacts.SectionNameOpeningBracket)
                {
                    if (section != null)
                        root.Sections.Add(section);

                    SnapshotToken deleteToken = new SnapshotToken(snapshot.ReadExact(ref cursor, RegistrySyntaxFacts.DeleteKey), _operatorType);
                    snapshot.ReadWhiteSpace(ref cursor);
                    SnapshotToken openingBracket = new SnapshotToken(snapshot.ReadExact(ref cursor, RegistrySyntaxFacts.SectionNameOpeningBracket), _delimiterType);
                    snapshot.ReadWhiteSpace(ref cursor);

                    // read key
                    SeparatedTokenListSyntax path = new SeparatedTokenListSyntax() { Section = section };

                    SnapshotToken name = new SnapshotToken(snapshot.ReadSectionName(ref cursor), _sectionNameType);
                    path.Tokens.Add(name);
                    snapshot.ReadWhiteSpace(ref cursor);

                    while (snapshot.IsAtExact(cursor, RegistrySyntaxFacts.KeySeparator))
                    {
                        SnapshotToken separator = new SnapshotToken(snapshot.ReadExact(ref cursor, RegistrySyntaxFacts.KeySeparator), _sectionNameType);
                        path.Separators.Add(separator);
                        snapshot.ReadWhiteSpace(ref cursor);

                        name = new SnapshotToken(snapshot.ReadSectionName(ref cursor), _sectionNameType);
                        path.Tokens.Add(name);
                        snapshot.ReadWhiteSpace(ref cursor);
                    }

                    SnapshotToken closingBracket = new SnapshotToken(snapshot.ReadExact(ref cursor, RegistrySyntaxFacts.SectionNameClosingBracket), _delimiterType);
                    snapshot.ReadWhiteSpace(ref cursor);
                    SnapshotToken commentToken = new SnapshotToken(snapshot.ReadComment(ref cursor), _commentType);

                    IList<SnapshotToken> trailingTrivia = new List<SnapshotToken>();
                    if (!commentToken.IsMissing)
                        trailingTrivia.Add(commentToken);

                    section = new RegistrySectionSyntax()
                    {
                        Document = root,
                        LeadingTrivia = leadingTrivia,
                        DeleteToken = deleteToken,
                        OpeningBracketToken = openingBracket,
                        NameSyntax = path,
                        ClosingBracketToken = closingBracket,
                        TrailingTrivia = trailingTrivia,
                    };
                    leadingTrivia = new List<SnapshotToken>();
                }

                // property
                else if (Char.IsLetter(first) || first == RegistrySyntaxFacts.Quote)
                {
                    // read key name
                    SnapshotToken nameOpeningQuote = new SnapshotToken(snapshot.ReadExact(ref cursor, RegistrySyntaxFacts.Quote), _stringType);
                    SnapshotToken name = new SnapshotToken(snapshot.ReadPropertyName(ref cursor), _propertyNameType);
                    SnapshotToken nameClosingQuote = new SnapshotToken(snapshot.ReadExact(ref cursor, RegistrySyntaxFacts.Quote), _stringType);

                    // delimiter
//.........这里部分代码省略.........
开发者ID:Peter-Juhasz,项目名称:RegistryLanguageService,代码行数:101,代码来源:RegistrySyntacticParser.cs


注:本文中的ITextSnapshot.ReadToCommentOrLineEndWhile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。