예제 #1
0
        public void Style(int startPos, int endPos)
        {
            var line = _scintilla.LineFromPosition(startPos);

            startPos = _scintilla.Lines[line].Position;

            var lastDivider = startPos;

            _scintilla.StartStyling(startPos);
            while (startPos < endPos)
            {
                int divider = FirstDivider(startPos, _scintilla.Text);
                if (divider == -1)
                {
                    divider = endPos;
                }
                if (divider - lastDivider == 1)
                {
                    startPos++;
                    lastDivider = divider;
                    continue;
                }
                string word = _scintilla.Text.Substring(lastDivider, divider - lastDivider - 1);
                if (_keywords.Contains(word.ToUpper()))
                {
                    if (word.ToUpper().Equals("EQL"))
                    {
                        _isEql = true;
                    }
                    ProcessLastWord();
                    SetStyle(word.Length, StyleKeyword);
                }
                else if (word[0] <= '9' && word[0] >= '0')
                {
                    try {
                        CompilerSupport.ConvertToInt(word);
                        ProcessLastWord();
                        SetStyle(word.Length, StyleNumber);
                    } catch {
                        lastDivider = _scintilla.Text.IndexOf(Environment.NewLine, divider + 1, StringComparison.Ordinal);
                        if (lastDivider == -1)
                        {
                            startPos = endPos;
                        }
                        else
                        {
                            startPos = lastDivider + 1;
                        }
                        SetStyle(word.Length, StyleError);
                        SetStyle(lastDivider - divider, StyleDefault);
                        continue;
                    }
                }
                else if (_identities.Contains(word))
                {
                    ProcessLastWord();
                    SetStyle(word.Length, StyleIdentifier);
                }
                else
                {
                    ProcessLastWord();
                    _lastWord = word;
                }
                if (divider >= _scintilla.Text.Length)
                {
                    break;
                }
                if (_scintilla.Text[divider] == ';')
                {
                    int newLine = _scintilla.Text.IndexOf(Environment.NewLine, divider + 1, StringComparison.Ordinal);
                    if (newLine == -1)
                    {
                        newLine = endPos;
                    }
                    SetStyle(newLine - divider, StyleComment);
                    divider = newLine;
                }
                lastDivider = divider;
                startPos    = lastDivider + 1;
            }
        }