当前位置: 首页>>代码示例>>C#>>正文


C# ILexer.NextToken方法代码示例

本文整理汇总了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);
		}
开发者ID:XQuantumForceX,项目名称:Reflexil,代码行数:56,代码来源:VBNetExpressionFinder.cs

示例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);
			}
		}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:10,代码来源:XmlModeLexerTests.cs

示例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);
			}
		}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:9,代码来源:ImplicitLineContinuationTests.cs

示例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));
			}
		}
开发者ID:XQuantumForceX,项目名称:Reflexil,代码行数:56,代码来源:VBNetExpressionFinder.cs


注:本文中的ILexer.NextToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。