本文整理汇总了C#中ILexer.NextToken方法的典型用法代码示例。如果您正苦于以下问题:C# ILexer.NextToken方法的具体用法?C# ILexer.NextToken怎么用?C# ILexer.NextToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILexer
的用法示例。
在下文中一共展示了ILexer.NextToken方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindExpression
public ExpressionResult FindExpression(string text, int offset)
{
Init(text, offset);
ExpressionFinder p = new ExpressionFinder();
lexer = ParserFactory.CreateLexer(SupportedLanguage.VBNet, new StringReader(text));
Token t = lexer.NextToken();
// put all tokens in front of targetPosition into the EF-Parser
while (t.EndLocation < targetPosition) {
p.InformToken(t);
t = lexer.NextToken();
}
// put current token into EF-Parser if it cannot be continued (is simple operator)
if (t.EndLocation == targetPosition && ((t.Kind <= Tokens.ColonAssign && t.Kind > Tokens.Identifier) || t.Kind == Tokens.EOL)) {
p.InformToken(t);
t = lexer.NextToken();
}
// make sure semantic actions are executed
p.Advance();
// remember current state, we'll use it to determine the context
var block = p.CurrentBlock;
ExpressionContext context = p.IsIdentifierExpected && !p.IsMissingModifier ? ExpressionContext.IdentifierExpected : GetContext(block);
BitArray expectedSet;
try {
expectedSet = p.GetExpectedSet();
} catch (InvalidOperationException) {
expectedSet = null;
}
// put current token into EF-Parser
if (t.Location < targetPosition) {
p.InformToken(t);
}
if (p.Errors.Any()) {
foreach (var e in p.Errors)
LoggingService.Warn("not expected: " + e);
}
if (p.NextTokenIsPotentialStartOfExpression)
return new ExpressionResult("", new DomRegion(targetPosition.Line, targetPosition.Column), context, expectedSet);
int lastExpressionStartOffset = LocationToOffset(p.CurrentBlock.lastExpressionStart);
if (lastExpressionStartOffset < 0)
return new ExpressionResult("", new DomRegion(targetPosition.Line, targetPosition.Column), context, expectedSet);
return MakeResult(text, lastExpressionStartOffset, offset, context, expectedSet);
}
示例2: CheckTokens
void CheckTokens(ILexer lexer, params int[] tokens)
{
for (int i = 0; i < tokens.Length; i++) {
int token = tokens[i];
Token t = lexer.NextToken();
int next = t.Kind;
Assert.IsEmpty(lexer.Errors.ErrorOutput);
Assert.AreEqual(token, next, "{2} of {3}: expected: \"{0}\", was: \"{1}\"; at {4}", Tokens.GetTokenString(token), Tokens.GetTokenString(next), i + 1, tokens.Length, t.Location);
}
}
示例3: CheckTokens
void CheckTokens(ILexer lexer, params int[] tokens)
{
for (int i = 0; i < tokens.Length; i++) {
int token = tokens[i];
Token t = lexer.NextToken();
int next = t.Kind;
Assert.AreEqual(token, next, "{2} of {3}: {0} != {1}; at {4}", Tokens.GetTokenString(token), Tokens.GetTokenString(next), i + 1, tokens.Length, t.Location);
}
}
示例4: FindFullExpression
public ExpressionResult FindFullExpression(string text, int offset)
{
Init(text, offset);
ExpressionFinder p = new ExpressionFinder();
lexer = ParserFactory.CreateLexer(SupportedLanguage.VBNet, new StringReader(text));
Token t;
Block block = Block.Default;
var expressionDelimiters = new[] { Tokens.EOL, Tokens.Colon, Tokens.Dot, Tokens.TripleDot, Tokens.DotAt };
while (true) {
t = lexer.NextToken();
p.InformToken(t);
if (block == Block.Default && t.EndLocation > targetPosition)
block = p.CurrentBlock;
if (block != Block.Default && (block.isClosed || expressionDelimiters.Contains(t.Kind) && block == p.CurrentBlock))
break;
if (t.Kind == Tokens.EOF)
break;
}
if (p.Errors.Any()) {
foreach (var e in p.Errors)
LoggingService.Warn("not expected: " + e);
}
BitArray expectedSet;
try {
expectedSet = p.GetExpectedSet();
} catch (InvalidOperationException) {
expectedSet = null;
}
int tokenOffset;
if (t == null || t.Kind == Tokens.EOF)
tokenOffset = text.Length;
else
tokenOffset = LocationToOffset(t.Location);
int lastExpressionStartOffset = LocationToOffset(block.lastExpressionStart);
if (lastExpressionStartOffset >= 0) {
if (offset < tokenOffset) {
// offset is in front of this token
return MakeResult(text, lastExpressionStartOffset, tokenOffset, GetContext(block), expectedSet);
} else {
// offset is IN this token
return MakeResult(text, lastExpressionStartOffset, offset, GetContext(block), expectedSet);
}
} else {
return new ExpressionResult(null, GetContext(block));
}
}