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