Esempio n. 1
0
        public override int ColorizeLine(int line, int length, IntPtr ptr, int state, uint[] attrs)
        {
            NemerleScanner scanner = (NemerleScanner)Scanner;

            scanner._currentLine = line;
            ScanLexer lex = scanner.GetLexer();

            if (lex == null)
            {
                return(0);
            }

            lex.SetFileName(scanner._source.GetFilePath());

            int ret;

            try
            {
                ret = base.ColorizeLine(line, length, ptr, state, attrs);

                if (attrs != null && scanner._colorizeEnd)
                {
                    attrs[length] = (uint)scanner._lastColor;
                }
            }
            finally
            {
                scanner._currentLine = -1;
            }

            return(ret);
        }
Esempio n. 2
0
        public BracketFinder(NemerleSource source, int startLine,
                             int startCol, NemerleScanner scanner, IVsTextColorState colorState)
        {
            #region Init fields

            Scanner   = scanner;
            Source    = source;
            StartLine = startLine;
            Lex       = scanner.GetNewLexer();
            Lex.SetFileName(source.GetFilePath());
            ColorState = colorState;
            _lineCount = source.GetLineCount();
            var line = startLine - 1;
            _buffer = new string[1] {
                source.GetText(line, 0, line, source.GetLineLength(line))
            };
            _startBufferLine = line;

            #endregion

            #region 2. Determine that it is a paired token. 3. Determine paired token.

            // Get tokens of line under text carret into dynamic array.
            List <ScanTokenInfo> lineToks = GetLineTokens(startLine, true);
            // Find index of token which located under text carret.
            int index = FindIndex(lineToks, x => x.Token.Location.Contains(startLine, startCol));

            if (index < 0)
            {
                return;
            }

            // If index is corret get corresponding token.
            ScanTokenInfo startBraceInfo = lineToks[index];
            // Remember it, if token have paired token.
            if (IsPairedToken(startBraceInfo.Token))
            {
                StartBraceInfo = startBraceInfo;
            }
            else
            {
                // otherwise try get right-hand token...
                startBraceInfo = RightHand(lineToks, index);
                // Remember it, if token have paired token.
                if (IsPairedToken(startBraceInfo.Token))
                {
                    StartBraceInfo = startBraceInfo;
                }
            }

            #endregion
        }