public ParseError(string NewDescription, int NewBegin, int NewLength)
 {
     TextPortion        = new TextPortion();
     Description        = NewDescription;
     TextPortion.Begin  = NewBegin;
     TextPortion.Length = NewLength;
 }
        /// <summary>
        /// Checks if Pattern equals the text, but does not change the struct
        /// </summary>
        public bool Compare(TextPortion Pattern, bool IgnoreCase)
        {
            if (_Length != Pattern._Length)
            {
                return(false);
            }

            return(Match(Pattern, IgnoreCase));
        }
        private bool Add(TextPortionTree <T> Item)
        {
            TextPortion tp = Item._TP;

            if (_TP.IsInit && !_TP.PortionInPortion(tp))
            {
                return(false);
            }

            for (int i = 0; i < _Children.Count; i++)
            {
                var ch  = _Children[i];
                var tpt = ch._TP;
                if (tp.End <= tpt.Begin)
                //New is before ch
                {
                    _Children.Insert(i, Item);
                    return(true);
                }
                else if (tp.Begin >= tpt.End)
                //New is after ch
                {
                    //Nothing to do; just for clarity (so to not include in the next else-ifs)
                }
                else if (tpt.PortionInPortion(tp))
                {
                    //New is in ch
                    return(ch.Add(Item));
                }
                else if (tp.PortionInPortion(tpt))
                //New contains ch (and maybe others
                {
                    int j;
                    for (j = i + 1; j < _Children.Count; j++)
                    {
                        if (_Children[j]._TP.Begin >= tp.End)
                        {
                            break;
                        }
                    }
                    Item._Children.AddRange(_Children.GetRange(i, j - i));
                    _Children.RemoveRange(i, j - i);
                    _Children.Insert(i, Item);
                    return(true);
                }
                else if ((tp.Begin < tpt.Begin) == (tp.End < tpt.End))
                {
                    //They interleave
                    return(false);
                }
            }

            //New is after the end of the list
            _Children.Add(Item);

            return(true);
        }
        /// <summary>
        /// Joins two TextPortions
        /// </summary>
        public void Append(TextPortion Other)
        {
            if (TryAppend(Other))
            {
                return;
            }

            Text   = ToString() + Other.ToString();
            _Begin = 0;
            Length = Text.Length;
        }
        public TextPortion(TextPortion rhs)
        {
            Text    = rhs.Text;
            _Begin  = rhs._Begin;
            _Length = rhs.Length;

            if (Text != null)
            {
                Debug.Assert((_Begin + _Length) <= Text.Length);
            }
        }
 private void UpdateTP()
 {
     if (_Children.Count == 0)
     {
         _TP = string.Empty;
     }
     else
     {
         _TP.Begin = _Children[0]._TP.Begin;
         _TP.End   = _Children[_Children.Count - 1]._TP.End;
     }
 }
 public ParseError(string newDescription, Match LastMatch, int newLength = 10)
 {
     TextPortion = new TextPortion();
     Description = newDescription;
     if (LastMatch != null)
     {
         TextPortion.Begin = LastMatch.Index + LastMatch.Length;
     }
     else
     {
         TextPortion.Begin = 0;
     }
     TextPortion.Length = newLength;
 }
        /// <summary>
        /// Try to join two TextPortions if they refer to the same string and are adjacent
        /// </summary>
        public bool TryAppend(TextPortion Other)
        {
            if (Other.Length == 0)
            {
                return(true);
            }

            if (ReferenceEquals(Text, Other.Text) && (End == Other._Begin))
            {
                End = Other.End;
                return(true);
            }

            return(false);
        }
            public void CopyFrom(Annotation Other)
            {
                Element             = Other.Element;
                FirstRunnable       = Other.FirstRunnable;
                RunnableParentBlock = Other.RunnableParentBlock;
                RunnablesCount      = Other.RunnablesCount;

                TreeViewNode = Other.TreeViewNode;
                ListViewItem = Other.ListViewItem;

                SourcePosition   = Other.SourcePosition;
                CompiledPosition = Other.CompiledPosition;

                IDE = Other.IDE;
            }
        /// <summary>
        /// Checks if Pattern is at the beginning of the text and updates the struct
        /// </summary>
        public bool Match(TextPortion Pattern, bool IgnoreCase)
        {
            if (Pattern.Length > Length)
            {
                return(false);
            }

            if (string.Compare(Text, _Begin, Pattern.Text, Pattern._Begin, Pattern.Length, IgnoreCase) != 0)
            {
                return(false);
            }

            MoveCaret(Pattern.Length);

            return(true);
        }
        public bool Add(TextPortion newItem, T newTag)
        {
            TextPortionTree <T> ch = new TextPortionTree <T>(newItem, newTag);

            ch._Tag = newTag;

            _TP = new TextPortion();

            if (!Add(ch))
            {
                return(false);
            }

            UpdateTP();

            return(true);
        }
 public ParseError(string newDescription, TextPortion NewTextPortion)
 {
     Description = newDescription;
     TextPortion = NewTextPortion;
 }
 private TextPortionTree(TextPortion newTP, T newTag)
 {
     _Tag = newTag;
     _TP  = newTP;
 }
 public bool PortionInPortion(TextPortion Other)
 {
     return((Other._Begin >= _Begin) && (Other.End <= End));
 }