示例#1
0
        protected override void RemoveSensitiveTokens(int position, TextRangeCollection <JadeToken> tokens)
        {
            if (tokens.Count > 0)
            {
                var line  = this.TextBuffer.CurrentSnapshot.GetLineFromPosition(position);
                var index = tokens.GetFirstItemAfterPosition(line.Start);
                if (index >= 0)
                {
                    for (var i = index; i >= 0; i--)
                    {
                        if (IsAnchorToken(tokens[i].TokenType))
                        {
                            line = this.TextBuffer.CurrentSnapshot.GetLineFromPosition(tokens[i].Start);
                            break;
                        }
                    }
                }

                int start = line.Start;
                var end   = tokens[tokens.Count - 1].End;

                if (start < end)
                {
                    tokens.RemoveInRange(TextRange.FromBounds(start, end), true);
                }
            }

            base.RemoveSensitiveTokens(position, tokens);
        }
示例#2
0
        public virtual ReadOnlyTextRangeCollection <T> Tokenize(ITextProvider textProvider, int start, int length, bool excludePartialTokens)
        {
            Debug.Assert(start >= 0 && length >= 0 && start + length <= textProvider.Length);

            this._cs          = new CharacterStream(textProvider);
            this._cs.Position = start;

            this.Tokens = new TextRangeCollection <T>();

            while (!this._cs.IsEndOfStream())
            {
                // Keep on adding tokens...
                AddNextToken();

                if (this._cs.Position >= start + length)
                {
                    break;
                }
            }

            if (excludePartialTokens)
            {
                var end = start + length;

                // Exclude tokens that are beyond the specified range
                int i;
                for (i = this.Tokens.Count - 1; i >= 0; i--)
                {
                    if (this.Tokens[i].End <= end)
                    {
                        break;
                    }
                }

                i++;

                if (i < this.Tokens.Count)
                {
                    this.Tokens.RemoveRange(i, this.Tokens.Count - i);
                }
            }

            var collection = new ReadOnlyTextRangeCollection <T>(this.Tokens);

            this.Tokens = null;

            return(collection);
        }
示例#3
0
        protected static ITextRange CompareRegions(
            OutlineRegionCollection newRegions,
            OutlineRegionCollection oldRegions, int upperBound)
        {
            TextRangeCollection <OutlineRegion> oldClone = null;
            TextRangeCollection <OutlineRegion> newClone = null;

            if (oldRegions != null)
            {
                oldClone = oldRegions.Clone() as OutlineRegionCollection;
                oldClone.Sort();
            }

            newClone = newRegions.Clone() as OutlineRegionCollection;
            newClone.Sort();

            return(newClone.RangeDifference(oldClone, 0, upperBound));
        }
        /// <summary>
        /// Merges another collection into existing one. Only adds elements
        /// that are not present in this collection. Both collections must
        /// be sorted by position for the method to work properly.
        /// </summary>
        /// <param name="other"></param>
        public void Merge(TextRangeCollection <T> other)
        {
            var i     = 0;
            var j     = 0;
            var count = this.Count;

            while (true)
            {
                if (i > count - 1)
                {
                    // Add elements remaining in the other collection
                    for (; j < other.Count; j++)
                    {
                        this.Add(other[j]);
                    }

                    break;
                }

                if (j > other.Count - 1)
                {
                    break;
                }

                if (this[i].Start < other[j].Start)
                {
                    i++;
                }
                else if (other[j].Start < this[i].Start)
                {
                    this.Add(other[j++]);
                }
                else
                {
                    // Element is already in the collection
                    j++;
                }
            }

            this.Sort();
        }
示例#5
0
 public ReadOnlyTextRangeCollection(TextRangeCollection <T> collection)
 {
     this.collection = collection;
 }
 /// <summary>
 /// Override this in specific language to remove extra tokens that the new text may depend on
 /// </summary>
 /// <param name="position"></param>
 /// <param name="tokens"></param>
 protected virtual void RemoveSensitiveTokens(int position, TextRangeCollection <TTokenClass> tokens)
 {
 }
        /// <summary>
        /// Compares two collections and calculates 'changed' range. In case this collection
        /// or comparand are empty, uses lowerBound and upperBound values as range
        /// delimiters. Typically lowerBound is 0 and upperBound is lentgh of the file.
        /// </summary>
        /// <param name="otherCollection">Collection to compare to</param>
        public virtual ITextRange RangeDifference(IEnumerable <ITextRange> otherCollection, int lowerBound, int upperBound)
        {
            if (otherCollection == null)
            {
                return(TextRange.FromBounds(lowerBound, upperBound));
            }

            var other = new TextRangeCollection <ITextRange>(otherCollection);

            if (this.Count == 0 && other.Count == 0)
            {
                return(TextRange.EmptyRange);
            }

            if (this.Count == 0)
            {
                return(TextRange.FromBounds(lowerBound, upperBound));
            }

            if (other.Count == 0)
            {
                return(TextRange.FromBounds(lowerBound, upperBound));
            }

            var minCount = Math.Min(this.Count, other.Count);
            var start = 0;
            var end = 0;
            int i, j;

            for (i = 0; i < minCount; i++)
            {
                start = Math.Min(this[i].Start, other[i].Start);

                if (this[i].Start != other[i].Start || this[i].Length != other[i].Length)
                {
                    break;
                }
            }

            if (i == minCount)
            {
                if (this.Count == other.Count)
                {
                    return(TextRange.EmptyRange);
                }

                if (this.Count > other.Count)
                {
                    return(TextRange.FromBounds(Math.Min(upperBound, other[minCount - 1].Start), upperBound));
                }
                else
                {
                    return(TextRange.FromBounds(Math.Min(this[minCount - 1].Start, upperBound), upperBound));
                }
            }

            for (i = this.Count - 1, j = other.Count - 1; i >= 0 && j >= 0; i--, j--)
            {
                end = Math.Max(this[i].End, other[j].End);

                if (this[i].Start != other[j].Start || this[i].Length != other[j].Length)
                {
                    break;
                }
            }

            if (start < end)
            {
                return(TextRange.FromBounds(start, end));
            }

            return(TextRange.FromBounds(lowerBound, upperBound));
        }