Esempio n. 1
0
        private static void HandleStartIndex(ParseContext context)
        {
            // Validate follows ")", "]", or a property name.
            if (context.LastToken == null ||
                (context.LastToken.Kind != TokenKind.EndParameter && context.LastToken.Kind != TokenKind.EndIndex && context.LastToken.Kind != TokenKind.PropertyName && context.LastToken.Kind != TokenKind.ExtensionNamedValue && context.LastToken.Kind != TokenKind.UnknownKeyword))
            {
                throw new ParseException(ParseExceptionKind.UnexpectedSymbol, context.Token, context.Expression);
            }

            // Wrap the object being indexed into.
            var  indexer = new IndexerNode();
            Node obj     = null;

            if (context.Containers.Count > 0)
            {
                ContainerNode container = context.Containers.Peek().Node;
                Int32         objIndex  = container.Parameters.Count - 1;
                obj = container.Parameters[objIndex];
                container.ReplaceParameter(objIndex, indexer);
            }
            else
            {
                obj          = context.Root;
                context.Root = indexer;
            }

            indexer.AddParameter(obj);

            // Update the container stack.
            context.Containers.Push(new ContainerInfo()
            {
                Node = indexer, Token = context.Token
            });
        }
Esempio n. 2
0
        private static void HandleDereference(ParseContext context)
        {
            // Validate follows ")", "]", or a property name.
            if (context.LastToken == null ||
                (context.LastToken.Kind != TokenKind.EndParameter && context.LastToken.Kind != TokenKind.EndIndex && context.LastToken.Kind != TokenKind.PropertyName && context.LastToken.Kind != TokenKind.ExtensionNamedValue && context.LastToken.Kind != TokenKind.UnknownKeyword))
            {
                throw new ParseException(ParseExceptionKind.UnexpectedSymbol, context.Token, context.Expression);
            }

            // Wrap the object being indexed into.
            var  indexer = new IndexerNode();
            Node obj     = null;

            if (context.Containers.Count > 0)
            {
                ContainerNode container = context.Containers.Peek().Node;
                Int32         objIndex  = container.Parameters.Count - 1;
                obj = container.Parameters[objIndex];
                container.ReplaceParameter(objIndex, indexer);
            }
            else
            {
                obj          = context.Root;
                context.Root = indexer;
            }

            indexer.AddParameter(obj);

            // Validate a property name follows.
            if (!TryGetNextToken(context))
            {
                throw new ParseException(ParseExceptionKind.ExpectedPropertyName, context.LastToken, context.Expression);
            }

            if (context.Token.Kind != TokenKind.PropertyName)
            {
                throw new ParseException(ParseExceptionKind.UnexpectedSymbol, context.Token, context.Expression);
            }

            // Add the property name to the indexer, as a string.
            String propertyName = context.Token.RawValue;

            indexer.AddParameter(new LiteralValueNode(propertyName));
        }