コード例 #1
0
        public override bool Equals(ExpressionBase otherBase)
        {
            var other = (otherBase as BinaryOperatorExpression);

            if (other == null)
                return false;

            if (other.Type != this.Type)
                return false;

            switch (this.Type)
            {
                case OperatorType.Add:
                case OperatorType.Multiply:
                    if (this.Left == other.Left && this.Right == other.Right ||
                        this.Left == other.Right && this.Right == other.Left)
                        return true;
                    break;
                case OperatorType.Subtract:
                case OperatorType.Divide:
                case OperatorType.Power:
                    if (this.Left.Equals(other.Left) && this.Right.Equals(other.Right))
                        return true;
                    break;
            }
            return false;
        }
コード例 #2
0
        public override Boolean Replace(ExpressionBase old, ExpressionBase replacement, bool doRecursively)
        {
            var hasReplaced = false;

            if (Object.ReferenceEquals(Left, old))
            {
                Left = replacement.Clone();
                Left.Parent = this;
                hasReplaced |= true;
            }
            else if (doRecursively)
            {
                hasReplaced |= Left.Replace(old, replacement, true);
            }

            if (Object.ReferenceEquals(Right, old))
            {
                Right = replacement.Clone();
                Right.Parent = this;
                hasReplaced |= true;
            }
            else if (doRecursively)
            {
                hasReplaced |= Right.Replace(old, replacement, true);
            }

            return hasReplaced;
        }
コード例 #3
0
        public override bool Equals(ExpressionBase otherBase)
        {
            var other = (otherBase as VariableExpression);

            if (other == null)
                return false;

            return this.value == other.value;
        }
コード例 #4
0
        public override bool Equals(ExpressionBase otherBase)
        {
            var other = (otherBase as NumericExpression);

            if (other == null)
                return false;

            return (Math.Abs(this.Number - other.Number) < double.Epsilon);
        }
コード例 #5
0
        public override bool Equals(ExpressionBase otherBase)
        {
            var other = (otherBase as DelimiterExpression);

            if (other == null)
                return false;

            return this.Expression == other.Expression;
        }
コード例 #6
0
        public override bool Equals(ExpressionBase otherBase)
        {
            var other = (otherBase as ConstantExpression);

            if (other == null)
                return false;

            return this.Type == other.Type;
        }
コード例 #7
0
        //a/c + b/c = (a+b)/c
        public static ExpressionBase AddFractionWithCommonDenominatorRule(ExpressionBase expression, List<ExpressionBase> selection)
        {
            //If expression is a sum.
            VariadicOperatorExpression variadicExpression = expression as VariadicOperatorExpression;
            if (variadicExpression != null && variadicExpression.Type == OperatorType.Add)
            {
                BinaryOperatorExpression binaryOperand;
                List<ExpressionBase> terms = new List<ExpressionBase>();
                ExpressionBase commonDenominator = null;

                //Foreach operand in sum.
                foreach (ExpressionBase operand in variadicExpression)
                {
                    //If operand is a fraction.
                    binaryOperand = operand as BinaryOperatorExpression;
                    if (binaryOperand != null && binaryOperand.Type == OperatorType.Divide)
                    {
                        //If operand is the first fraction in sum
                        if (terms.Count == 0)
                        {
                            //Add numerator to list of numerators.
                            terms.Add(binaryOperand.Left.Clone());

                            //Set commonDenominator to operand's denominator.
                            commonDenominator = binaryOperand.Right.Clone();
                        }
                        else if (commonDenominator == binaryOperand.Right)
                        {
                            //Add fraction's numerator to list if its denominator equals commenDenominator.
                            terms.Add(binaryOperand.Left.Clone());
                        }
                        else
                        {
                            //Return null if an fraction's denominator does not equals commenDenominator.
                            return null;
                        }
                    }
                    else
                    {
                        //Return if operand is not a fraction.
                        return null;
                    }
                }
                if (terms.Count > 1)
                {
                    //Initialize sum of all fractions' numerators.
                    VariadicOperatorExpression SuggestionNumerator = new VariadicOperatorExpression(OperatorType.Add, terms[0], terms[1]);
                    SuggestionNumerator.Add(terms.Skip(2).ToList());

                    //Return fraction with sum of all fractions' numerators and with their common denominator.
                    return new BinaryOperatorExpression(SuggestionNumerator, commonDenominator, OperatorType.Divide);
                }
            }
            return null;
        }
コード例 #8
0
        protected BinaryExpression(ExpressionBase left, ExpressionBase right, OperatorType type)
            : base(type)
        {
            if (left == null)
                throw new ArgumentNullException("left");
            if (right == null)
                throw new ArgumentNullException("right");

            Left = left;
            Right = right;
        }
コード例 #9
0
        protected UnaryExpression(OperatorType type, ExpressionBase expression)
            : base(type)
        {
            if (type != OperatorType.Minus)
                throw new ArgumentException("Invalid Type: " + type, "type");
            if (expression == null)
                throw new ArgumentNullException("expression");

            Expression = expression;
            Expression.Parent = this;
        }
コード例 #10
0
 public ExpressionModel(string expression, Action<ExpressionModel> onChange, params ExpressionRule[] rules)
 {
     selectionParent = null;
     selection = new List<ExpressionBase>();
     identities = new List<Identity>();
     serializer = new ExpressionSerializer();
     analyzer = new ExpressionAnalyzer();
     this.expression = serializer.Deserialize(expression);
     foreach (ExpressionRule rule in rules)
     {
         analyzer.Add(rule);
     }
     OnChanged = onChange;
     callOnChanged();
 }
コード例 #11
0
 public void ApplyIdentity(ExpressionBase identity)
 {
     ExpressionBase parent = Selected.Parent;
     if (parent == null)
     {
         expression = identity;
     }
     else
     {
         Selected.Replace(identity);
     }
     Selected.Parent = parent;
     UpdateSelection();
     UnSelectAll();
     UpdateIdentities();
 }
コード例 #12
0
        public override bool Replace(ExpressionBase old, ExpressionBase replacement, bool doRecursively)
        {
            var hasReplaced = false;

            if (Object.ReferenceEquals(Expression, old))
            {
                Expression = replacement.Clone();
                Expression.Parent = this;
                hasReplaced |= true;
            }
            else if (doRecursively)
            {
                hasReplaced |= Expression.Replace(old, replacement, true);
            }

            return hasReplaced;
        }
コード例 #13
0
 // 4^2 = 16, 4/2 = 2
 public static ExpressionBase CalculateBinaryRule(ExpressionBase expression, List<ExpressionBase> selection)
 {
     BinaryOperatorExpression binary = expression as BinaryOperatorExpression;
     if (binary != null)
     {
         int? leftNumber, rightNumber;
         leftNumber = FromNumeric(binary.Left);
         rightNumber = FromNumeric(binary.Right);
         //If left and right operands are numbers
         if (leftNumber != null && rightNumber != null)
         {
             //If expression is a power
             if (binary.Type == OperatorType.Power)
             {
                 if ((int)rightNumber > 0)
                 {
                     //Calculate and return left^right
                     int sum = 1;
                     for (int n = 0; n < (int)rightNumber; n++)
                     {
                         sum *= (int)leftNumber;
                     }
                     return ToNumeric(sum);
                 }
                 else
                 {
                     return null;
                 }
             }
             else if (binary.Type == OperatorType.Divide && (int)leftNumber % (int)rightNumber == 0)
             {
                 //If expression is a fraction return left / right
                 return ToNumeric((int)leftNumber / (int)rightNumber);
             }
             else
             {
                 return null;
             }
         }
     }
     return null;
 }
コード例 #14
0
ファイル: WhereClause.cs プロジェクト: windischb/PgSql
 public IWhereClauseConnectionBase Gte(string propertyName, object value)
 {
     _first = new ExpressionGreaterThanOrEqual(propertyName, value);
     return(this);
 }
コード例 #15
0
 public UnaryExpression(ExpressionBase innerExpression)
 {
     InnerExpression = innerExpression;
 }
コード例 #16
0
ファイル: WhereClause.cs プロジェクト: windischb/PgSql
 public IWhereClauseConnectionBase Between(string propertyName, object min, object max)
 {
     _first = new ExpressionBetween(propertyName, min, max);
     return(this);
 }
コード例 #17
0
        public override bool Evaluate(InterpreterScope scope, out ExpressionBase result)
        {
            var leaderboard = new Leaderboard();

            var stringExpression = GetStringParameter(scope, "title", out result);

            if (stringExpression == null)
            {
                return(false);
            }
            leaderboard.Title = stringExpression.Value;

            stringExpression = GetStringParameter(scope, "description", out result);
            if (stringExpression == null)
            {
                return(false);
            }
            leaderboard.Description = stringExpression.Value;

            leaderboard.Start = ProcessTrigger(scope, "start", out result);
            if (leaderboard.Start == null)
            {
                return(false);
            }

            leaderboard.Cancel = ProcessTrigger(scope, "cancel", out result);
            if (leaderboard.Cancel == null)
            {
                return(false);
            }

            leaderboard.Submit = ProcessTrigger(scope, "submit", out result);
            if (leaderboard.Submit == null)
            {
                return(false);
            }

            leaderboard.Value = ProcessValue(scope, "value", out result);
            if (leaderboard.Value == null)
            {
                return(false);
            }

            var format = GetStringParameter(scope, "format", out result);

            if (format == null)
            {
                return(false);
            }

            leaderboard.Format = Leaderboard.ParseFormat(format.Value);
            if (leaderboard.Format == ValueFormat.None)
            {
                result = new ParseErrorExpression(format.Value + " is not a supported leaderboard format", format);
                return(false);
            }

            var lowerIsBetter = GetBooleanParameter(scope, "lower_is_better", out result);

            if (lowerIsBetter == null)
            {
                return(false);
            }
            leaderboard.LowerIsBetter = lowerIsBetter.Value;

            var integerExpression = GetIntegerParameter(scope, "id", out result);

            if (integerExpression == null)
            {
                return(false);
            }
            leaderboard.Id = integerExpression.Value;

            var functionCall = scope.GetContext <FunctionCallExpression>();

            if (functionCall != null && functionCall.FunctionName.Name == this.Name.Name)
            {
                leaderboard.SourceLine = functionCall.Location.Start.Line;
            }

            var context = scope.GetContext <AchievementScriptContext>();

            Debug.Assert(context != null);
            context.Leaderboards.Add(leaderboard);
            return(true);
        }
コード例 #18
0
        public void Select(ExpressionBase expression)
        {
            expression.Selected = expression.Selected == false;

            UpdateSelection();

            UpdateIdentities();
        }
コード例 #19
0
ファイル: WhereClause.cs プロジェクト: windischb/PgSql
 public IWhereClauseConnectionBase LTreeMatch(string propertyName, string value)
 {
     _first = new ExpressionLTreeMatch(propertyName, value);
     return(this);
 }
コード例 #20
0
 public ExpressionBase <T> Optimize(ExpressionBase <T> expression) =>
 expression switch
 {
コード例 #21
0
        private static bool NormalizeNots(ref ExpressionBase expression, out ParseErrorExpression error)
        {
            error = null;

            // not a condition - don't need to worry about it
            var condition = expression as ConditionalExpression;

            if (condition == null)
            {
                return(true);
            }

            // not a not, just recurse
            if (condition.Operation != ConditionalOperation.Not)
            {
                var left = condition.Left;
                if (!NormalizeNots(ref left, out error))
                {
                    return(false);
                }

                var right = condition.Right;
                if (!NormalizeNots(ref right, out error))
                {
                    return(false);
                }

                if (!ReferenceEquals(left, condition.Left) || !ReferenceEquals(right, condition.Right))
                {
                    expression = new ConditionalExpression(left, condition.Operation, right);
                }

                return(true);
            }

            // found a not - eliminate it
            var operand = ((ConditionalExpression)expression).Right;

            // logical inversion
            condition = operand as ConditionalExpression;
            if (condition != null)
            {
                switch (condition.Operation)
                {
                case ConditionalOperation.Not:
                    // !(!A) => A
                    expression = condition.Right;
                    break;

                case ConditionalOperation.And:
                    // !(A && B) => !A || !B
                    expression = new ConditionalExpression(
                        new ConditionalExpression(null, ConditionalOperation.Not, condition.Left),
                        ConditionalOperation.Or,
                        new ConditionalExpression(null, ConditionalOperation.Not, condition.Right));
                    break;

                case ConditionalOperation.Or:
                    // !(A || B) => !A && !B
                    expression = new ConditionalExpression(
                        new ConditionalExpression(null, ConditionalOperation.Not, condition.Left),
                        ConditionalOperation.And,
                        new ConditionalExpression(null, ConditionalOperation.Not, condition.Right));
                    break;

                default:
                    throw new NotImplementedException("Unsupported condition operation");
                }

                return(NormalizeNots(ref expression, out error));
            }

            // comparative inversion
            var comparison = operand as ComparisonExpression;

            if (comparison != null)
            {
                // !(A == B) => A != B, !(A < B) => A >= B, ...
                expression = new ComparisonExpression(
                    comparison.Left,
                    ComparisonExpression.GetOppositeComparisonOperation(comparison.Operation),
                    comparison.Right);

                return(NormalizeNots(ref expression, out error));
            }

            // unsupported inversion
            error = new ParseErrorExpression("! operator cannot be applied to " + operand.Type, operand);
            return(false);
        }
コード例 #22
0
        public override bool BuildMacro(RichPresenceDisplayFunction.RichPresenceDisplayContext context, InterpreterScope scope, out ExpressionBase result)
        {
            var macro = GetStringParameter(scope, "macro", out result);

            if (macro == null)
            {
                return(false);
            }

            var expression = GetParameter(scope, "expression", out result);

            if (expression == null)
            {
                return(false);
            }

            var value = TriggerBuilderContext.GetValueString(expression, scope, out result);

            if (value == null)
            {
                return(false);
            }

            var functionCall = scope.GetContext <FunctionCallExpression>();
            var valueFormat  = GetValueFormat(macro.Value);

            context.RichPresence.AddValueField(functionCall, macro.Value, valueFormat);

            result = new StringConstantExpression(String.Format("@{0}({1})", macro.Value, value));
            return(true);
        }
コード例 #23
0
        public override bool Evaluate(InterpreterScope scope, out ExpressionBase result)
        {
            var stringExpression = GetStringParameter(scope, "format_string", out result);

            if (stringExpression == null)
            {
                return(false);
            }

            var varargs = GetParameter(scope, "varargs", out result) as ArrayExpression;

            if (varargs == null)
            {
                if (!(result is ParseErrorExpression))
                {
                    result = new ParseErrorExpression("unexpected varargs", stringExpression);
                }
                return(false);
            }

            var builder = new StringBuilder();

            var tokenizer = new PositionalTokenizer(Tokenizer.CreateTokenizer(stringExpression.Value));

            while (tokenizer.NextChar != '\0')
            {
                var token = tokenizer.ReadTo('{');
                builder.Append(token.ToString());

                if (tokenizer.NextChar == '\0')
                {
                    break;
                }

                var positionalTokenColumn = tokenizer.Column;
                tokenizer.Advance();
                if (tokenizer.NextChar == '}')
                {
                    result = new ParseErrorExpression("Empty parameter index",
                                                      stringExpression.Location.Start.Line, stringExpression.Location.Start.Column + positionalTokenColumn,
                                                      stringExpression.Location.Start.Line, stringExpression.Location.Start.Column + tokenizer.Column - 1);
                    return(false);
                }
                var index = tokenizer.ReadNumber();
                if (tokenizer.NextChar != '}')
                {
                    result = new ParseErrorExpression("Invalid positional token",
                                                      stringExpression.Location.Start.Line, stringExpression.Location.Start.Column + positionalTokenColumn,
                                                      stringExpression.Location.Start.Line, stringExpression.Location.Start.Column + tokenizer.Column - 1);
                    return(false);
                }
                tokenizer.Advance();

                Int32 parameterIndex;
                if (!Int32.TryParse(index.ToString(), out parameterIndex) ||
                    parameterIndex < 0 || parameterIndex >= varargs.Entries.Count)
                {
                    result = new ParseErrorExpression("Invalid parameter index: " + index.ToString(),
                                                      stringExpression.Location.Start.Line, stringExpression.Location.Start.Column + positionalTokenColumn,
                                                      stringExpression.Location.Start.Line, stringExpression.Location.Start.Column + tokenizer.Column - 1);
                    return(false);
                }

                result = varargs.Entries[parameterIndex];
                var functionCall = result as FunctionCallExpression;
                if (functionCall != null)
                {
                    if (!functionCall.Evaluate(scope, out result))
                    {
                        return(false);
                    }
                }

                if (result.IsLiteralConstant)
                {
                    result.AppendStringLiteral(builder);
                }
                else
                {
                    result = new ParseErrorExpression("Cannot convert expression to string", result);
                    return(false);
                }
            }

            result = new StringConstantExpression(builder.ToString());
            return(true);
        }
コード例 #24
0
ファイル: EditorViewModel.cs プロジェクト: Jamiras/RATools
        private string BuildTooltip(ExpressionBase expression)
        {
            if (expression.Location.Start.Line > 0 && expression.Location.End.Line > 0)
            {
                var text = GetText(expression.Location.Start.Line, expression.Location.Start.Column,
                                   expression.Location.End.Line, expression.Location.End.Column + 1);
                var  builder = new StringBuilder();
                bool lastCharWasWhitespace = true;
                bool inComment             = false;
                foreach (var c in text)
                {
                    if (inComment)
                    {
                        inComment = (c != '\n');
                    }
                    else if (Char.IsWhiteSpace(c))
                    {
                        if (lastCharWasWhitespace)
                        {
                            continue;
                        }

                        builder.Append(' ');
                        lastCharWasWhitespace = true;
                    }
                    else if (c == '/' && (builder.Length > 0 && builder[builder.Length - 1] == '/'))
                    {
                        inComment = true;
                        builder.Length--;

                        lastCharWasWhitespace = (builder.Length == 0 || builder[builder.Length - 1] == ' ');
                    }
                    else
                    {
                        builder.Append(c);
                        lastCharWasWhitespace = false;
                    }
                }

                if (lastCharWasWhitespace && builder.Length > 0)
                {
                    builder.Length--;
                }

                return(builder.ToString());
            }

            var tooltip = expression.ToString();
            var index   = tooltip.IndexOf(':');

            if (index >= 0)
            {
                if (tooltip[index + 1] == ' ')
                {
                    index++;
                }
                tooltip = tooltip.Substring(index + 1);
            }

            return(tooltip);
        }
コード例 #25
0
 public SubtractionExpression(ExpressionBase.IExpressionBase expr1, ExpressionBase.IExpressionBase expr2)
 {
     _expr1 = expr1;
     _expr2 = expr2;
 }
コード例 #26
0
 public void UnSelectAll()
 {
     for (int index = 0; index < selection.Count; index++)
     {
         selection[index].Selected = false;
     }
     selection.Clear();
     identities.Clear();
     selectionParent = null;
     callOnChanged();
 }
コード例 #27
0
ファイル: WhereClause.cs プロジェクト: windischb/PgSql
 public IWhereClauseConnectionBase Like(string propertyName, string value, bool ignoreCase)
 {
     _first = new ExpressionLike(propertyName, value, ignoreCase);
     return(this);
 }
コード例 #28
0
ファイル: WhereClauseOr.cs プロジェクト: windischb/PgSql
 internal WhereClauseOr(ExpressionBase firstxpressions)
 {
     Xpressions.Add(firstxpressions);
 }
コード例 #29
0
 public FunctionExpression(ExpressionBase expression, string function)
 {
     Expression = expression;
     Expression.Parent = this;
     Function = function.ToLower();
 }
コード例 #30
0
ファイル: WhereClause.cs プロジェクト: windischb/PgSql
 public IWhereClauseConnectionBase IsNotNull(string propertyName)
 {
     _first = new ExpressionIsNotNull(propertyName);
     return(this);
 }
コード例 #31
0
 public void UpdateIdentities()
 {
     UpdateSelection();
     selectionParent = analyzer.GetCommonParent(selection);
     identities = analyzer.GetIdentities(selection);
     Console.WriteLine("Identities updated");
     if (OnChanged != null)
         OnChanged(this);
 }
コード例 #32
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="expression">A C# expression that is evaluated to determine if the event should be traced or not.</param>
 public ExpressionFilter(string expression)
 {
     if (expression == null) throw new ArgumentNullException("expression");
     compiledExpression = CompileExpression(expression);
 }
コード例 #33
0
 public SubtractionExpression(ExpressionBase expression1, ExpressionBase expression2)
 {
     this.expression1 = expression1;
     this.expression2 = expression2;
 }
コード例 #34
0
ファイル: WhereClause.cs プロジェクト: windischb/PgSql
 public IWhereClauseConnectionBase Lt(string propertyName, object value)
 {
     _first = new ExpressionLowerThan(propertyName, value);
     return(this);
 }
コード例 #35
0
 public Not(ExpressionBase innerExpression)
     : base(innerExpression)
 {
 }
コード例 #36
0
 public ComputedQuestion(QLMemory memory, string name, string label, QType type, ExpressionBase expression)
     : base(memory, name, label, type)
 {
     _value = expression;
 }
コード例 #37
0
        public override bool Equals(ExpressionBase otherBase)
        {
            var other = (otherBase as FunctionExpression);

            if (other == null)
                return false;

            return this.Function == other.Function && this.Expression == other.Expression;
        }
コード例 #38
0
        protected ParseErrorExpression BuildTriggerCondition(TriggerBuilderContext context, InterpreterScope scope, ExpressionBase condition)
        {
            var            builder = new ScriptInterpreterAchievementBuilder();
            ExpressionBase result;

            if (!TriggerBuilderContext.ProcessAchievementConditions(builder, condition, scope, out result))
            {
                return((ParseErrorExpression)result);
            }

            if (builder.AlternateRequirements.Count > 0)
            {
                return(new ParseErrorExpression(Name.Name + " does not support ||'d conditions", condition));
            }

            if (builder.CoreRequirements.Count > 1)
            {
                var last = builder.CoreRequirements.Last();
                foreach (var requirement in builder.CoreRequirements)
                {
                    if (requirement.Type == RequirementType.None && !ReferenceEquals(requirement, last))
                    {
                        requirement.Type = RequirementType.AndNext;
                    }
                }
            }

            ParseErrorExpression error = ValidateSingleCondition(builder.CoreRequirements);

            if (error != null)
            {
                return(new ParseErrorExpression(error, condition));
            }

            error = ModifyRequirements(builder);
            if (error != null)
            {
                return(error);
            }

            foreach (var requirement in builder.CoreRequirements)
            {
                context.Trigger.Add(requirement);
            }

            return(null);
        }
コード例 #39
0
 public AdditionExpression(ExpressionBase.IExpressionBase expr1, ExpressionBase.IExpressionBase expr2)
 {
     _expr1 = expr1;
     _expr2 = expr2;
 }
コード例 #40
0
 public AdditionExpression(ExpressionBase exp1, ExpressionBase exp2)
 {
     _expression1 = exp1;
     _expression2 = exp2;
 }
コード例 #41
0
 public Sub(ExpressionBase leftExpression, ExpressionBase rightExpression)
     : base(leftExpression, rightExpression)
 {
 }
コード例 #42
0
ファイル: WhereClause.cs プロジェクト: windischb/PgSql
 public IWhereClauseConnectionBase Eq(string propertyName, object value)
 {
     _first = new ExpressionEqual(propertyName, value);
     return(this);
 }
コード例 #43
0
 public string Serialize(ExpressionBase expression)
 {
     return expression.ToString();
 }
コード例 #44
0
 private static ExpressionBase Parse(string input)
 {
     return(ExpressionBase.Parse(new PositionalTokenizer(Tokenizer.CreateTokenizer(input))));
 }
コード例 #45
0
ファイル: QLMemory.cs プロジェクト: MagielBruntink/poly-ql
 public void DeclareComputedValue(string name, ExpressionBase value)
 {
     _idsComputedValues[name] = value;
 }
コード例 #46
0
ファイル: LengthFunction.cs プロジェクト: Jamiras/RATools
 public override bool ReplaceVariables(InterpreterScope scope, out ExpressionBase result)
 {
     return(Evaluate(scope, out result));
 }
コード例 #47
0
 public override Boolean Replace(ExpressionBase old, ExpressionBase replacement, bool doRecursively)
 {
     return false;
 }
コード例 #48
0
 public Pos(ExpressionBase innerExpression) : base(innerExpression)
 {
 }
コード例 #49
0
 public DelimiterExpression(ExpressionBase expression)
 {
     Expression = expression;
     Expression.Parent = this;
 }
コード例 #50
0
 public Equals(ExpressionBase leftExpression, ExpressionBase rightExpression)
     : base(leftExpression, rightExpression)
 {
 }
コード例 #51
0
 public GrThEq(ExpressionBase leftExpression, ExpressionBase rightExpression)
     : base(leftExpression, rightExpression)
 {
 }
コード例 #52
0
            /// <summary>
            /// Set the new expression.
            /// </summary>
            /// <param name="newExpr">The new expression.</param>
            public void SwitchCurrentExpression(ExpressionBase newExpr)
            {
                var updateResult = true;

                // Whitespace insertion control at operators.
                if (newExpr is Operator)
                {
                    var op = (Operator)newExpr;
                    // TODO @ Parser: Still errors in whitespace insertion...

                    if (CurrentExpr == null || (CurrentExpr is Operator && ((Operator)CurrentExpr).HasRightWhitespace))
                    {
                        op.HasLeftWhitespace  = false;
                        op.HasRightWhitespace = false;
                    }
                }

                // Control the behaviour of sub- and superscript.
                if (SubAndSuperscriptExpr != null)
                {
                    if (SubAndSuperscriptType == CharType.Subscript)
                    {
                        if (SubAndSuperscriptExpr.SubScript == null)
                        {
                            SubAndSuperscriptExpr.SubScript = newExpr;
                            return;
                        }
                        else
                        {
                            SubAndSuperscriptExpr = null;
                            SubAndSuperscriptType = CharType.Unknown;
                        }
                    }
                    else
                    {
                        if (SubAndSuperscriptExpr.SuperScript == null)
                        {
                            SubAndSuperscriptExpr.SuperScript = newExpr;
                            return;
                        }
                        else
                        {
                            SubAndSuperscriptExpr = null;
                            SubAndSuperscriptType = CharType.Unknown;
                        }
                    }
                }

                // Assign new expression to current expression.
                CurrentExpr = newExpr;

                // Handle command expressions. Stop adding expressions after the required count was reached.
                if (CommandExpr != null)
                {
                    updateResult = false;
                    CommandExpr.AddEpression(CurrentExpr);
                    CurrentExpr = CommandExpr;

                    if (CommandExpr.RequiredExpressionCount == 0)
                    {
                        // Handle fractions before they are finished.
                        if (CommandExpr is Fraction)
                        {
                            FractionStackCounter--;
                        }

                        // Set the previous command expression or null.
                        if (CommandExprStack.Count > 0)
                        {
                            CommandExpr = CommandExprStack.Pop();
                        }
                        else
                        {
                            CommandExpr = null;
                        }
                    }
                }

                // Check, whether this expression is a composite expression and therefore needs input blocks.
                if (CurrentExpr is CompositeExpression && (CurrentExpr != CommandExpr) && ((CompositeExpression)CurrentExpr).RequiredExpressionCount > 0)
                {
                    if (CommandExpr != null)
                    {
                        CommandExprStack.Push(CommandExpr);
                    }
                    CommandExpr = (CompositeExpression)CurrentExpr;

                    // Handle the fraction stack.
                    if (newExpr is Fraction)
                    {
                        FractionStackCounter++;
                        ((Fraction)newExpr).IsSubFraction = FractionStackCounter > 1;
                    }
                }

                // Break here, if needed.
                if (updateResult)
                {
                    // Set the new result:
                    // - If the last result was null, copy the new expression.
                    // - Otherwise, try to cast to a block or create a new one.
                    if (Result == null)
                    {
                        Result = CurrentExpr;
                    }
                    else
                    {
                        var block = (Result is Block) ? (Block)Result : new Block()
                        {
                            Expressions = { Result }
                        };
                        block.Expressions.Add(CurrentExpr);
                        Result = block;
                    }
                }
            }
コード例 #53
0
 public Div(ExpressionBase leftExpression, ExpressionBase rightExpression)
     : base(leftExpression, rightExpression)
 {
 }
コード例 #54
0
ファイル: WhereClause.cs プロジェクト: windischb/PgSql
 public IWhereClauseConnectionBase Any(string propertyName, params object[] value)
 {
     _first = new ExpressionAny(propertyName, value);
     return(this);
 }