本文整理汇总了C#中ILexer.Peek方法的典型用法代码示例。如果您正苦于以下问题:C# ILexer.Peek方法的具体用法?C# ILexer.Peek怎么用?C# ILexer.Peek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILexer
的用法示例。
在下文中一共展示了ILexer.Peek方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsBlockStart
internal static bool IsBlockStart(ILexer lexer, Token current, Token prev)
{
if (blockTokens.Contains(current.Kind)) {
if (current.Kind == Tokens.If) {
if (prev.Kind != Tokens.EOL)
return false;
lexer.StartPeek();
Token currentToken = null;
while ((currentToken = lexer.Peek()).Kind != Tokens.EOL) {
if (currentToken.Kind == Tokens.Then)
return lexer.Peek().Kind == Tokens.EOL;
}
}
if (current.Kind == Tokens.Function) {
lexer.StartPeek();
if (lexer.Peek().Kind == Tokens.OpenParenthesis)
return false;
}
if (current.Kind == Tokens.With && prev.Kind != Tokens.EOL)
return false;
if (current.Kind == Tokens.While && (prev.Kind == Tokens.Skip || prev.Kind == Tokens.Take))
return false;
if (current.Kind == Tokens.Select && prev.Kind != Tokens.EOL)
return false;
if (current.Kind == Tokens.Class || current.Kind == Tokens.Structure) {
lexer.StartPeek();
Token t = lexer.Peek();
if (t.Kind == Tokens.CloseParenthesis || t.Kind == Tokens.CloseCurlyBrace || t.Kind == Tokens.Comma)
return false;
}
if (current.Kind == Tokens.Module) {
lexer.StartPeek();
Token t = lexer.Peek();
if (t.Kind == Tokens.Colon)
return false;
}
if (prev.Kind == Tokens.End ||
prev.Kind == Tokens.Loop ||
prev.Kind == Tokens.Exit ||
prev.Kind == Tokens.Continue ||
prev.Kind == Tokens.Resume ||
prev.Kind == Tokens.GoTo ||
prev.Kind == Tokens.Do)
return false;
else
return true;
}
return IsSpecialCase(current, prev);
}
示例2: IsBlockStart
static bool IsBlockStart(ILexer lexer, Token current, Token prev, out bool isMultiLineLambda)
{
isMultiLineLambda = false;
if (blockTokens.Contains(current.Kind)) {
if (current.Kind == Tokens.If) {
if (prev.Kind != Tokens.EOL)
return false;
lexer.StartPeek();
Token currentToken = null;
while ((currentToken = lexer.Peek()).Kind > Tokens.EOL) {
if (currentToken.Kind == Tokens.Then)
return lexer.Peek().Kind == Tokens.EOL;
}
}
// check if it is a lambda
if (current.Kind == Tokens.Function || current.Kind == Tokens.Sub) {
lexer.StartPeek();
bool isSingleLineLambda = false;
if (lexer.Peek().Kind == Tokens.OpenParenthesis) {
isSingleLineLambda = true;
int brackets = 1;
// look for end of parameter list
while (brackets > 0) {
var t = lexer.Peek();
if (t.Kind == Tokens.OpenParenthesis)
brackets++;
if (t.Kind == Tokens.CloseParenthesis)
brackets--;
}
// expression is multi-line lambda if next Token is EOL
if (brackets == 0)
return isMultiLineLambda = (lexer.Peek().Kind == Tokens.EOL);
}
// do not indent if current token is start of single-line lambda
if (isSingleLineLambda)
return false;
}
if (current.Kind == Tokens.With && prev.Kind > Tokens.EOL)
return false;
if (current.Kind == Tokens.While && (prev.Kind == Tokens.Skip || prev.Kind == Tokens.Take))
return false;
if (current.Kind == Tokens.Select && prev.Kind > Tokens.EOL)
return false;
if (current.Kind == Tokens.Class || current.Kind == Tokens.Structure) {
lexer.StartPeek();
Token t = lexer.Peek();
if (t.Kind == Tokens.CloseParenthesis || t.Kind == Tokens.CloseCurlyBrace || t.Kind == Tokens.Comma)
return false;
}
if (current.Kind == Tokens.Module) {
lexer.StartPeek();
Token t = lexer.Peek();
if (t.Kind == Tokens.Colon)
return false;
}
if (prev.Kind == Tokens.End ||
prev.Kind == Tokens.Loop ||
prev.Kind == Tokens.Exit ||
prev.Kind == Tokens.Continue ||
prev.Kind == Tokens.Resume ||
prev.Kind == Tokens.GoTo ||
prev.Kind == Tokens.Do)
return false;
else
return true;
}
return IsSpecialCase(current, prev);
}
示例3: IsAutomaticPropertyWithDefaultValue
static bool IsAutomaticPropertyWithDefaultValue(ILexer lexer, Token currentToken, Token prevToken)
{
if (currentToken.Kind != Tokens.Property)
return false;
lexer.StartPeek();
int parenthesesNesting = 0;
// look for parameter list, = or EOL
Token t;
while ((t = lexer.Peek()).Kind != Tokens.EOF) {
if (t.Kind == Tokens.OpenParenthesis)
parenthesesNesting++;
if (t.Kind == Tokens.CloseParenthesis)
parenthesesNesting--;
if (parenthesesNesting == 0 && t.Kind == Tokens.Assign)
return true;
if (t.Kind == Tokens.EOL)
return false;
}
return false;
}
示例4: FindNextEol
static int FindNextEol(ILexer lexer)
{
lexer.StartPeek();
Token t = lexer.Peek();
while (t.Kind > Tokens.EOL) // break on EOF(0) or EOL(1)
t = lexer.Peek();
return t.Location.Line;
}
示例5: FindNextEol
static int FindNextEol(ILexer lexer)
{
lexer.StartPeek();
Token t = lexer.Peek();
while (t.Kind != Tokens.EOL)
t = lexer.Peek();
return t.Location.Line;
}