Beispiel #1
0
        private void scintilla1_TextChanged(object sender, EventArgs e)
        {
            if (_maxLineLength != scintilla1.Lines.Count.ToString().Length)
            {
                _maxLineLength = scintilla1.Lines.Count.ToString().Length;
                UpdateMarginWidth();
            }
            if (scintilla1.TextLength == 0)
            {
                return;
            }

            scintilla1.Lines.Current.DeleteMarker(_marker);
            //scintilla1.Styles.ClearDocumentStyle();

            ANTLRStringStream stream = new ANTLRStringStream(scintilla1.Text);
            Lexer1            lexer  = new Lexer1(stream);
            IToken            token;
            IToken            last = null;

            while ((token = lexer.NextToken()).Type != -1)
            {
                last = token;
                switch (token.Type)
                {
                case 4:     // Block Comment
                    scintilla1.GetRange(token.StartIndex, token.StopIndex + 1).SetStyle(4);
                    break;

                case 7:     // Line Comment
                    scintilla1.GetRange(token.StartIndex, token.StopIndex + 1).SetStyle(4);
                    break;

                case 9:     // Reserved Word
                    scintilla1.GetRange(token.StartIndex, token.StopIndex + 1).SetStyle(1);
                    break;

                case 5:     // Identifier
                    scintilla1.GetRange(token.StartIndex, token.StopIndex + 1).SetStyle(0);
                    break;

                case 6:     // Int
                    scintilla1.GetRange(token.StartIndex, token.StopIndex + 1).SetStyle(2);
                    break;

                case 10:     // String
                    scintilla1.GetRange(token.StartIndex, token.StopIndex + 1).SetStyle(3);
                    break;

                case 8:     // Other
                    scintilla1.GetRange(token.StartIndex, token.StopIndex + 1).SetStyle(0);
                    break;

                case 11:     // Whitespace
                    //scintilla1.GetRange(token.StartIndex, token.StopIndex + 1).SetStyle(0);
                    break;

                default:
                    MessageBox.Show("Unknown token type");
                    break;
                }
            }

            int mark = 0;

            if (last == null)
            {
                mark = 0;
            }
            else if (last.StopIndex + 1 < scintilla1.TextLength)
            {
                mark = last.StopIndex + 1;
            }
            else
            {
                return;
            }

            while (mark < scintilla1.TextLength && scintilla1.CharAt(mark) != '\"' && scintilla1.CharAt(mark) != '/')
            {
                ++mark;
            }
            if (mark >= scintilla1.TextLength)
            {
                return;
            }
            else if (scintilla1.CharAt(mark) == '\"')
            {
                scintilla1.GetRange(mark, scintilla1.TextLength).SetStyle(3);
            }
            else
            {
                scintilla1.GetRange(mark, scintilla1.TextLength).SetStyle(4);
            }
        }
Beispiel #2
0
        private void scintilla1_TextChanged(object sender, EventArgs e)
        {
            if (_maxLineLength != scintilla1.Lines.Count.ToString().Length)
            {
                _maxLineLength = scintilla1.Lines.Count.ToString().Length;
                UpdateMarginWidth();
            }
            if (scintilla1.TextLength == 0)
                return;

            scintilla1.Lines.Current.DeleteMarker(_marker);
            //scintilla1.Styles.ClearDocumentStyle();

            ANTLRStringStream stream = new ANTLRStringStream(scintilla1.Text);
            Lexer1 lexer = new Lexer1(stream);
            IToken token;
            IToken last = null;
            while ((token = lexer.NextToken()).Type != -1)
            {
                last = token;
                switch (token.Type)
                {
                    case 4: // Block Comment
                        scintilla1.GetRange(token.StartIndex, token.StopIndex + 1).SetStyle(4);
                        break;
                    case 7: // Line Comment
                        scintilla1.GetRange(token.StartIndex, token.StopIndex + 1).SetStyle(4);
                        break;
                    case 9: // Reserved Word
                        scintilla1.GetRange(token.StartIndex, token.StopIndex + 1).SetStyle(1);
                        break;
                    case 5: // Identifier
                        scintilla1.GetRange(token.StartIndex, token.StopIndex + 1).SetStyle(0);
                        break;
                    case 6: // Int
                        scintilla1.GetRange(token.StartIndex, token.StopIndex + 1).SetStyle(2);
                        break;
                    case 10: // String
                        scintilla1.GetRange(token.StartIndex, token.StopIndex + 1).SetStyle(3);
                        break;
                    case 8: // Other
                        scintilla1.GetRange(token.StartIndex, token.StopIndex + 1).SetStyle(0);
                        break;
                    case 11: // Whitespace
                        //scintilla1.GetRange(token.StartIndex, token.StopIndex + 1).SetStyle(0);
                        break;
                    default:
                        MessageBox.Show("Unknown token type");
                        break;
                }
            }

            int mark = 0;
            if (last == null)
                mark = 0;
            else if (last.StopIndex + 1 < scintilla1.TextLength)
                mark = last.StopIndex + 1;
            else
                return;

            while (mark < scintilla1.TextLength && scintilla1.CharAt(mark) != '\"' && scintilla1.CharAt(mark) != '/')
            {
                ++mark;
            }
            if (mark >= scintilla1.TextLength)
                return;
            else if (scintilla1.CharAt(mark) == '\"')
            {
                scintilla1.GetRange(mark, scintilla1.TextLength).SetStyle(3);
            }
            else
            {
                scintilla1.GetRange(mark, scintilla1.TextLength).SetStyle(4);
            }
        }