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


C# ITextSnapshot.ReadDelimiter方法代码示例

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


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

示例1: Parse

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

            List<SnapshotToken> leadingTrivia = new List<SnapshotToken>();
            RobotsTxtRecordSyntax currentRecord = new RobotsTxtRecordSyntax() { Document = root };
            bool lastLineWasBlankLine = false;

            foreach (ITextSnapshotLine line in snapshot.Lines)
            {
                bool isBlankLine = false;

                SnapshotPoint cursor = line.Start;
                snapshot.ReadWhiteSpace(ref cursor); // skip white space

                // skip blank lines
                if (cursor == line.End)
                {
                    if (currentRecord.Lines.Any())
                    {
                        root.Records.Add(currentRecord);
                        currentRecord = new RobotsTxtRecordSyntax { Document = root };
                    }

                    continue;
                }

                char first = cursor.GetChar();

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

                // record
                else if (Char.IsLetter(first))
                {
                    SnapshotToken name = new SnapshotToken(snapshot.ReadFieldName(ref cursor), _recordNameType);

                    // handle new record
                    if (lastLineWasBlankLine)
                    {
                        if (currentRecord.Lines.Any())
                        {
                            root.Records.Add(currentRecord);
                            currentRecord = new RobotsTxtRecordSyntax { Document = root };
                        }

                        isBlankLine = true;
                    }

                    snapshot.ReadWhiteSpace(ref cursor);
                    SnapshotToken delimiter = new SnapshotToken(snapshot.ReadDelimiter(ref cursor), _delimiterType);
                    snapshot.ReadWhiteSpace(ref cursor);
                    SnapshotToken value = new SnapshotToken(snapshot.ReadFieldValue(ref cursor), _recordValueType);
                    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);

                    RobotsTxtLineSyntax lineSyntax = new RobotsTxtLineSyntax()
                    {
                        Record = currentRecord,
                        LeadingTrivia = leadingTrivia,
                        NameToken = name,
                        DelimiterToken = delimiter,
                        ValueToken = value,
                        TrailingTrivia = trailingTrivia,
                    };
                    currentRecord.Lines.Add(lineSyntax);
                    leadingTrivia = new List<SnapshotToken>();
                }

                // error
                else
                    ; // TODO: report error

                lastLineWasBlankLine = isBlankLine;
            }

            if (leadingTrivia.Any())
            {
                if (currentRecord.Lines.Any())
                    foreach (var trivia in leadingTrivia)
                        currentRecord.TrailingTrivia.Add(trivia);
                else
                    foreach (var trivia in leadingTrivia)
                        root.LeadingTrivia.Add(trivia);
            }

            if (currentRecord.Lines.Any())
                root.Records.Add(currentRecord);

            return new SyntaxTree(snapshot, root);
        }
开发者ID:peterwie,项目名称:RobotsTxtLanguageService,代码行数:99,代码来源:RobotsTxtSyntacticParser.cs


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