private IPropertyExpression AttachedDependencyProperty(Lexemes <ˍ> lexemes)
        {
            if (lexemes.AcceptToken("("))
            {
                var xamlType = this.XamlType(lexemes);
                lexemes.AcceptToken(".");
                lexemes.AcceptTokenType(ˍ._, out var propertyName);
                if (lexemes.AcceptToken(")"))
                {
                    return(new AttachedDependencyProperty(xamlType, propertyName));
                }
            }

            return(null);
        }
Beispiel #2
0
        private Expression MagnitudeExpression(Lexemes lexemes, Expression lhs, ParseSettings parseSettings)
        {
            if (lexemes.AcceptToken(Constants.Power))
            {
                var constantExpression = this.ConstantExpression(lexemes, parseSettings);
                return(this.MagnitudeExpression(
                           lexemes,
                           new MagnitudeExpression(lhs, constantExpression),
                           parseSettings));
            }

            string exponent;

            if (lexemes.AcceptTokenType(TokenType.Exponent, out exponent))
            {
                var constantExpression =
                    new ConstantExpression(
                        double.Parse(CharacterConverter.FromExponentNotation(exponent), parseSettings.CultureInfo));
                return(this.MagnitudeExpression(
                           lexemes,
                           new MagnitudeExpression(lhs, constantExpression),
                           parseSettings));
            }

            return(lhs);
        }
Beispiel #3
0
        private Expression MultiplicativeExpression(Lexemes lexemes, Expression lhs, ParseSettings parseSettings)
        {
            if (lexemes.AcceptToken(Constants.Multiply) || lexemes.AcceptToken(Constants.MultiplyDot) ||
                lexemes.AcceptToken(Constants.MultiplyCross))
            {
                var rhs = this.TryMagnitudeExpression(lexemes, parseSettings);
                return(this.MultiplicativeExpression(lexemes, new MultiplicationExpression(lhs, rhs), parseSettings));
            }

            if (lexemes.AcceptToken(Constants.Divide))
            {
                var rhs = this.TryMagnitudeExpression(lexemes, parseSettings);
                return(this.MultiplicativeExpression(lexemes, new DivisionExpression(lhs, rhs), parseSettings));
            }

            return(lhs);
        }
        private IIndexerExpression Indexer(Lexemes <ˍ> lexemes)
        {
            if (lexemes.AcceptToken("["))
            {
                var literalList = new List <Literal>();
                this.LiteralList(lexemes, literalList);
                if (lexemes.AcceptToken("]"))
                {
                    if (lexemes.AcceptTokenType(TokenInfo.End))
                    {
                        lexemes.MoveToPrevious();
                        return(new Indexer(literalList));
                    }

                    return(new IndexerPart(literalList));
                }

                throw CreateParseException(BindingPathError.RightAngleBracketMissing, lexemes.Current);
            }

            return(null);
        }
        private XamlType XamlType(Lexemes <ˍ> lexemes)
        {
            var namespacePrefix = string.Empty;

            lexemes.AcceptTokenType(ˍ._, out var identifier);
            if (lexemes.AcceptToken(":"))
            {
                namespacePrefix = identifier;
                lexemes.AcceptTokenType(ˍ._, out identifier);
            }

            return(new XamlType(namespacePrefix, identifier));
        }
Beispiel #6
0
        private Expression PrimaryExpression(Lexemes lexemes, ParseSettings parseSettings)
        {
            if (lexemes.AcceptToken(Constants.LeftParenthesis))
            {
                var expression = this.Expression(lexemes, parseSettings);
                if (lexemes.AcceptToken(Constants.RightParenthesis))
                {
                    return(new ParenthesisExpression(expression));
                }

                throw CreateParseException(ExpressionError.RightParenthesisNotFound, lexemes.Current);
            }

            if (lexemes.AcceptToken(Constants.LeftWeakParenthesis))
            {
                var expression = this.Expression(lexemes, parseSettings);
                if (lexemes.AcceptToken(Constants.RightWeakParenthesis))
                {
                    return(expression);
                }

                throw CreateParseException(ExpressionError.RightWeakParenthesisNotFound, lexemes.Current);
            }

            string identifier;

            if (lexemes.AcceptTokenType(TokenType.Identifier, true, out identifier))
            {
                var result = this.unitExpressionParser.Parse(identifier, false);
                if (result)
                {
                    return(result.Value);
                }

                throw CreateParseException(ExpressionError.IdentifierNotFound, lexemes.MoveToPrevious(), result.Error);
            }

            return(this.ConstantExpression(lexemes, parseSettings));
        }
        private IBindingPathExpression PropertyAccessor(Lexemes <ˍ> lexemes, IBindingPathExpression lhs)
        {
            if (lexemes.AcceptToken("."))
            {
                var result = this.AttachedDependencyProperty(lexemes);
                if (result == null)
                {
                    result = this.Property(lexemes, true);
                }

                return(this.BindingPath(lexemes, new PropertyAccessor(lhs, result)));
            }

            return(lhs);
        }
        private void LiteralList(Lexemes <ˍ> lexemes, List <Literal> literalList)
        {
            XamlType castXamlType = default;

            if (lexemes.AcceptToken("("))
            {
                castXamlType = this.XamlType(lexemes);
                if (!lexemes.AcceptToken(")"))
                {
                    throw CreateParseException(BindingPathError.RightParenthesisMissing, lexemes.Current);
                }
            }

            if (!lexemes.AcceptTokenType(ˍ._, true, out var value))
            {
                throw CreateParseException(BindingPathError.ValueMissing, lexemes.Current);
            }

            literalList.Add(new Literal(castXamlType, value.Trim()));
            if (lexemes.AcceptToken(","))
            {
                this.LiteralList(lexemes, literalList);
            }
        }
        private IBindingPathExpression PrimaryExpression(Lexemes <ˍ> lexemes)
        {
            if (lexemes.AcceptToken("."))
            {
                return(new DataContextSource());
            }

            var indexerResult = this.Indexer(lexemes);

            if (indexerResult != null)
            {
                return(indexerResult);
            }

            var dependencyPropertyResult = this.AttachedDependencyProperty(lexemes);

            if (dependencyPropertyResult != null)
            {
                return(dependencyPropertyResult);
            }

            return(this.Property(lexemes, false));
        }
        private Expression MultiplicativeExpression(Lexemes lexemes, Expression lhs, ParseSettings parseSettings)
        {
            if (lexemes.AcceptToken(Constants.Multiply) || lexemes.AcceptToken(Constants.MultiplyDot)
                || lexemes.AcceptToken(Constants.MultiplyCross))
            {
                var rhs = this.TryMagnitudeExpression(lexemes, parseSettings);
                return this.MultiplicativeExpression(lexemes, new MultiplicationExpression(lhs, rhs), parseSettings);
            }

            if (lexemes.AcceptToken(Constants.Divide))
            {
                var rhs = this.TryMagnitudeExpression(lexemes, parseSettings);
                return this.MultiplicativeExpression(lexemes, new DivisionExpression(lhs, rhs), parseSettings);
            }

            return lhs;
        }
        private Expression PrimaryExpression(Lexemes lexemes, ParseSettings parseSettings)
        {
            if (lexemes.AcceptToken(Constants.LeftParenthesis))
            {
                var expression = this.Expression(lexemes, parseSettings);
                if (lexemes.AcceptToken(Constants.RightParenthesis))
                {
                    return new ParenthesisExpression(expression);
                }

                throw CreateParseException(ExpressionError.RightParenthesisNotFound, lexemes.Current);
            }

            if (lexemes.AcceptToken(Constants.LeftWeakParenthesis))
            {
                var expression = this.Expression(lexemes, parseSettings);
                if (lexemes.AcceptToken(Constants.RightWeakParenthesis))
                {
                    return expression;
                }

                throw CreateParseException(ExpressionError.RightWeakParenthesisNotFound, lexemes.Current);
            }

            string identifier;
            if (lexemes.AcceptTokenType(TokenType.Identifier, true, out identifier))
            {
                var result = this.unitExpressionParser.Parse(identifier, false);
                if (result)
                {
                    return result.Value;
                }

                throw CreateParseException(ExpressionError.IdentifierNotFound, lexemes.MoveToPrevious(), result.Error);
            }

            return this.ConstantExpression(lexemes, parseSettings);
        }
        private Expression MagnitudeExpression(Lexemes lexemes, Expression lhs, ParseSettings parseSettings)
        {
            if (lexemes.AcceptToken(Constants.Power))
            {
                var constantExpression = this.ConstantExpression(lexemes, parseSettings);
                return this.MagnitudeExpression(
                    lexemes,
                    new MagnitudeExpression(lhs, constantExpression),
                    parseSettings);
            }

            string exponent;
            if (lexemes.AcceptTokenType(TokenType.Exponent, out exponent))
            {
                var constantExpression =
                    new ConstantExpression(
                        double.Parse(CharacterConverter.FromExponentNotation(exponent), parseSettings.CultureInfo));
                return this.MagnitudeExpression(
                    lexemes,
                    new MagnitudeExpression(lhs, constantExpression),
                    parseSettings);
            }

            return lhs;
        }