protected override MvxSerializableBindingDescription ParseBindingDescription()
        {
            var description = new MvxSerializableBindingDescription();
            SkipWhitespace();

            while (true)
            {
                ParseNextBindingDescriptionOptionInto(description);

                SkipWhitespace();
                if (IsComplete)
                    return description;

                switch (CurrentChar)
                {
                    case ',':
                        MoveNext();
                        break;
                    case ';':
                        return description;
                    default:
                        throw new MvxException(
                            "Unexpected character {0} at position {1} in {2} - expected string-end, ',' or ';'",
                            CurrentChar,
                            CurrentIndex,
                            FullText);
                }
            }
        }
Пример #2
0
        protected override void ParseFunctionStyleBlockInto(MvxSerializableBindingDescription description, string block)
        {
            description.Function = block;
            this.MoveNext();
            if (this.IsComplete)
                throw new MvxException("Unterminated () pair for combiner {0}", block);

            var terminationFound = false;
            var sources = new List<MvxSerializableBindingDescription>();
            while (!terminationFound)
            {
                this.SkipWhitespace();
                sources.Add(this.ParseBindingDescription(ParentIsLookingForComma.ParentIsLookingForComma));
                this.SkipWhitespace();
                if (this.IsComplete)
                    throw new MvxException("Unterminated () while parsing combiner {0}", block);

                switch (this.CurrentChar)
                {
                    case ')':
                        this.MoveNext();
                        terminationFound = true;
                        break;

                    case ',':
                        this.MoveNext();
                        break;

                    default:
                        throw new MvxException("Unexpected character {0} while parsing () combiner contents for {1}", this.CurrentChar, block);
                }
            }

            description.Sources = sources.ToArray();
        }
        protected virtual void ParseNextBindingDescriptionOptionInto(MvxSerializableBindingDescription description)
        {
            if (IsComplete)
                return;

            var block = ReadTextUntilNonQuotedOccurrenceOfAnyOf(TerminatingCharacters().ToArray());
            block = block.Trim();
            if (string.IsNullOrEmpty(block))
            {
                HandleEmptyBlock(description);
                return;
            }

            switch (block)
            {
                case "Path":
                    ParseEquals(block);
                    ThrowExceptionIfPathAlreadyDefined(description);
                    description.Path = ReadTextUntilNonQuotedOccurrenceOfAnyOf(',', ';');
                    break;
                case "Converter":
                    ParseEquals(block);
                    var converter = ReadTargetPropertyName();
                    if (!string.IsNullOrEmpty(description.Converter))
                        MvxBindingTrace.Warning("Overwriting existing Converter with {0}", converter);
                    description.Converter = converter;
                    break;
                case "ConverterParameter":
                    ParseEquals(block);
                    if (description.ConverterParameter != null)
                        MvxBindingTrace.Warning("Overwriting existing ConverterParameter");
                    description.ConverterParameter = ReadValue();
                    break;
                case "CommandParameter":
                    ParseEquals(block);
                    if (!string.IsNullOrEmpty(description.Converter))
                        MvxBindingTrace.Warning("Overwriting existing Converter with CommandParameter");
                    description.Converter = "CommandParameter";
                    description.ConverterParameter = ReadValue();
                    break;
                case "FallbackValue":
                    ParseEquals(block);
                    if (description.FallbackValue != null)
                        MvxBindingTrace.Warning("Overwriting existing FallbackValue");
                    description.FallbackValue = ReadValue();
                    break;
                case "Mode":
                    ParseEquals(block);
                    //if (description.Mode != MvxBindingMode.Default)
                    //{
                    //    MvxBindingTrace.Trace(MvxTraceLevel.Warning, "Mode specified multiple times in binding in {0} - for readability either use <,>,<1,<> or use (Mode=...) - not both", FullText);
                    //}
                    description.Mode = ReadBindingMode();
                    break;
                default:
                    ParseNonKeywordBlockInto(description, block);
                    break;
            }
        }
 public MvxBindingDescription SerializableBindingToBinding(string targetName,
                                                           MvxSerializableBindingDescription description)
 {
     return new MvxBindingDescription
         {
             TargetName = targetName,
             SourcePropertyPath = description.Path,
             Converter = FindConverter(description.Converter),
             ConverterParameter = description.ConverterParameter,
             Mode = description.Mode,
             FallbackValue = description.FallbackValue
         };
 }
        private void ParseNextBindingDescriptionOptionInto(MvxSerializableBindingDescription description)
        {
            if (IsComplete)
                return;

            var block = ReadTextUntilNonQuotedOccurrenceOfAnyOf('=', ',', ';');
            block = block.Trim();
            if (string.IsNullOrEmpty(block))
            {
                return;
            }

            switch (block)
            {
                case "Path":
                    ParseEquals(block);
                    description.Path = ReadTextUntilNonQuotedOccurrenceOfAnyOf(',', ';');
                    break;
                case "Converter":
                    ParseEquals(block);
                    description.Converter = ReadTargetPropertyName();
                    break;
                case "ConverterParameter":
                    ParseEquals(block);
                    description.ConverterParameter = ReadValue();
                    break;
                case "FallbackValue":
                    ParseEquals(block);
                    description.FallbackValue = ReadValue();
                    break;
                case "Mode":
                    ParseEquals(block);
                    //if (description.Mode != MvxBindingMode.Default)
                    //{
                    //    MvxBindingTrace.Trace(MvxTraceLevel.Warning, "Mode specified multiple times in binding in {0} - for readability either use <,>,<1,<> or use (Mode=...) - not both", FullText);
                    //}
                    description.Mode = ReadBindingMode();
                    break;
                default:
                    if (!string.IsNullOrEmpty(description.Path))
                    {
                        throw new MvxException(
                            "You cannot specify Path more than once - first Path '{0}', second Path '{1}', position {2} in {3}",
                            description.Path, block, CurrentIndex, FullText);
                    }
                    description.Path = block;
                    break;
            }
        }
        protected void ParseNextBindingDescriptionOptionInto(MvxSerializableBindingDescription description)
        {
            if (IsComplete)
                return;

            var block = ReadTextUntilNonQuotedOccurrenceOfAnyOf('=', ',', ';');
            block = block.Trim();
            if (string.IsNullOrEmpty(block))
            {
                return;
            }

            switch (block)
            {
                case "Source":
                    ParseEquals(block);
                    var sourceName = ReadTextUntilNonQuotedOccurrenceOfAnyOf(',', ';');
                    description.Path = sourceName;
                    break;

                case "Converter":
                    ParseEquals(block);
                    description.Converter = ReadValidCSharpName();
                    break;

                case "Key":
                    ParseEquals(block);
                    description.ConverterParameter = ReadValue();
                    break;

                case "FallbackValue":
                    ParseEquals(block);
                    description.FallbackValue = ReadValue();
                    break;

                default:
                    if (description.ConverterParameter != null)
                    {
                        throw new MvxException(
                            "Problem parsing Language Binding near '{0}', Key set to '{1}', position {2} in {3}",
                            block, description.ConverterParameter, CurrentIndex, FullText);
                    }

                    block = UnquoteBlockIfNecessary(block);

                    description.ConverterParameter = block;
                    break;
            }
        }
        protected override void ParseNextBindingDescriptionOptionInto(MvxSerializableBindingDescription description)
        {
            if (IsComplete)
                return;

            object literal;
            if (TryReadValue(AllowNonQuotedText.DoNotAllow, out literal))
            {
                ThrowExceptionIfPathAlreadyDefined(description);
                description.Literal = literal;
                return;
            }

            base.ParseNextBindingDescriptionOptionInto(description);
        }
        protected override MvxSerializableBindingDescription ParseBindingDescription()
        {
            var description = new MvxSerializableBindingDescription
            {
                Converter = this.DefaultConverterName,
                Path      = this.DefaultTextSourceName,
                Mode      = this.DefaultBindingMode
            };

            this.SkipWhitespace();

            while (true)
            {
                this.ParseNextBindingDescriptionOptionInto(description);

                this.SkipWhitespace();
                if (this.IsComplete)
                {
                    return(description);
                }

                switch (this.CurrentChar)
                {
                case ',':
                    this.MoveNext();
                    break;

                case ';':
                    return(description);

                default:
                    throw new MvxException(
                              "Unexpected character {0} at position {1} in {2} - expected string-end, ',' or ';'",
                              this.CurrentChar,
                              this.CurrentIndex,
                              this.FullText);
                }
            }
        }
Пример #9
0
        private void DoTest(KeyValuePair <string, MvxSerializableBindingSpecification> testPair)
        {
            var language = new MvxLanguageBindingParser();
            MvxSerializableBindingSpecification result;
            var parsed = language.TryParseBindingSpecification(testPair.Key, out result);

            Assert.True(parsed, "Failed to parse " + testPair.Key);
            Assert.Single(result);
            var keyAndDescription       = testPair.Value.First();
            var resultKeyAndDescription = result.First();
            var expectedDescription     = new MvxSerializableBindingDescription()
            {
                Path               = keyAndDescription.Value.Path ?? "TextSource",
                Converter          = keyAndDescription.Value.Converter ?? "Language",
                ConverterParameter = keyAndDescription.Value.ConverterParameter,
                FallbackValue      = keyAndDescription.Value.FallbackValue,
                Mode               = MvxBindingMode.OneTime
            };

            Assert.Equal(keyAndDescription.Key, resultKeyAndDescription.Key);
            AssertAreEquivalent(expectedDescription, resultKeyAndDescription.Value);
        }
Пример #10
0
 protected void AssertAreEquivalent(MvxSerializableBindingDescription expected,
                                    MvxSerializableBindingDescription actual)
 {
     Assert.AreEqual(expected.Converter, actual.Converter);
     Assert.AreEqual(expected.ConverterParameter, actual.ConverterParameter);
     Assert.AreEqual(expected.FallbackValue, actual.FallbackValue);
     Assert.AreEqual(expected.Mode, actual.Mode);
     Assert.AreEqual(expected.Path, actual.Path);
     Assert.AreEqual(expected.Function, actual.Function);
     Assert.AreEqual(expected.Literal, actual.Literal);
     if (expected.Sources == null)
     {
         Assert.IsNull(actual.Sources);
     }
     else
     {
         Assert.AreEqual(expected.Sources.Count, actual.Sources.Count);
         for (var i = 0; i < expected.Sources.Count; i++)
         {
             AssertAreEquivalent(expected.Sources[i], actual.Sources[i]);
         }
     }
 }
Пример #11
0
        public bool TryParseBindingDescription(string text, out MvxSerializableBindingDescription requestedDescription)
        {
            if (string.IsNullOrEmpty(text))
            {
                requestedDescription = new MvxSerializableBindingDescription();
                return(false);
            }

            try
            {
                var converter = Mvx.Resolve <IMvxJsonConverter>();
                requestedDescription = converter.DeserializeObject <MvxSerializableBindingDescription>(text);
            }
            catch (Exception exception)
            {
                requestedDescription = null;
                MvxBindingTrace.Trace(MvxTraceLevel.Error,
                                      "Problem parsing Json tag for databinding {0}", exception.ToLongString());
                return(false);
            }

            return(true);
        }
        protected virtual MvxSerializableBindingDescription ParseBindingDescription(
            ParentIsLookingForComma parentIsLookingForComma)
        {
            var description = new MvxSerializableBindingDescription();
            SkipWhitespace();

            while (true)
            {
                ParseNextBindingDescriptionOptionInto(description);

                SkipWhitespace();
                if (IsComplete)
                    return description;

                switch (CurrentChar)
                {
                    case ',':
                        if (parentIsLookingForComma == ParentIsLookingForComma.ParentIsLookingForComma)
                            return description;

                        MoveNext();
                        break;

                    case ';':
                    case ')':
                        return description;

                    default:
                        if (DetectOperator())
                            ParseOperatorWithLeftHand(description);
                        else
                            throw new MvxException(
                                "Unexpected character {0} at position {1} in {2} - expected string-end, ',' or ';'",
                                CurrentChar,
                                CurrentIndex,
                                FullText);
                        break;
                }
            }
        }
 protected void ThrowExceptionIfPathAlreadyDefined(MvxSerializableBindingDescription description)
 {
     if (description.Path != null
         && description.Literal != null
         && description.Function != null)
     {
         throw new MvxException(
             "Make sure you are using ';' to separate multiple bindings. You cannot specify Path/Literal/Combiner more than once - position {0} in {1}",
             CurrentIndex, FullText);
     }
 }
        protected override MvxSerializableBindingDescription ParseBindingDescription()
        {
            var description = new MvxSerializableBindingDescription
            {
                Converter = this.DefaultConverterName,
                Path = this.DefaultTextSourceName,
                Mode = this.DefaultBindingMode
            };

            this.SkipWhitespace();

            while (true)
            {
                this.ParseNextBindingDescriptionOptionInto(description);

                this.SkipWhitespace();
                if (this.IsComplete)
                    return description;

                switch (this.CurrentChar)
                {
                    case ',':
                        this.MoveNext();
                        break;

                    case ';':
                        return description;

                    default:
                        throw new MvxException(
                            "Unexpected character {0} at position {1} in {2} - expected string-end, ',' or ';'",
                            this.CurrentChar,
                            this.CurrentIndex,
                            this.FullText);
                }
            }
        }
Пример #15
0
 protected virtual MvxSerializableBindingDescription ParseOperatorWithLeftHand(
     MvxSerializableBindingDescription description)
 {
     throw new MvxException("Operators not expected in base SwissBinding");
 }
Пример #16
0
 protected virtual void HandleEmptyBlock(MvxSerializableBindingDescription description)
 {
     // default implementation doesn't do any special handling on an empty block
 }
 private void ThrowExceptionIfPathAlreadyDefined(MvxSerializableBindingDescription description, string block)
 {
     if (!string.IsNullOrEmpty(description.Path))
     {
         throw new MvxException(
             "Make sure you are using ';' to separate multiple bindings. You cannot specify Path more than once - first Path '{0}', second Path '{1}', position {2} in {3}",
             description.Path, block, CurrentIndex, FullText);
     }
 }
Пример #18
0
        protected override MvxSerializableBindingDescription ParseOperatorWithLeftHand(MvxSerializableBindingDescription description)
        {
            // get the operator Combiner
            var twoCharacterOperatorString = this.SafePeekString(2);

            // TODO - I guess this should be done by dictionaries
            string combinerName = null;
            uint   moveFowards  = 0;

            switch (twoCharacterOperatorString)
            {
            case "!=":
                combinerName = "NotEqualTo";
                moveFowards  = 2;
                break;

            case ">=":
                combinerName = "GreaterThanOrEqualTo";
                moveFowards  = 2;
                break;

            case "<=":
                combinerName = "LessThanOrEqualTo";
                moveFowards  = 2;
                break;

            case "==":
                combinerName = "EqualTo";
                moveFowards  = 2;
                break;

            case "&&":
                combinerName = "And";
                moveFowards  = 2;
                break;

            case "||":
                combinerName = "Or";
                moveFowards  = 2;
                break;
            }

            // TODO - I guess this should be done by dictionaries
            if (combinerName == null)
            {
                switch (this.CurrentChar)
                {
                case '>':
                    combinerName = "GreaterThan";
                    moveFowards  = 1;
                    break;

                case '<':
                    combinerName = "LessThan";
                    moveFowards  = 1;
                    break;

                case '+':
                    combinerName = "Add";
                    moveFowards  = 1;
                    break;

                case '-':
                    combinerName = "Subtract";
                    moveFowards  = 1;
                    break;

                case '*':
                    combinerName = "Multiply";
                    moveFowards  = 1;
                    break;

                case '/':
                    combinerName = "Divide";
                    moveFowards  = 1;
                    break;

                case '%':
                    combinerName = "Modulus";
                    moveFowards  = 1;
                    break;

                case '!':
                    combinerName = "Inverted";
                    moveFowards  = 1;
                    break;

                case '^':
                    combinerName = "XOr";
                    moveFowards  = 1;
                    break;
                }
            }

            if (combinerName == null)
            {
                throw new MvxException("Unexpected operator starting with {0}", this.CurrentChar);
            }

            this.MoveNext(moveFowards);

            // now create the operator Combiner
            var child = new MvxSerializableBindingDescription()
            {
                Path               = description.Path,
                Literal            = description.Literal,
                Sources            = description.Sources,
                Function           = description.Function,
                Converter          = description.Converter,
                FallbackValue      = description.FallbackValue,
                ConverterParameter = description.ConverterParameter,
                Mode               = description.Mode
            };

            description.Converter          = null;
            description.ConverterParameter = null;
            description.FallbackValue      = null;
            description.Path     = null;
            description.Mode     = MvxBindingMode.Default;
            description.Literal  = null;
            description.Function = combinerName;
            description.Sources  = new List <MvxSerializableBindingDescription>()
            {
                child,
                this.ParseBindingDescription(ParentIsLookingForComma.ParentIsLookingForComma)
            };

            return(description);
        }
Пример #19
0
 private void ParseMode(string block, MvxSerializableBindingDescription description)
 {
     ParseEquals(block);
     description.Mode = ReadBindingMode();
 }
Пример #20
0
        protected virtual void ParseNextBindingDescriptionOptionInto(MvxSerializableBindingDescription description)
        {
            if (this.IsComplete)
                return;

            var block = this.ReadTextUntilNonQuotedOccurrenceOfAnyOf(this.TerminatingCharacters().ToArray());
            block = block.Trim();
            if (string.IsNullOrEmpty(block))
            {
                this.HandleEmptyBlock(description);
                return;
            }

            switch (block)
            {
                case "Path":
                    this.ParseEquals(block);
                    this.ThrowExceptionIfPathAlreadyDefined(description);
                    description.Path = this.ReadTextUntilNonQuotedOccurrenceOfAnyOf(',', ';');
                    break;

                case "Converter":
                    this.ParseEquals(block);
                    var converter = this.ReadTargetPropertyName();
                    if (!string.IsNullOrEmpty(description.Converter))
                        MvxBindingTrace.Warning("Overwriting existing Converter with {0}", converter);
                    description.Converter = converter;
                    break;

                case "ConverterParameter":
                    this.ParseEquals(block);
                    if (description.ConverterParameter != null)
                        MvxBindingTrace.Warning("Overwriting existing ConverterParameter");
                    description.ConverterParameter = this.ReadValue();
                    break;

                case "CommandParameter":
                    if (!this.IsComplete &&
                        this.CurrentChar == '(')
                    {
                        // following https://github.com/MvvmCross/MvvmCross/issues/704, if the next character is "(" then
                        // we can treat CommandParameter as a normal non-keyword block
                        this.ParseNonKeywordBlockInto(description, block);
                    }
                    else
                    {
                        this.ParseEquals(block);
                        if (!string.IsNullOrEmpty(description.Converter))
                            MvxBindingTrace.Warning("Overwriting existing Converter with CommandParameter");
                        description.Converter = "CommandParameter";
                        description.ConverterParameter = this.ReadValue();
                    }
                    break;

                case "FallbackValue":
                    this.ParseEquals(block);
                    if (description.FallbackValue != null)
                        MvxBindingTrace.Warning("Overwriting existing FallbackValue");
                    description.FallbackValue = this.ReadValue();
                    break;

                case "Mode":
                    this.ParseEquals(block);
                    //if (description.Mode != MvxBindingMode.Default)
                    //{
                    //    MvxBindingTrace.Trace(MvxTraceLevel.Warning, "Mode specified multiple times in binding in {0} - for readability either use <,>,<1,<> or use (Mode=...) - not both", FullText);
                    //}
                    description.Mode = this.ReadBindingMode();
                    break;

                default:
                    this.ParseNonKeywordBlockInto(description, block);
                    break;
            }
        }
Пример #21
0
        protected override MvxSerializableBindingDescription ParseOperatorWithLeftHand(MvxSerializableBindingDescription description)
        {
            // Parse the operator
            var parsed       = ParseTwoCharacterOperator();
            var moveForwards = parsed.Item1;
            var combinerName = parsed.Item2;

            if (combinerName == null)
            {
                var gotCombinerName = SingleCharacterOperatorCombinerNames.TryGetValue(CurrentChar, out combinerName);
                if (gotCombinerName)
                {
                    moveForwards = 1;
                }
            }

            if (combinerName == null)
            {
                throw new MvxException("Unexpected operator starting with {0}", CurrentChar);
            }

            MoveNext(moveForwards);

            // now create the operator Combiner
            var child = new MvxSerializableBindingDescription
            {
                Path               = description.Path,
                Literal            = description.Literal,
                Sources            = description.Sources,
                Function           = description.Function,
                Converter          = description.Converter,
                FallbackValue      = description.FallbackValue,
                ConverterParameter = description.ConverterParameter,
                Mode               = description.Mode
            };

            description.Converter          = null;
            description.ConverterParameter = null;
            description.FallbackValue      = null;
            description.Path     = null;
            description.Mode     = MvxBindingMode.Default;
            description.Literal  = null;
            description.Function = combinerName;
            description.Sources  = new List <MvxSerializableBindingDescription>
            {
                child,
                ParseBindingDescription(ParentIsLookingForComma.ParentIsLookingForComma)
            };

            return(description);
        }
 protected virtual MvxSerializableBindingDescription ParseOperatorWithLeftHand(
     MvxSerializableBindingDescription description)
 {
     throw new MvxException("Operators not expected in base SwissBinding");
 }
 protected virtual void HandleEmptyBlock(MvxSerializableBindingDescription description)
 {
     // default implementation doesn't do any special handling on an empty block
 }
Пример #24
0
        protected virtual void ParseNextBindingDescriptionOptionInto(MvxSerializableBindingDescription description)
        {
            if (IsComplete)
            {
                return;
            }

            var block = ReadTextUntilNonQuotedOccurrenceOfAnyOf(TerminatingCharacters().ToArray());

            block = block.Trim();
            if (string.IsNullOrEmpty(block))
            {
                HandleEmptyBlock(description);
                return;
            }

            switch (block)
            {
            case "Path":
                ParseEquals(block);
                ThrowExceptionIfPathAlreadyDefined(description);
                description.Path = ReadTextUntilNonQuotedOccurrenceOfAnyOf(',', ';');
                break;

            case "Converter":
                ParseEquals(block);
                var converter = ReadTargetPropertyName();
                if (!string.IsNullOrEmpty(description.Converter))
                {
                    MvxBindingTrace.Warning("Overwriting existing Converter with {0}", converter);
                }
                description.Converter = converter;
                break;

            case "ConverterParameter":
                ParseEquals(block);
                if (description.ConverterParameter != null)
                {
                    MvxBindingTrace.Warning("Overwriting existing ConverterParameter");
                }
                description.ConverterParameter = ReadValue();
                break;

            case "CommandParameter":
                if (!IsComplete &&
                    CurrentChar == '(')
                {
                    // following https://github.com/MvvmCross/MvvmCross/issues/704, if the next character is "(" then
                    // we can treat CommandParameter as a normal non-keyword block
                    ParseNonKeywordBlockInto(description, block);
                }
                else
                {
                    ParseEquals(block);
                    if (!string.IsNullOrEmpty(description.Converter))
                    {
                        MvxBindingTrace.Warning("Overwriting existing Converter with CommandParameter");
                    }
                    description.Converter          = "CommandParameter";
                    description.ConverterParameter = ReadValue();
                }
                break;

            case "FallbackValue":
                ParseEquals(block);
                if (description.FallbackValue != null)
                {
                    MvxBindingTrace.Warning("Overwriting existing FallbackValue");
                }
                description.FallbackValue = ReadValue();
                break;

            case "Mode":
                ParseEquals(block);
                //if (description.Mode != MvxBindingMode.Default)
                //{
                //    MvxBindingTrace.Trace(MvxTraceLevel.Warning, "Mode specified multiple times in binding in {0} - for readability either use <,>,<1,<> or use (Mode=...) - not both", FullText);
                //}
                description.Mode = ReadBindingMode();
                break;

            default:
                ParseNonKeywordBlockInto(description, block);
                break;
            }
        }
Пример #25
0
        protected override void HandleEmptyBlock(MvxSerializableBindingDescription description)
        {
            if (this.IsComplete)
                return;

            if (this.CurrentChar == '(')
            {
                this.MoveNext();
                this.ParseChildBindingDescriptionInto(description, ParentIsLookingForComma.ParentIsNotLookingForComma);

                this.SkipWhitespace();
                if (this.IsComplete || this.CurrentChar != ')')
                    throw new MvxException("Unterminated () pair");
                this.MoveNext();
                this.SkipWhitespace();
            }
        }
        protected virtual void ParseFunctionStyleBlockInto(MvxSerializableBindingDescription description, string block)
        {
            description.Converter = block;
            MoveNext();
            if (IsComplete)
                throw new MvxException("Unterminated () pair for converter {0}", block);

            ParseChildBindingDescriptionInto(description);
            SkipWhitespace();
            switch (CurrentChar)
            {
                case ')':
                    MoveNext();
                    break;

                case ',':
                    MoveNext();
                    ReadConverterParameterAndClosingBracket(description);
                    break;

                default:
                    throw new MvxException("Unexpected character {0} while parsing () contents", CurrentChar);
            }
        }
Пример #27
0
        protected override MvxSerializableBindingDescription ParseOperatorWithLeftHand(MvxSerializableBindingDescription description)
        {
            // get the operator Combiner
            var twoCharacterOperatorString = this.SafePeekString(2);

            // TODO - I guess this should be done by dictionaries
            string combinerName = null;
            uint moveFowards = 0;
            switch (twoCharacterOperatorString)
            {
                case "!=":
                    combinerName = "NotEqualTo";
                    moveFowards = 2;
                    break;

                case ">=":
                    combinerName = "GreaterThanOrEqualTo";
                    moveFowards = 2;
                    break;

                case "<=":
                    combinerName = "LessThanOrEqualTo";
                    moveFowards = 2;
                    break;

                case "==":
                    combinerName = "EqualTo";
                    moveFowards = 2;
                    break;

                case "&&":
                    combinerName = "And";
                    moveFowards = 2;
                    break;

                case "||":
                    combinerName = "Or";
                    moveFowards = 2;
                    break;
            }

            // TODO - I guess this should be done by dictionaries
            if (combinerName == null)
            {
                switch (this.CurrentChar)
                {
                    case '>':
                        combinerName = "GreaterThan";
                        moveFowards = 1;
                        break;

                    case '<':
                        combinerName = "LessThan";
                        moveFowards = 1;
                        break;

                    case '+':
                        combinerName = "Add";
                        moveFowards = 1;
                        break;

                    case '-':
                        combinerName = "Subtract";
                        moveFowards = 1;
                        break;

                    case '*':
                        combinerName = "Multiply";
                        moveFowards = 1;
                        break;

                    case '/':
                        combinerName = "Divide";
                        moveFowards = 1;
                        break;

                    case '%':
                        combinerName = "Modulus";
                        moveFowards = 1;
                        break;
                }
            }

            if (combinerName == null)
                throw new MvxException("Unexpected operator starting with {0}", this.CurrentChar);

            this.MoveNext(moveFowards);

            // now create the operator Combiner
            var child = new MvxSerializableBindingDescription()
            {
                Path = description.Path,
                Literal = description.Literal,
                Sources = description.Sources,
                Function = description.Function,
                Converter = description.Converter,
                FallbackValue = description.FallbackValue,
                ConverterParameter = description.ConverterParameter,
                Mode = description.Mode
            };

            description.Converter = null;
            description.ConverterParameter = null;
            description.FallbackValue = null;
            description.Path = null;
            description.Mode = MvxBindingMode.Default;
            description.Literal = null;
            description.Function = combinerName;
            description.Sources = new List<MvxSerializableBindingDescription>()
                {
                    child,
                    this.ParseBindingDescription(ParentIsLookingForComma.ParentIsLookingForComma)
                };

            return description;
        }
 protected void ReadConverterParameterAndClosingBracket(MvxSerializableBindingDescription description)
 {
     SkipWhitespace();
     description.ConverterParameter = ReadValue();
     SkipWhitespace();
     if (CurrentChar != ')')
         throw new MvxException("Unterminated () pair for converter {0}");
     MoveNext();
 }
Пример #29
0
 private void ParsePath(string block, MvxSerializableBindingDescription description)
 {
     ParseEquals(block);
     ThrowExceptionIfPathAlreadyDefined(description);
     description.Path = ReadTextUntilNonQuotedOccurrenceOfAnyOf(',', ';');
 }
 protected void ParseChildBindingDescriptionInto(MvxSerializableBindingDescription description,
                                                 ParentIsLookingForComma parentIsLookingForComma =
                                                     ParentIsLookingForComma.ParentIsLookingForComma)
 {
     SkipWhitespace();
     description.Function = "Single";
     description.Sources = new[]
         {
             ParseBindingDescription(parentIsLookingForComma)
         };
 }
 protected virtual void ParseNonKeywordBlockInto(MvxSerializableBindingDescription description, string block)
 {
     if (!IsComplete && CurrentChar == '(')
     {
         ParseFunctionStyleBlockInto(description, block);
     }
     else
     {
         ThrowExceptionIfPathAlreadyDefined(description);
         description.Path = block;
     }
 }
 public bool TryParseBindingDescription(string text, out MvxSerializableBindingDescription requestedDescription)
 {
     return(ChooseParser(text).TryParseBindingDescription(text, out requestedDescription));
 }