本文整理汇总了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;
}