Beispiel #1
0
        public override int Style(CodeEditor editor, int pos, int endPos)
        {
            ILexer lex = null;

            // Find a lexer that can continue lexing.
            // Use the previous state to select the right lexer.
            // As long as no lexer can be found, move the start position backward.
            while (pos >= 0 && lex == null)
                lex = FindLexerForStyle(editor.GetStyleAt(pos--));

            // start lexing from the newly determined start position
            return (lex ?? lexer.First()).Style(editor, pos + 1, endPos);
        }
Beispiel #2
0
 /// <summary>
 /// Find last position in the text that has the specified style.
 /// </summary>
 /// <param name="editor"></param>
 /// <param name="style"></param>
 /// <param name="from"></param>
 /// <returns></returns>
 protected int FindLastStyleOf(CodeEditor editor, int style, int from)
 {
     while (from > 0 && editor.GetStyleAt(from) != style)
         from--;
     return editor.GetStyleAt(from) == style ? from : -1;
 }
Beispiel #3
0
        private int ProcessBraceState(CodeEditor editor, Region c)
        {
            // is a closing brace
            if (c[-1] == '}')
            {
                int i, count, style;

                // find matching brace position
                for (i = c.Pos - 1, count = 0; i >= 0; i--)
                {
                    switch (editor.GetCharAt(i))
                    {
                        case '{': count--; break;
                        case '}': count++; break;
                    }
                    if (count == 0) break;
                }

                // if no matching brace found, exit
                if (count != 0 || i < 0)
                    return -1;

                // go to first non base state before the matching brace position
                for (style = editor.GetStyleAt(--i);
                    i >= 0 && firstBaseStyle <= style && style <= lastBaseStyle;
                    style = editor.GetStyleAt(--i))
                {
                    var C = editor.GetCharAt(i);
                    if (C == '{' || C == '}')
                        break;
                }

                // if no function lexer state found, exit
                if ((i < 0 || style < firstStyle || lastStyle < style) && style != BraceStyle)
                    return -1;
            }

            return ProcessDefaultState(editor, c);
        }