예제 #1
0
 public SimpleFormat(
     Location location, Expression argument, bool leftAlign, int width, FormatString formatString)
     : base(location, argument)
 {
     LeftAlign = leftAlign;
     Width = width;
     FormatString = Utilities.ThrowIfNull(formatString, "formatString");
 }
        public UnaryExpression(Location location, Operator unaryOperator, Expression operand)
            : base(location)
        {
            Operator = Utilities.ThrowIfNull(unaryOperator, "unaryOperator");
            Operand = Utilities.ThrowIfNull(operand, "operand");

            if(Operator.Token != '-')
                throw new ArgumentException(
                    Utilities.InvariantFormat("\"{0}\" is not unary operator.", Operator), "unaryOperator");
        }
        public BinaryExpression(
            Location location, Operator binaryOperator, Expression leftExpression, Expression rightExpression)
            : base(location)
        {
            Operator = Utilities.ThrowIfNull(binaryOperator, "binaryOperator");
            LeftExpression = Utilities.ThrowIfNull(leftExpression, "leftExpression");
            RightExpression = Utilities.ThrowIfNull(rightExpression, "rightExpression");

            if(!Operator.IsBinaryOperator(Operator.Token))
                throw new ArgumentException(
                    Utilities.InvariantFormat("\"{0}\" is not binary operator.", Operator), "binaryOperator");
        }
예제 #4
0
        private Expression ParseCondition(Expression implicitOperand)
        {
            if (this.nextTokenInfo.Token == Token.Else)
            {
                this.Consume();
                return new ConstantExpression(this.currentTokenInfo.Location, true, "else");
            }

            Expression condition = null;

            do
            {
                Expression andExpression = null;

                do
                {
                    if (this.nextTokenInfo.Token == Token.Else)
                    {
                        throw new FormattingException(this.nextTokenInfo.Location, "\"else\" must be used alone.");
                    }

                    Operator @operator = this.ParseOperator();

                    if ([email protected])
                    {
                        throw new FormattingException(@operator.Location, "Expected binary operator.");
                    }

                    Expression rightOperand = this.ParseUnaryExpression();

                    var expression = new BinaryExpression(
                        Location.FromRange(@operator, rightOperand), @operator, implicitOperand, rightOperand);

                    andExpression = andExpression == null
                                        ? expression
                                        : new BinaryExpression(
                                              Location.FromRange(andExpression, expression),
                                              new Operator(Location.Unknown, Token.And, string.Empty),
                                              andExpression,
                                              expression);
                }
                while (this.nextTokenInfo.Token != ':' && this.nextTokenInfo.Token != ',');

                this.Accept(',');

                condition = condition == null
                                ? andExpression
                                : new BinaryExpression(
                                      Location.FromRange(condition, andExpression),
                                      new Operator(this.currentTokenInfo.Location, ','),
                                      condition,
                                      andExpression);
            }
            while (this.nextTokenInfo.Token != ':');

            return condition;
        }
예제 #5
0
        private SimpleFormat ParseSimpleFormat(Expression argument)
        {
            bool leftAlign;
            int width;

            if (this.Accept(','))
            {
                leftAlign = this.Accept('-');
                width = int.Parse(this.Expect(Token.Integer).Text);
            }
            else
            {
                leftAlign = false;
                width = 0;
            }

            this.scanner.State = ScannerState.ScanningText;

            return new SimpleFormat(
                Location.Unknown,
                argument,
                leftAlign,
                width,
                this.Accept(':') ? this.ParseFormatString(this.currentTokenInfo.Location.Start) : FormatString.Empty);
        }
예제 #6
0
        private ConditionalFormat ParseConditionalFormat(Expression argument)
        {
            var cases = new List<Case>();

            do
            {
                int start = this.Expect('{').Location.Start;
                Expression condition = this.ParseCondition(argument);

                this.scanner.State = ScannerState.ScanningText;

                this.Expect(':');

                FormatString formatString = this.ParseFormatString(this.nextTokenInfo.Location.Start);
                int end = this.Expect('}').Location.End;

                this.scanner.State = ScannerState.ScanningTokens;

                cases.Add(new Case(new Location(start, end), condition, formatString));
            }
            while (this.nextTokenInfo.Token == '{');

            return new ConditionalFormat(Location.Unknown, argument, cases);
        }
 public ConditionalFormat(Location location, Expression argument, IEnumerable<Case> cases)
     : base(location, argument)
 {
     Cases = new ReadOnlyCollection<Case>(new List<Case>(Utilities.ThrowIfNull(cases, "cases")));
 }