Esempio n. 1
0
 public override void Visit(KeyExpr expr)
 {
     if (expr.Target == null)
     {
         _needsAsync = true;
     }
 }
Esempio n. 2
0
        private Expr ParseIndexExpr(Expr prev)
        {
            var openBracket = Match("[");
            var next        = GetToken();

            Expr projectionFilter = null;

            if (next.Kind == "STRING" && GetToken(1).Kind == "]")
            {
                Match("STRING");
                Match("]");
                projectionFilter = new KeyExpr(GetLocation(next), prev, next.Text);
            }
            else if (next.Kind == "..")
            {
                Match("..");

                next = GetToken();
                if (next.Kind == "]")
                {
                    Match("]");
                    projectionFilter = new SliceExpr(GetLocation(openBracket), prev, null, null);
                }
                else
                {
                    var upperBound = ParseExpr();
                    projectionFilter = new SliceExpr(GetLocation(openBracket), prev, null, upperBound);
                }
            }
            else
            {
                var filter = ParseExpr();
                next = GetToken();

                if (next.Kind == "..")
                {
                    Expr upperBound = null;
                    Match("..");
                    next = GetToken();
                    if (next.Kind != "]")
                    {
                        upperBound = ParseExpr();
                    }
                    Match("]");
                    projectionFilter = new SliceExpr(GetLocation(openBracket), prev, filter, upperBound);
                }
                else
                {
                    Match("]");
                    projectionFilter = new IndexExpr(GetLocation(openBracket), prev, filter);
                }
            }

            return(projectionFilter);
        }
 public override String ToQueryPlan()
 {
     return(KeyExpr.ToExpressionStringMinPrecedenceSafe());
 }
Esempio n. 4
0
 public override void Visit(KeyExpr expr) => _needsAsyncByItself           = expr.Target == null ? true : _needsAsyncByItself;
Esempio n. 5
0
 public virtual void Visit(KeyExpr expr)
 {
 }
Esempio n. 6
0
        private Expr ParseMapProjectionExpr(Expr prev)
        {
            var bracket = Match("{");

            var projections = new List <Expr>();

            while (true)
            {
                var token = GetToken();

                if (token.Kind == "}")
                {
                    Match("}");
                    break;
                }

                string id = null;
                Expr   projection;

                if (token.Kind == "}")
                {
                    Match("}");
                    break;
                }

                if (token.Kind == "...")
                {
                    var ellipsis = Match("...");
                    var next     = GetToken();
                    projection = new SpreadExpr(GetLocation(ellipsis), ParseExpr());
                }
                else if (token.Kind == "$")
                {
                    var dollar         = Match("$");
                    var dollarLocation = GetLocation(dollar);
                    id         = Match("ID").Text;
                    projection = new KeyValuePairExpr(dollarLocation, id, new VariableExpr(dollarLocation, id));
                }
                else
                {
                    var idToken    = MatchAny(new [] { "STRING", "ID" });
                    var idLocation = GetLocation(idToken);
                    id = idToken.Text;
                    var curr = GetToken();
                    if (curr.Kind == ":")
                    {
                        Match(":");
                        projection = new KeyValuePairExpr(idLocation, id, ParseExpr());
                    }
                    else if (curr.Kind == "{")
                    {
                        // These are all equivalent:
                        // foo: foo | { a, b, c }
                        // foo | { a, b, c }
                        // foo { a, b, c }
                        MatchOptional("|");

                        var rhs = new ChainExpr(
                            new KeyExpr(idLocation, prev, id),
                            ParseExpr(),
                            ChainBehavior.ToMultipleIfArray);

                        projection = new KeyValuePairExpr(idLocation, id, rhs);
                    }
                    else if (curr.Kind == "(")
                    {
                        // key(a: 123)  =>  key: key(a:123)
                        var keyExpr = new KeyExpr(idLocation, prev, id);
                        var rhs     = ParseChainRemainder(keyExpr);

                        projection = new KeyValuePairExpr(idLocation, id, rhs);
                    }
                    else if (curr.Kind == "[?")
                    {
                        // x[? filter] => x: x[? filter]
                        var keyExpr = new KeyExpr(idLocation, prev, id);
                        var rhs     = ParseChainRemainder(keyExpr);

                        projection = new KeyValuePairExpr(idLocation, id, rhs);
                    }
                    else if (curr.Kind == "[")
                    {
                        // x[5] => x: x[5]
                        var keyExpr = new KeyExpr(idLocation, prev, id);
                        var rhs     = ParseChainRemainder(keyExpr);

                        projection = new KeyValuePairExpr(idLocation, id, rhs);
                    }
                    else if (curr.Kind == "|")
                    {
                        // These are all equivalent:
                        // foo: foo | { a, b, c }
                        // foo | { a, b, c }
                        // foo { a, b, c }
                        MatchOptional("|");

                        var rhs = new ChainExpr(
                            new KeyExpr(idLocation, prev, id),
                            ParseExpr(),
                            ChainBehavior.OneToOne);

                        projection = new KeyValuePairExpr(idLocation, id, rhs);
                    }
                    else if (curr.Kind == "|<")
                    {
                        // This is another shorthand for filtring an array of objects. These are equivalent:
                        /// foo: foo |< { a, b, c }
                        /// foo |< { a, b, c}
                        Match("|<");

                        var rhs = new ChainExpr(
                            new KeyExpr(idLocation, prev, id),
                            ParseExpr(),
                            ChainBehavior.ToMultiple);

                        projection = new KeyValuePairExpr(idLocation, id, rhs);
                    }
                    else
                    {
                        projection = new KeyValuePairExpr(idLocation, id, new KeyExpr(idLocation, null, id));
                    }
                }

                projections.Add(projection);

                var tok = MatchAny(new [] { ",", "}" });
                if (tok.Kind == "}")
                {
                    break;
                }
            }

            return(new MapProjectionExpr(GetLocation(bracket), prev, projections));
        }