Beispiel #1
0
        private State ParseIndexer(Reader r, List <ExpressionNode> nodes)
        {
            var args = ArgumentListParser.Parse(r, '[', ']');

            if (args.Count == 0)
            {
                throw new ExpressionParseException(r.Position, "Indexer may not be empty.");
            }

            nodes.Add(new StringIndexerNode(args));
            return(State.AfterMember);
        }
Beispiel #2
0
        private State ParseRelativeSource(CharacterReader r, List <ExpressionNode> nodes)
        {
            var mode = IdentifierParser.Parse(r);

            if (mode == "self")
            {
                nodes.Add(new SelfNode());
            }
            else if (mode == "parent")
            {
                Type ancestorType  = null;
                var  ancestorLevel = 0;
                if (PeekOpenBracket(r))
                {
                    var args = ArgumentListParser.Parse(r, '[', ']', ';');
                    if (args.Count > 2 || args.Count == 0)
                    {
                        throw new ExpressionParseException(r.Position, "Too many arguments in RelativeSource syntax sugar");
                    }
                    else if (args.Count == 1)
                    {
                        if (int.TryParse(args[0], out int level))
                        {
                            ancestorType  = null;
                            ancestorLevel = level;
                        }
                        else
                        {
                            var typeName = ParseTypeName(new CharacterReader(args[0]));
                            ancestorType = _typeResolver(typeName.ns, typeName.typeName);
                        }
                    }
                    else
                    {
                        var typeName = ParseTypeName(new CharacterReader(args[0]));
                        ancestorType  = _typeResolver(typeName.ns, typeName.typeName);
                        ancestorLevel = int.Parse(args[1]);
                    }
                }
                nodes.Add(new FindAncestorNode(ancestorType, ancestorLevel));
            }
            else
            {
                throw new ExpressionParseException(r.Position, "Unknown RelativeSource mode.");
            }

            return(State.AfterMember);
        }