本文整理汇总了C#中Reader.Unread方法的典型用法代码示例。如果您正苦于以下问题:C# Reader.Unread方法的具体用法?C# Reader.Unread怎么用?C# Reader.Unread使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Reader
的用法示例。
在下文中一共展示了Reader.Unread方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Tokenize
/// <summary>
/// Parses tokens from a given string.
/// </summary>
public static IEnumerable<Token> Tokenize(string input)
{
var reader = new Reader(input ?? string.Empty);
while (reader.Read() != null)
{
var ch = reader.Value;
//
// Identifier or function
//
if (ch == '-' || IsNmStart(ch))
{
reader.Mark();
if (reader.Value == '-')
{
if (!IsNmStart(reader.Read()))
throw new FormatException(string.Format("Invalid identifier at position {0}.", reader.Position));
}
while (IsNmChar(reader.Read())) { /* NOP */ }
if (reader.Value == '(')
yield return Token.Function(reader.Marked());
else
yield return Token.Ident(reader.MarkedWithUnread());
}
//
// Integer
//
else if (IsDigit(ch))
{
reader.Mark();
do { /* NOP */ } while (IsDigit(reader.Read()));
yield return Token.Integer(reader.MarkedWithUnread());
}
//
// Whitespace, including that which is coupled with some punctuation
//
else if (IsS(ch))
{
var space = ParseWhiteSpace(reader);
ch = reader.Read();
switch (ch)
{
case ',': yield return Token.Comma(); break;
case '+': yield return Token.Plus(); break;
case '>': yield return Token.Greater(); break;
case '~': yield return Token.Tilde(); break;
default:
reader.Unread();
yield return Token.WhiteSpace(space);
break;
}
}
else switch(ch)
{
case '*': // * or *=
case '~': // ~ or ~=
case '|': // | or |=
{
if (reader.Read() == '=')
{
yield return ch == '*'
? Token.SubstringMatch()
: ch == '|' ? Token.DashMatch()
: Token.Includes();
}
else
{
reader.Unread();
yield return ch == '*' || ch == '|'
? Token.Char(ch.Value)
: Token.Tilde();
}
break;
}
case '^': // ^=
case '$': // $=
{
if (reader.Read() != '=')
throw new FormatException(string.Format("Invalid character at position {0}.", reader.Position));
switch (ch)
{
case '^': yield return Token.PrefixMatch(); break;
case '$': yield return Token.SuffixMatch(); break;
}
break;
}
//
// Single-character punctuation
//
case '.': yield return Token.Dot(); break;
case ':': yield return Token.Colon(); break;
case ',': yield return Token.Comma(); break;
case '=': yield return Token.Equals(); break;
case '[': yield return Token.LeftBracket(); break;
//.........这里部分代码省略.........