Exemple #1
0
        void LambdaExpr(out ElaExpression exp)
        {
            while (!(la.kind == 0 || la.kind == 25)) {SynErr(96); Get();}
            Expect(25);
            var lambda = new ElaLambda(t);
            exp = lambda;
            var left = default(ElaExpression);
            var right = default(ElaExpression);

            Expr(out left);
            if (la.kind == 24) {
            Get();
            Expr(out right);
            } else if (la.kind == 23) {
            Get();
            LambdaGuard(out right);
            } else SynErr(97);
            lambda.Left = left;
            lambda.Right = right;
        }
Exemple #2
0
        private void ProcessDoBlock(ElaExpression cexp1, ElaExpression cexp2, ref ElaExpression rootExp)
        {
            var eqt = default(ElaJuxtaposition);
            var lam = default(ElaLambda);
            var letb = default(ElaLetBinding);

            if (cexp2 == null)
            {
                cexp2 = cexp1;
                cexp1 = new ElaPlaceholder();
            }

            if (rootExp.Type == ElaNodeType.Juxtaposition)
                eqt = (ElaJuxtaposition)rootExp;
            else if (rootExp.Type == ElaNodeType.Lambda)
            {
                lam = (ElaLambda)rootExp;
                eqt = lam.Right as ElaJuxtaposition;
            }
            else if (rootExp.Type == ElaNodeType.LetBinding)
            {
                letb = (ElaLetBinding)rootExp;
                eqt = letb.Expression as ElaJuxtaposition;
            }
            else if (rootExp.Type != ElaNodeType.None)
            {
                eqt = new ElaJuxtaposition { Spec = true };
                eqt.SetLinePragma(cexp1.Line, cexp1.Column);
                eqt.Parameters.Add(null);
                eqt.Parameters.Add(rootExp);
            }

            if (eqt != null && !eqt.Spec)
            {
                var eqt2 = new ElaJuxtaposition();
                eqt2.SetLinePragma(eqt.Line, eqt.Column);
                eqt2.Target = new ElaNameReference(t) { Name = ">>-" };
                eqt2.Parameters.Add(null);
                eqt2.Parameters.Add(eqt);
                eqt = eqt2;
            }

            if (eqt != null && eqt.Parameters.Count == 2)
            {
                if (eqt.Parameters[0] == null)
                {
                    eqt.Target = new ElaNameReference(t) { Name = ">>=" };

                    var lambda = new ElaLambda();
                    lambda.SetLinePragma(cexp2.Line, cexp2.Column);
                    lambda.Left = new ElaPlaceholder();

                    var lambda2 = new ElaLambda();
                    lambda2.SetLinePragma(cexp2.Line, cexp2.Column);
                    lambda2.Left = cexp1;

                    var eqt1 = new ElaJuxtaposition { Spec = true };
                    eqt1.SetLinePragma(cexp2.Line, cexp2.Column);
                    eqt1.Target = new ElaNameReference(t) { Name = ">>=" };
                    eqt1.Parameters.Add(cexp2);
                    eqt1.Parameters.Add(lambda2);
                    lambda.Right = eqt1;

                    eqt.Parameters[0] = eqt.Parameters[1];
                    eqt.Parameters[1] = lambda;
                    rootExp = lambda2;
                }
                else
                {
                    throw new Exception("Unable to process do-notation.");
                }
            }
            else
            {
                if (eqt == null)
                {
                    eqt = new ElaJuxtaposition { Spec = true };
                    eqt.SetLinePragma(cexp1.Line, cexp1.Column);

                    if (lam != null)
                        lam.Right = eqt;
                    else if (letb != null)
                        letb.Expression = eqt;
                }

                eqt.Target = new ElaNameReference(t) { Name = ">>=" };
                eqt.Parameters.Add(cexp2);

                var lambda = new ElaLambda();
                lambda.SetLinePragma(cexp2.Line, cexp2.Column);
                lambda.Left = cexp1;

                eqt.Parameters.Add(lambda);
                rootExp = lambda;
            }
        }