public static VariableDeclarationExpression Parse(ExpressionWalker ew)
        {
            // ReSharper disable once UseObjectOrCollectionInitializer
            var var = new VariableDeclarationExpression();

            var.Name = StringIdentity.Parse(ew);
            ew.IsCurrentOrThrow(ExpressionToken.Equal);
            ew.NextOrThrow();

            var.Right = Expression.ParseExpression(ew);
            return(var);
        }
Beispiel #2
0
 public static ReferenceIdentity Wrap(StringIdentity iden)
 {
     return(new ReferenceIdentity(iden.Name, iden.Matches().First()));
 }
Beispiel #3
0
        public static IdentityExpression Parse(ExpressionWalker ew, Type caller = null, Expression left = null)
        {
            var ret = new IdentityExpression();

            //types:
            //justname
            //justname.accessor
            //justname.accessor[5].second
            //justname.method().someval
            //justname.method().someval[3].thatsfar

            if (left == null)
            {
                ew.IsCurrentOrThrow(ExpressionToken.Literal);
            }
            if (ew.HasNext && ew.PeakNext.WhitespacesAfterMatch == 0 && ew.PeakNext.Token == ExpressionToken.Period && caller != typeof(IdentityExpression) || left != null)
            {
                var first = left ?? ParseExpression(ew, typeof(IdentityExpression));
                ew.NextOrThrow(); //skip the predicted period.
                var next = ew.PeakNext;
                switch (next.Token)
                {
                //currently we are at Literal
                case ExpressionToken.Period:
                    ret.Identity = new PropertyIdentity(first, Parse(ew));
                    return(ret);

                case ExpressionToken.LeftBracet:
                    ret.Identity = new PropertyIdentity(first, IndexerCallExpression.Parse(ew));
                    return(ret);

                case ExpressionToken.LeftParen:
                    ret.Identity = new PropertyIdentity(first, CallExpression.Parse(ew));
                    return(ret);

                default:
                    if (left != null)
                    {
                        return(new IdentityExpression(new PropertyIdentity(left, Parse(ew, typeof(IdentityExpression), null))));
                    }

                    if (first != null)
                    {
                        //just a plain single word!
                        var right = new IdentityExpression();
                        if (ew.IsCurrent(ExpressionToken.Null))
                        {
                            right.Identity = NullIdentity.Instance;
                        }
                        else
                        {
                            ew.IsCurrentOrThrow(ExpressionToken.Literal);
                            right.Identity = StringIdentity.Create(ew.Current.Match);
                        }

                        ew.Next();
                        return(new IdentityExpression(new PropertyIdentity(first, right)));
                    }

                    goto _plain_identity;
                }
            }

_plain_identity:
            //just a plain single word!
            if (ew.IsCurrent(ExpressionToken.Null))
            {
                ret.Identity = NullIdentity.Instance;
            }
            else
            {
                ew.IsCurrentOrThrow(ExpressionToken.Literal);
                ret.Identity = StringIdentity.Create(ew.Current.Match);
            }

            ew.Next();
            return(ret);
        }