本文整理汇总了C#中ITokenStream.Advance方法的典型用法代码示例。如果您正苦于以下问题:C# ITokenStream.Advance方法的具体用法?C# ITokenStream.Advance怎么用?C# ITokenStream.Advance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITokenStream
的用法示例。
在下文中一共展示了ITokenStream.Advance方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
private ParseItemList Parse(ITextProvider text, IItemFactory itemFactory, ITokenStream stream, IParsingExecutionContext context)
{
var results = new ParseItemList();
while (!context.IsCancellationRequested && stream.Current.Type != TokenType.EndOfFile)
{
int position = stream.Position;
ParseItem item;
if (!itemFactory.TryCreate(null, text, stream, out item))
break;
if (item.Parse(itemFactory, text, stream))
results.Add(item);
// guard against infinite loop (in case token couldn't be handled)
if (stream.Position == position)
stream.Advance();
}
// freeze everything
if (!context.IsCancellationRequested)
foreach (var item in results)
item.Freeze();
return results;
}
示例2: IsValidRuleSet
public static bool IsValidRuleSet(ITokenStream stream)
{
int position = stream.Position;
try
{
bool seenColon = false;
var previous = stream.Current;
while (stream.Advance().Type != TokenType.EndOfFile)
{
var curent = stream.Current;
// selector body
if (curent.Type == TokenType.OpenCurlyBrace) return true;
// parent terminator
if (curent.Type == TokenType.CloseCurlyBrace) return false;
// property terminator
if (curent.Type == TokenType.Semicolon) return false;
if (curent.Type == TokenType.Colon)
{
seenColon = true;
var next = stream.Advance();
// if space after colon, then we are in a property
if (curent.End != next.Start) return false;
// if next value is not identifer or function, then we are a property
if (!(next.Type == TokenType.Identifier || next.Type == TokenType.Function)) return false;
}
// check for space
if (curent.Start != previous.End && !seenColon) return true;
previous = stream.Current;
}
}
finally
{
stream.SeekTo(position);
}
return false;
}
示例3: Parse
public override bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
{
if (stream.Current.Type != TokenType.EndOfFile)
{
var token = stream.Current;
_Start = token.Start;
_Length = token.Length;
_End = _Start + _Length;
SourceType = token.Type;
stream.Advance();
return true;
}
return false;
}
示例4: IsValidName
public static bool IsValidName(ITokenStream stream)
{
int start = stream.Position;
var lastToken = stream.Current;
bool valid = false;
while (IsValidNameComponent(stream.Current.Type))
{
valid = true;
if (stream.Advance().Start != lastToken.End)
break;
lastToken = stream.Current;
}
stream.SeekTo(start);
return valid;
}
示例5: Parse
public override bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
{
if (stream.Current.Type == TokenType.StartOfFile)
{
stream.Advance();
while (stream.Current.Type != TokenType.EndOfFile)
{
int position = stream.Position;
ParseItem item;
if (itemFactory.TryCreateParsedOrDefault(this, text, stream, out item))
{
Children.Add(item);
}
else if (stream.Position == position)
{
// add current token if and only if we didn't move position at all
Children.AddCurrentAndAdvance(stream);
}
}
}
return Children.Count > 0;
}
示例6: IsDeclaration
public static bool IsDeclaration(ITextProvider text, ITokenStream stream)
{
int position = stream.Position;
bool validPropertyName = false;
while (true)
{
var last = stream.Current;
var next = stream.Advance();
if (next.Start > last.End || IsDeclarationTerminator(last.Type))
break;
if (next.Type == TokenType.Colon)
{
var value = stream.Peek(1);
switch (value.Type)
{
case TokenType.Ampersand:
validPropertyName = false;
break;
case TokenType.Identifier:
case TokenType.Function:
validPropertyName = value.Start > next.End || !IsPseudoSelector(text, value);
break;
default:
validPropertyName = true;
break;
}
break;
}
}
stream.SeekTo(position);
return validPropertyName;
}