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


C# TokenStream.IsNext方法代码示例

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


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

示例1: ParseLambda

		public static Expression ParseLambda(TokenStream tokens)
		{
			tokens.SkipWhitespace();
			if (tokens.IsNext("lambda"))
			{
				Token lambdaToken = tokens.PopExpected("lambda");
				List<Token> argNames = new List<Token>();
				List<Expression> argValues = new List<Expression>();

				if (!tokens.PopIfPresent(":"))
				{
					bool nextAllowed = true;
					while (!tokens.PopIfPresent(":"))
					{
						if (!nextAllowed) tokens.PopExpected(":"); // throws
						Token argName = tokens.Pop();
						if (!Util.IsIdentifier(argName)) throw new ParserException(argName, "Invalid lambda arg name.");
						Expression argValue = null;
						if (tokens.PopIfPresent("="))
						{
							argValue = ExpressionParser.Parse(tokens);
						}

						argNames.Add(argName);
						argValues.Add(argValue);

						nextAllowed = tokens.PopIfPresent(",");
					}
				}
			}

			return ParseTernary(tokens);
		}
开发者ID:blakeohare,项目名称:crython,代码行数:33,代码来源:ExpressionParser.cs

示例2: ParseEntityWithSuffix

        private static Expression ParseEntityWithSuffix(TokenStream tokens)
        {
            Expression expression = ParseRootEntity(tokens);
            bool nextAllowed;
            bool keepGoing = true;
            string next = tokens.PeekValue();

            while (keepGoing)
            {
                switch (next)
                {
                    case "[":
                        // indexing or slicing
                        Token bracketToken = tokens.Pop();
                        List<Expression> sliceComponents = new List<Expression>();
                        nextAllowed = true;
                        while (!tokens.PopIfPresent("]"))
                        {
                            if (!nextAllowed) tokens.PopExpected("]"); // throws

                            if (tokens.IsNext(":"))
                            {
                                sliceComponents.Add(null);
                            }
                            else
                            {
                                sliceComponents.Add(Parse(tokens));
                            }
                            nextAllowed = tokens.PopIfPresent(":");
                        }
                        if (nextAllowed)
                        {
                            sliceComponents.Add(null);
                        }
                        if (sliceComponents.Count == 0)
                        {
                            throw new ParserException(bracketToken, "Unexpected token.");
                        }
                        else if (sliceComponents.Count == 1)
                        {
                            expression = new IndexExpression(expression, bracketToken, sliceComponents[0]);
                        }
                        else if (sliceComponents.Count <= 3)
                        {
                            expression = new SliceExpression(expression, bracketToken, sliceComponents);
                        }
                        else
                        {
                            throw new ParserException(bracketToken, "Slice expression has too many components.");
                        }
                        break;
                    case "(":
                        // function call
                        Token openParen = tokens.Pop();
                        nextAllowed = true;
                        List<Expression> args = new List<Expression>();
                        while (!tokens.PopIfPresent(")"))
                        {
                            if (!nextAllowed) tokens.PopExpected(")"); // throws
                            args.Add(Parse(tokens));
                            nextAllowed = tokens.PopIfPresent(",");
                        }

                        expression = new FunctionInvocation(expression, args);
                        break;
                    case ".":
                        // dot field
                        Token dotToken = tokens.Pop();
                        Token fieldToken = tokens.Pop();
                        if (!Util.IsIdentifier(fieldToken))
                        {
                            throw new ParserException(fieldToken, "Invalid field.");
                        }
                        expression = new DotField(expression, dotToken, fieldToken, fieldToken.Value);
                        break;
                    default:
                        keepGoing = false;
                        break;
                }
                next = tokens.PeekValue();
            }

            return expression;
        }
开发者ID:blakeohare,项目名称:pyweek-sentientstorage,代码行数:84,代码来源:ExpressionParser.cs

示例3: ParseBooleanNot

        public static Expression ParseBooleanNot(TokenStream tokens)
        {
            tokens.SkipWhitespace();
            if (tokens.IsNext("not"))
            {
                Token notToken = tokens.Pop();
                Expression expression = ParseComparisons(tokens);
                return new Negation(notToken, expression, Negation.PrefixType.BOOLEAN_NOT);
            }

            return ParseComparisons(tokens);
        }
开发者ID:blakeohare,项目名称:pyweek-sentientstorage,代码行数:12,代码来源:ExpressionParser.cs


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