Пример #1
0
        /// <summary>
        /// Retrives the related items for a token from the remaining items list.
        /// </summary>
        /// <param name="matched">
        /// The <see cref="Token"/> the items we are looking for are related to.
        /// </param>
        /// <param name="remainingItems">
        /// A <see cref="TokenSequence"/> containing the yet to be matched items.
        /// </param>
        /// <param name="position">
        /// A <see cref="ExpressionItemPosition"/> the position of the related item.
        /// </param>
        /// <returns>
        /// A <see cref="TokenSequence"/> containing the items related to the
        /// matched item found in the given position.
        /// </returns>
        protected TokenSequence GetRelatedItems(Token matched,
                                                TokenSequence remainingItems,
                                                ExpressionItemPosition position)
        {
            TokenSequence sequence = new TokenSequence();

            string remainingItemsString = remainingItems.ToString();

            int i = 0;

            while (i < remainingItems.Count)
            {
                Token checkedItem = remainingItems[i];

                if (CheckTokenInRelatedSequence(matched, checkedItem, position))
                {
                    sequence.Append(checkedItem);
                    remainingItems.RemoveAt(i);
                }
                else if (!SpecialPosition(matched, checkedItem))
                {
                    LogSentInvoker("Encontrado {0}, cancelando la creación de la secuencia de items «{1}» {2}",
                                   checkedItem.Text,
                                   position,
                                   matched.Type);
                    break;
                }
                else
                {
                    i++;
                }
            }

            LogSentInvoker("Extraida la secuencia ({0}) en posicion «{1}» de entre los elementos de ({2})",
                           sequence,
                           position,
                           remainingItemsString);

            return(sequence);
        }
Пример #2
0
        /// <summary>
        /// Checks if a token is in a given position related to the matched token.
        /// </summary>
        /// <param name="matched">
        /// A <see cref="Token"/> which the checked token will be checked to.
        /// </param>
        /// <param name="checkedItem">
        /// A <see cref="Token"/> that we want to know if it is in the related
        /// position especified respect to the matched token.
        /// </param>
        /// <param name="position">
        /// A <see cref="ExpressionItemPosition"/> specifiying the position the
        /// checked item should be.
        /// </param>
        /// <returns>
        /// A <see cref="System.Boolean"/> indicating if the checked item is in the
        /// given position related to the matched token.
        /// </returns>
        protected bool CheckTokenInRelatedSequence(Token matched,
                                                   Token checkedItem,
                                                   ExpressionItemPosition position)
        {
            bool res = false;



            switch (position)
            {
            case ExpressionItemPosition.Above:
                // This condition is used for upper fraction operands
                // and summatory-like limit expression.
                res = checkedItem.Bottom < matched.Top;
                break;

            case ExpressionItemPosition.Below:
                // This condition is used for lower fraction operands
                // and summatory-like initialization expressions.
                res = checkedItem.Top > matched.Bottom;
                break;

            case ExpressionItemPosition.Inside:
                // This condition is used for roots' inner expressions.
                res = ((checkedItem.Left >= matched.TopmostX) &&
                       (checkedItem.Right < matched.Right) &&
                       (checkedItem.Top > matched.Top) &&
                       (checkedItem.Bottom < matched.Bottom));

                break;

            case ExpressionItemPosition.RootIndex:
                // This condition is used for roots' index expressions.
                res = ((checkedItem.Left < matched.TopmostX) &&
                       (checkedItem.Bottom < matched.Percent0_66Line));
                break;

            case ExpressionItemPosition.SubIndex:
                // This condition is used for subindexes and
                // integral-like initialization expressions.
                // We treat the comma case specialy :(
                res = (matched.Left <checkedItem.Left &&
                                     ((checkedItem.Text == "," && checkedItem.Bodyline > matched.Baseline) ||
                                      (checkedItem.Text != "," && checkedItem.Bodyline > matched.Percent0_33Line)) &&
                                     checkedItem.Baseline> matched.Percent0_75Line);

                break;

            case ExpressionItemPosition.SuperIndex:
                // This condition is used for superindexe and
                // integral-like limit expressions.

                res = (matched.Left < checkedItem.Left &&
                       checkedItem.Baseline < matched.Percent0_75Line &&
                       checkedItem.Bodyline < matched.Percent0_33Line);
                break;
            }



            return(res);
        }
		/// <summary>
		/// Checks if a token is in a given position related to the matched token.
		/// </summary>
		/// <param name="matched">
		/// A <see cref="Token"/> which the checked token will be checked to.
		/// </param>
		/// <param name="checkedItem">
		/// A <see cref="Token"/> that we want to know if it is in the related 
		/// position especified respect to the matched token.
		/// </param>
		/// <param name="position">
		/// A <see cref="ExpressionItemPosition"/> specifiying the position the 
		/// checked item should be.
		/// </param>
		/// <returns>
		/// A <see cref="System.Boolean"/> indicating if the checked item is in the
		/// given position related to the matched token.
		/// </returns>
		protected bool CheckTokenInRelatedSequence(Token matched, 
		                                          Token checkedItem, 
		                                          ExpressionItemPosition position)
		{
			
			bool res =  false;
			
		
			
			switch(position)
			{
				case ExpressionItemPosition.Above:
					// This condition is used for upper fraction operands
					// and summatory-like limit expression.
					res = checkedItem.Bottom< matched.Top;
					break;
				case ExpressionItemPosition.Below:
					// This condition is used for lower fraction operands
					// and summatory-like initialization expressions.
					res = checkedItem.Top > matched.Bottom;
					break;
				case ExpressionItemPosition.Inside:
					// This condition is used for roots' inner expressions.
					res = ((checkedItem.Left >= matched.TopmostX )
						&& (checkedItem.Right < matched.Right)
						&& (checkedItem.Top> matched.Top)
						&& (checkedItem.Bottom < matched.Bottom));
							
					break;
				case ExpressionItemPosition.RootIndex:
					// This condition is used for roots' index expressions.
					res = ((checkedItem.Left < matched.TopmostX)
					       && (checkedItem.Bottom < matched.Percent0_66Line));
					break;
				case ExpressionItemPosition.SubIndex:
					// This condition is used for subindexes and
					// integral-like initialization expressions.
					// We treat the comma case specialy :(
					res = (matched.Left< checkedItem.Left 
					       && ((checkedItem.Text =="," && checkedItem.Bodyline > matched.Baseline)
					           ||( checkedItem.Text !="," && checkedItem.Bodyline > matched.Percent0_33Line))
					       && checkedItem.Baseline > matched.Percent0_75Line);
					
					break;					
				case ExpressionItemPosition.SuperIndex:
					// This condition is used for superindexe and
					// integral-like limit expressions.
					
					res = (matched.Left < checkedItem.Left
					       && checkedItem.Baseline < matched.Percent0_75Line
					       && checkedItem.Bodyline < matched.Percent0_33Line);
					break;
			}
			
			
			
			return res;
			
		}
		/// <summary>
		/// Retrives the related items for a token from the remaining items list.
		/// </summary>
		/// <param name="matched">
		/// The <see cref="Token"/> the items we are looking for are related to.
		/// </param>
		/// <param name="remainingItems">
		/// A <see cref="TokenSequence"/> containing the yet to be matched items.
		/// </param>
		/// <param name="position">
		/// A <see cref="ExpressionItemPosition"/> the position of the related item.
		/// </param>
		/// <returns>
		/// A <see cref="TokenSequence"/> containing the items related to the
		/// matched item found in the given position.
		/// </returns>
		protected TokenSequence GetRelatedItems(Token matched,
		                                        TokenSequence remainingItems, 
		                                        ExpressionItemPosition position)
		{
			TokenSequence sequence = new TokenSequence();
			
			string remainingItemsString = remainingItems.ToString();
			
			int i= 0;
			while (i < remainingItems.Count)
			{
				Token checkedItem = remainingItems[i];
				
				if(CheckTokenInRelatedSequence(matched, checkedItem, position))
				{
					sequence.Append(checkedItem);
					remainingItems.RemoveAt(i);
				}
				else if(!SpecialPosition(matched, checkedItem))
				{
					LogSentInvoker("Encontrado {0}, cancelando la creación de la secuencia de items «{1}» {2}",
					               checkedItem.Text,
					               position,
					               matched.Type);
					break;
				}
				else
				{
					i++;
				}
			}
			
			LogSentInvoker("Extraida la secuencia ({0}) en posicion «{1}» de entre los elementos de ({2})",
			               sequence,
			               position,
			               remainingItemsString);
			
			return sequence;
		}