~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to editors/qeditor/ada_colorizer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2006-05-23 18:39:42 UTC
  • Revision ID: james.westby@ubuntu.com-20060523183942-hucifbvh68k2bwz7
Tags: upstream-3.3.2
Import upstream version 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2003 Oliver Kellogg
 
3
 * okellogg@users.sourceforge.net
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 */
 
10
#include "ada_colorizer.h"
 
11
#include "qeditor.h"
 
12
#include "paragdata.h"
 
13
 
 
14
#include <qfont.h>
 
15
#include <qapplication.h>
 
16
#include <qsettings.h>
 
17
#include <private/qrichtext_p.h>
 
18
#include <kdebug.h>
 
19
 
 
20
static const char *ada_keywords[] = {
 
21
    "abort",
 
22
    "abs",
 
23
    "accept",
 
24
    "access",
 
25
    "all",
 
26
    "and",
 
27
    "array",
 
28
    "at",
 
29
    "begin",
 
30
    "body",
 
31
    "case",
 
32
    "constant",
 
33
    "declare",
 
34
    "delay",
 
35
    "delta",
 
36
    "digits",
 
37
    "do",
 
38
    "else",
 
39
    "elsif",
 
40
    "end",
 
41
    "entry",
 
42
    "exception",
 
43
    "exit",
 
44
    "for",
 
45
    "function",
 
46
    "generic",
 
47
    "goto",
 
48
    "if",
 
49
    "in",
 
50
    "is",
 
51
    "limited",
 
52
    "loop",
 
53
    "mod",
 
54
    "new",
 
55
    "not",
 
56
    "null",
 
57
    "of",
 
58
    "or",
 
59
    "others",
 
60
    "out",
 
61
    "package",
 
62
    "pragma",
 
63
    "private",
 
64
    "procedure",
 
65
    "raise",
 
66
    "range",
 
67
    "record",
 
68
    "rem",
 
69
    "renames",
 
70
    "return",
 
71
    "reverse",
 
72
    "select",
 
73
    "separate",
 
74
    "subtype",
 
75
    "task",
 
76
    "terminate",
 
77
    "then",
 
78
    "type",
 
79
    "use",
 
80
    "when",
 
81
    "while",
 
82
    "with",
 
83
    "xor",
 
84
    0
 
85
};
 
86
 
 
87
AdaColorizer::AdaColorizer (QEditor * editor)
 
88
    : QSourceColorizer (editor)
 
89
{
 
90
    //default context
 
91
    HLItemCollection* context0 = new HLItemCollection (0);
 
92
    context0->appendChild (new StartsWithHLItem ("--", Comment, 0));
 
93
    context0->appendChild (new KeywordsHLItem (ada_keywords, Keyword, Normal, 0));
 
94
    context0->appendChild (new WhiteSpacesHLItem (Normal, 0));
 
95
    context0->appendChild (new StringHLItem ("\"", String, 1));
 
96
    context0->appendChild (new NumberHLItem (Constant, 0));
 
97
    context0->appendChild (new RegExpHLItem ("[0-9][0-9]*#[A-Fa-f0-9]*#", Constant, 0));
 
98
 
 
99
    HLItemCollection* context1 = new HLItemCollection (String);
 
100
    context1->appendChild (new StringHLItem ("\"", String, 0));
 
101
 
 
102
    m_items.append (context0);
 
103
    m_items.append (context1);
 
104
}
 
105
 
 
106
AdaColorizer::~AdaColorizer ()
 
107
{
 
108
}
 
109
 
 
110
int AdaColorizer::computeLevel (QTextParagraph* parag, int startLevel)
 
111
{
 
112
    int level = startLevel;
 
113
 
 
114
    QString s = editor ()->text (parag->paragId ());
 
115
    ParagData* data = (ParagData*) parag->extraData ();
 
116
    if (!data || s.isEmpty ()) {
 
117
        kdDebug() << "AdaColorizer::computeLevel: early return" << endl;
 
118
        return startLevel;
 
119
    }
 
120
 
 
121
    data->setBlockStart (false);
 
122
 
 
123
    // Level starters for Ada:  begin, case, do, if, loop, select, while
 
124
    QRegExp startRx ("^\\s*(begin|case|if|loop|select|while)\\b", false);
 
125
    
 
126
    // We need another regexp for loops such as "for I in 1 .. 2 loop" because
 
127
    // the keyword does not appear at the start of the line.
 
128
    // We do not use the keyword "for" here because its meaning is overloaded.
 
129
    // We must also guard against matching the statement "end loop".
 
130
    QRegExp startLoopRx ("\\bloop\\s*(--.*)?$", false);
 
131
 
 
132
    // Level terminators for Ada: end
 
133
    QRegExp endRx ("^\\s*end\\b", false);
 
134
 
 
135
    if (startRx.search (s) != -1 || startLoopRx.search (s) != -1)
 
136
        ++level;
 
137
    else if (endRx.search (s) != -1)
 
138
        --level;
 
139
 
 
140
    if (level > startLevel) {
 
141
        data->setBlockStart (true);
 
142
    }
 
143
 
 
144
    kdDebug() << "AdaColorizer::computeLevel called, startLevel="
 
145
              << startLevel << ", text: '" << s
 
146
              << "', level=" << level << endl;
 
147
    return level;
 
148
}
 
149