Beispiel #1
0
        public void Init(VersionInstance content)
        {
            Content = content;

            LexController controller = new LexController(Content.Text, new InitTokenPush(Tokens));

            controller.Match();
        }
Beispiel #2
0
        public IncrementInfo Update(VersionInstance newContent, UpdateRange updateRange)
        {
            int lastTokenCount            = Tokens.Count;
            AffectedAreaInfo affectedArea = GetAffectedArea(updateRange);

            // The number of lines
            int lineDelta   = NumberOfNewLines(updateRange.Text) - updateRange.Range.LineSpan();
            int columnDelta = NumberOfCharactersInLastLine(updateRange.Text) - updateRange.Range.ColumnSpan();

            int indexOffset = updateRange.Text.Length - (Content.IndexOf(updateRange.Range.End) - Content.IndexOf(updateRange.Range.Start));

            // Adjust token ranges.
            for (int i = affectedArea.EndingTokenIndex; i < Tokens.Count; i++)
            {
                if (updateRange.Range.End <= Tokens[i].Range.Start)
                {
                    // Use the old content for getting the update range index.
                    int s = Content.IndexOf(Tokens[i].Range.Start) + indexOffset,
                        e = Content.IndexOf(Tokens[i].Range.End) + indexOffset;

                    // Use the new content to update the positions.
                    newContent.UpdatePosition(Tokens[i].Range.Start, s);
                    newContent.UpdatePosition(Tokens[i].Range.End, e);
                }
            }

            var           tokenInsert = new IncrementalTokenInsert(Tokens, affectedArea.StartingTokenIndex, affectedArea.EndingTokenIndex);
            LexController controller  = new LexController(newContent.Text, tokenInsert);

            // Set start range
            controller.Index  = affectedArea.StartIndex;
            controller.Line   = newContent.GetLine(controller.Index);
            controller.Column = newContent.GetColumn(controller.Index);

            controller.Match();
            Content = newContent;
            return(new IncrementInfo(affectedArea.StartingTokenIndex, affectedArea.EndingTokenIndex, Tokens.Count - lastTokenCount));
        }