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


C# TokenStream.PeekIndention方法代码示例

本文整理汇总了C#中TokenStream.PeekIndention方法的典型用法代码示例。如果您正苦于以下问题:C# TokenStream.PeekIndention方法的具体用法?C# TokenStream.PeekIndention怎么用?C# TokenStream.PeekIndention使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TokenStream的用法示例。


在下文中一共展示了TokenStream.PeekIndention方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ParseBlock

		// YOU LEFT OFF HERE
		// You were about to go through and document exactly what each indention variable meant more clearly.
		private IList<Executable> ParseBlock(TokenStream tokens, int ownerIndention, bool start)
		{
			int blockIndention = tokens.PeekIndention();
			if (start)
			{
				if (blockIndention != 0)
				{
					throw new ParserException(tokens.Peek(), "Unexpected indention");
				}
			}
			else
			{
				if (blockIndention == -1)
				{
					// This indicates the code is on the same line. Parse one line.
					// def foo(): return 42
					Executable exec = this.Parse(tokens, false, -1);
					return new List<Executable>() { exec };
				}

				if (blockIndention <= ownerIndention)
				{
					// No indention was found. But it is required.
					throw new ParserException(tokens.Peek(), "Expected: indention");
				}
			}

			int requiredIndention = blockIndention;
			
			List<Executable> code = new List<Executable>();
			while (tokens.HasMore)
			{
				int currentIndention = tokens.PeekIndention();

				// any new indention should be handled by a recursive call
				if (currentIndention > requiredIndention) throw new ParserException(tokens.Peek(), "Unexpected indention");

				// if it's indented less than the required but more than the previous, then that's not right
				// e.g.
				// def foo()
				//     x = 1
				//   return x # this is wrong
				if (currentIndention < requiredIndention && currentIndention > ownerIndention) throw new ParserException(tokens.Peek(), "Unexpected indention");

				// def foo()
				//     x = 42
				// y = 3.14 # this is no longer part of foo()
				// start is excluded because when start is true, the owner indention and current indention are the same.
				if (!start && currentIndention <= ownerIndention) return code;

				tokens.SkipWhitespace();
				if (tokens.HasMore)
				{
					code.Add(this.Parse(tokens, true, currentIndention));
				}
				else
				{
					return code;
				}
			}
			return code;
		}
开发者ID:blakeohare,项目名称:crython,代码行数:64,代码来源:ExecutableParser.cs


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