~ubuntu-branches/ubuntu/wily/tora/wily-proposed

« back to all changes in this revision

Viewing changes to src/qscintilla2/Qt4/qscilexerperl.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Meskes
  • Date: 2009-11-19 15:18:19 UTC
  • mfrom: (1.2.9 upstream) (3.3.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091119151819-me89ezmxzkvl0lws
Tags: 2.1.1-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// This module implements the QsciLexerPerl class.
 
2
//
 
3
// Copyright (c) 2008 Riverbank Computing Limited <info@riverbankcomputing.com>
 
4
// 
 
5
// This file is part of QScintilla.
 
6
// 
 
7
// This file may be used under the terms of the GNU General Public
 
8
// License versions 2.0 or 3.0 as published by the Free Software
 
9
// Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
 
10
// included in the packaging of this file.  Alternatively you may (at
 
11
// your option) use any later version of the GNU General Public
 
12
// License if such license has been publicly approved by Riverbank
 
13
// Computing Limited (or its successors, if any) and the KDE Free Qt
 
14
// Foundation. In addition, as a special exception, Riverbank gives you
 
15
// certain additional rights. These rights are described in the Riverbank
 
16
// GPL Exception version 1.1, which can be found in the file
 
17
// GPL_EXCEPTION.txt in this package.
 
18
// 
 
19
// Please review the following information to ensure GNU General
 
20
// Public Licensing requirements will be met:
 
21
// http://trolltech.com/products/qt/licenses/licensing/opensource/. If
 
22
// you are unsure which license is appropriate for your use, please
 
23
// review the following information:
 
24
// http://trolltech.com/products/qt/licenses/licensing/licensingoverview
 
25
// or contact the sales department at sales@riverbankcomputing.com.
 
26
// 
 
27
// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
 
28
// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
 
29
// A PARTICULAR PURPOSE. Trolltech reserves all rights not expressly
 
30
// granted herein.
 
31
// 
 
32
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
33
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
34
 
 
35
 
 
36
#include "Qsci/qscilexerperl.h"
 
37
 
 
38
#include <qcolor.h>
 
39
#include <qfont.h>
 
40
#include <qsettings.h>
 
41
 
 
42
 
 
43
// The ctor.
 
44
QsciLexerPerl::QsciLexerPerl(QObject *parent)
 
45
    : QsciLexer(parent),
 
46
      fold_comments(false), fold_compact(true)
 
47
{
 
48
}
 
49
 
 
50
 
 
51
// The dtor.
 
52
QsciLexerPerl::~QsciLexerPerl()
 
53
{
 
54
}
 
55
 
 
56
 
 
57
// Returns the language name.
 
58
const char *QsciLexerPerl::language() const
 
59
{
 
60
    return "Perl";
 
61
}
 
62
 
 
63
 
 
64
// Returns the lexer name.
 
65
const char *QsciLexerPerl::lexer() const
 
66
{
 
67
    return "perl";
 
68
}
 
69
 
 
70
 
 
71
// Return the set of character sequences that can separate auto-completion
 
72
// words.
 
73
QStringList QsciLexerPerl::autoCompletionWordSeparators() const
 
74
{
 
75
    QStringList wl;
 
76
 
 
77
    wl << "::" << "->";
 
78
 
 
79
    return wl;
 
80
}
 
81
 
 
82
 
 
83
// Return the style used for braces.
 
84
int QsciLexerPerl::braceStyle() const
 
85
{
 
86
    return Operator;
 
87
}
 
88
 
 
89
 
 
90
// Return the string of characters that comprise a word.
 
91
const char *QsciLexerPerl::wordCharacters() const
 
92
{
 
93
    return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$@%&";
 
94
}
 
95
 
 
96
 
 
97
// Returns the foreground colour of the text for a style.
 
98
QColor QsciLexerPerl::defaultColor(int style) const
 
99
{
 
100
    switch (style)
 
101
    {
 
102
    case Default:
 
103
        return QColor(0x80,0x80,0x80);
 
104
 
 
105
    case Error:
 
106
    case Backticks:
 
107
    case QuotedStringQX:
 
108
        return QColor(0xff,0xff,0x00);
 
109
 
 
110
    case Comment:
 
111
        return QColor(0x00,0x7f,0x00);
 
112
 
 
113
    case POD:
 
114
    case PODVerbatim:
 
115
        return QColor(0x00,0x40,0x00);
 
116
 
 
117
    case Number:
 
118
        return QColor(0x00,0x7f,0x7f);
 
119
 
 
120
    case Keyword:
 
121
        return QColor(0x00,0x00,0x7f);
 
122
 
 
123
    case DoubleQuotedString:
 
124
    case SingleQuotedString:
 
125
    case SingleQuotedHereDocument:
 
126
    case DoubleQuotedHereDocument:
 
127
    case BacktickHereDocument:
 
128
    case QuotedStringQ:
 
129
    case QuotedStringQQ:
 
130
        return QColor(0x7f,0x00,0x7f);
 
131
 
 
132
    case Operator:
 
133
    case Identifier:
 
134
    case Scalar:
 
135
    case Array:
 
136
    case Hash:
 
137
    case SymbolTable:
 
138
    case Regex:
 
139
    case Substitution:
 
140
    case HereDocumentDelimiter:
 
141
    case QuotedStringQR:
 
142
    case QuotedStringQW:
 
143
    case SubroutinePrototype:
 
144
        return QColor(0x00,0x00,0x00);
 
145
 
 
146
    case DataSection:
 
147
        return QColor(0x60,0x00,0x00);
 
148
 
 
149
    case FormatIdentifier:
 
150
    case FormatBody:
 
151
        return QColor(0xc0,0x00,0xc0);
 
152
    }
 
153
 
 
154
    return QsciLexer::defaultColor(style);
 
155
}
 
156
 
 
157
 
 
158
// Returns the end-of-line fill for a style.
 
159
bool QsciLexerPerl::defaultEolFill(int style) const
 
160
{
 
161
    switch (style)
 
162
    {
 
163
    case POD:
 
164
    case DataSection:
 
165
    case SingleQuotedHereDocument:
 
166
    case DoubleQuotedHereDocument:
 
167
    case BacktickHereDocument:
 
168
    case PODVerbatim:
 
169
    case FormatBody:
 
170
        return true;
 
171
    }
 
172
 
 
173
    return QsciLexer::defaultEolFill(style);
 
174
}
 
175
 
 
176
 
 
177
// Returns the font of the text for a style.
 
178
QFont QsciLexerPerl::defaultFont(int style) const
 
179
{
 
180
    QFont f;
 
181
 
 
182
    switch (style)
 
183
    {
 
184
    case Comment:
 
185
#if defined(Q_OS_WIN)
 
186
        f = QFont("Comic Sans MS",9);
 
187
#else
 
188
        f = QFont("Bitstream Vera Serif",9);
 
189
#endif
 
190
        break;
 
191
 
 
192
    case POD:
 
193
#if defined(Q_OS_WIN)
 
194
        f = QFont("Times New Roman",11);
 
195
#else
 
196
        f = QFont("Bitstream Charter",10);
 
197
#endif
 
198
        break;
 
199
 
 
200
    case Keyword:
 
201
    case Operator:
 
202
    case DoubleQuotedHereDocument:
 
203
    case FormatIdentifier:
 
204
        f = QsciLexer::defaultFont(style);
 
205
        f.setBold(true);
 
206
        break;
 
207
 
 
208
    case DoubleQuotedString:
 
209
    case SingleQuotedString:
 
210
    case QuotedStringQQ:
 
211
    case PODVerbatim:
 
212
#if defined(Q_OS_WIN)
 
213
        f = QFont("Courier New",10);
 
214
#else
 
215
        f = QFont("Bitstream Vera Sans Mono",9);
 
216
#endif
 
217
        break;
 
218
 
 
219
    case BacktickHereDocument:
 
220
    case SubroutinePrototype:
 
221
        f = QsciLexer::defaultFont(style);
 
222
        f.setItalic(true);
 
223
        break;
 
224
 
 
225
    default:
 
226
        f = QsciLexer::defaultFont(style);
 
227
    }
 
228
 
 
229
    return f;
 
230
}
 
231
 
 
232
 
 
233
// Returns the set of keywords.
 
234
const char *QsciLexerPerl::keywords(int set) const
 
235
{
 
236
    if (set == 1)
 
237
        return
 
238
            "NULL __FILE__ __LINE__ __PACKAGE__ __DATA__ __END__ "
 
239
            "AUTOLOAD BEGIN CORE DESTROY END EQ GE GT INIT LE LT "
 
240
            "NE CHECK abs accept alarm and atan2 bind binmode "
 
241
            "bless caller chdir chmod chomp chop chown chr chroot "
 
242
            "close closedir cmp connect continue cos crypt "
 
243
            "dbmclose dbmopen defined delete die do dump each "
 
244
            "else elsif endgrent endhostent endnetent endprotoent "
 
245
            "endpwent endservent eof eq eval exec exists exit exp "
 
246
            "fcntl fileno flock for foreach fork format formline "
 
247
            "ge getc getgrent getgrgid getgrnam gethostbyaddr "
 
248
            "gethostbyname gethostent getlogin getnetbyaddr "
 
249
            "getnetbyname getnetent getpeername getpgrp getppid "
 
250
            "getpriority getprotobyname getprotobynumber "
 
251
            "getprotoent getpwent getpwnam getpwuid getservbyname "
 
252
            "getservbyport getservent getsockname getsockopt glob "
 
253
            "gmtime goto grep gt hex if index int ioctl join keys "
 
254
            "kill last lc lcfirst le length link listen local "
 
255
            "localtime lock log lstat lt m map mkdir msgctl "
 
256
            "msgget msgrcv msgsnd my ne next no not oct open "
 
257
            "opendir or ord our pack package pipe pop pos print "
 
258
            "printf prototype push q qq qr quotemeta qu qw qx "
 
259
            "rand read readdir readline readlink readpipe recv "
 
260
            "redo ref rename require reset return reverse "
 
261
            "rewinddir rindex rmdir s scalar seek seekdir select "
 
262
            "semctl semget semop send setgrent sethostent "
 
263
            "setnetent setpgrp setpriority setprotoent setpwent "
 
264
            "setservent setsockopt shift shmctl shmget shmread "
 
265
            "shmwrite shutdown sin sleep socket socketpair sort "
 
266
            "splice split sprintf sqrt srand stat study sub "
 
267
            "substr symlink syscall sysopen sysread sysseek "
 
268
            "system syswrite tell telldir tie tied time times tr "
 
269
            "truncate uc ucfirst umask undef unless unlink unpack "
 
270
            "unshift untie until use utime values vec wait "
 
271
            "waitpid wantarray warn while write x xor y";
 
272
 
 
273
    return 0;
 
274
}
 
275
 
 
276
 
 
277
// Returns the user name of a style.
 
278
QString QsciLexerPerl::description(int style) const
 
279
{
 
280
    switch (style)
 
281
    {
 
282
    case Default:
 
283
        return tr("Default");
 
284
 
 
285
    case Error:
 
286
        return tr("Error");
 
287
 
 
288
    case Comment:
 
289
        return tr("Comment");
 
290
 
 
291
    case POD:
 
292
        return tr("POD");
 
293
 
 
294
    case Number:
 
295
        return tr("Number");
 
296
 
 
297
    case Keyword:
 
298
        return tr("Keyword");
 
299
 
 
300
    case DoubleQuotedString:
 
301
        return tr("Double-quoted string");
 
302
 
 
303
    case SingleQuotedString:
 
304
        return tr("Single-quoted string");
 
305
 
 
306
    case Operator:
 
307
        return tr("Operator");
 
308
 
 
309
    case Identifier:
 
310
        return tr("Identifier");
 
311
 
 
312
    case Scalar:
 
313
        return tr("Scalar");
 
314
 
 
315
    case Array:
 
316
        return tr("Array");
 
317
 
 
318
    case Hash:
 
319
        return tr("Hash");
 
320
 
 
321
    case SymbolTable:
 
322
        return tr("Symbol table");
 
323
 
 
324
    case Regex:
 
325
        return tr("Regular expression");
 
326
 
 
327
    case Substitution:
 
328
        return tr("Substitution");
 
329
 
 
330
    case Backticks:
 
331
        return tr("Backticks");
 
332
 
 
333
    case DataSection:
 
334
        return tr("Data section");
 
335
 
 
336
    case HereDocumentDelimiter:
 
337
        return tr("Here document delimiter");
 
338
 
 
339
    case SingleQuotedHereDocument:
 
340
        return tr("Single-quoted here document");
 
341
 
 
342
    case DoubleQuotedHereDocument:
 
343
        return tr("Double-quoted here document");
 
344
 
 
345
    case BacktickHereDocument:
 
346
        return tr("Backtick here document");
 
347
 
 
348
    case QuotedStringQ:
 
349
        return tr("Quoted string (q)");
 
350
 
 
351
    case QuotedStringQQ:
 
352
        return tr("Quoted string (qq)");
 
353
 
 
354
    case QuotedStringQX:
 
355
        return tr("Quoted string (qx)");
 
356
 
 
357
    case QuotedStringQR:
 
358
        return tr("Quoted string (qr)");
 
359
 
 
360
    case QuotedStringQW:
 
361
        return tr("Quoted string (qw)");
 
362
 
 
363
    case PODVerbatim:
 
364
        return tr("POD verbatim");
 
365
 
 
366
    case SubroutinePrototype:
 
367
        return tr("Subroutine prototype");
 
368
 
 
369
    case FormatIdentifier:
 
370
        return tr("Format identifier");
 
371
 
 
372
    case FormatBody:
 
373
        return tr("Format body");
 
374
    }
 
375
 
 
376
    return QString();
 
377
}
 
378
 
 
379
 
 
380
// Returns the background colour of the text for a style.
 
381
QColor QsciLexerPerl::defaultPaper(int style) const
 
382
{
 
383
    switch (style)
 
384
    {
 
385
    case Error:
 
386
        return QColor(0xff,0x00,0x00);
 
387
 
 
388
    case POD:
 
389
        return QColor(0xe0,0xff,0xe0);
 
390
 
 
391
    case Scalar:
 
392
        return QColor(0xff,0xe0,0xe0);
 
393
 
 
394
    case Array:
 
395
        return QColor(0xff,0xff,0xe0);
 
396
 
 
397
    case Hash:
 
398
        return QColor(0xff,0xe0,0xff);
 
399
 
 
400
    case SymbolTable:
 
401
        return QColor(0xe0,0xe0,0xe0);
 
402
 
 
403
    case Regex:
 
404
        return QColor(0xa0,0xff,0xa0);
 
405
 
 
406
    case Substitution:
 
407
        return QColor(0xf0,0xe0,0x80);
 
408
 
 
409
    case Backticks:
 
410
        return QColor(0xa0,0x80,0x80);
 
411
 
 
412
    case DataSection:
 
413
        return QColor(0xff,0xf0,0xd8);
 
414
 
 
415
    case HereDocumentDelimiter:
 
416
    case SingleQuotedHereDocument:
 
417
    case DoubleQuotedHereDocument:
 
418
    case BacktickHereDocument:
 
419
        return QColor(0xdd,0xd0,0xdd);
 
420
 
 
421
    case PODVerbatim:
 
422
        return QColor(0xc0,0xff,0xc0);
 
423
 
 
424
    case FormatBody:
 
425
        return QColor(0xff,0xf0,0xff);
 
426
    }
 
427
 
 
428
    return QsciLexer::defaultPaper(style);
 
429
}
 
430
 
 
431
 
 
432
// Refresh all properties.
 
433
void QsciLexerPerl::refreshProperties()
 
434
{
 
435
    setCommentProp();
 
436
    setCompactProp();
 
437
}
 
438
 
 
439
 
 
440
// Read properties from the settings.
 
441
bool QsciLexerPerl::readProperties(QSettings &qs,const QString &prefix)
 
442
{
 
443
    int rc = true;
 
444
 
 
445
    fold_comments = qs.value(prefix + "foldcomments", false).toBool();
 
446
    fold_compact = qs.value(prefix + "foldcompact", true).toBool();
 
447
 
 
448
    return rc;
 
449
}
 
450
 
 
451
 
 
452
// Write properties to the settings.
 
453
bool QsciLexerPerl::writeProperties(QSettings &qs,const QString &prefix) const
 
454
{
 
455
    int rc = true;
 
456
 
 
457
    qs.setValue(prefix + "foldcomments", fold_comments);
 
458
    qs.setValue(prefix + "foldcompact", fold_compact);
 
459
 
 
460
    return rc;
 
461
}
 
462
 
 
463
 
 
464
// Return true if comments can be folded.
 
465
bool QsciLexerPerl::foldComments() const
 
466
{
 
467
    return fold_comments;
 
468
}
 
469
 
 
470
 
 
471
// Set if comments can be folded.
 
472
void QsciLexerPerl::setFoldComments(bool fold)
 
473
{
 
474
    fold_comments = fold;
 
475
 
 
476
    setCommentProp();
 
477
}
 
478
 
 
479
 
 
480
// Set the "fold.comment" property.
 
481
void QsciLexerPerl::setCommentProp()
 
482
{
 
483
    emit propertyChanged("fold.comment",(fold_comments ? "1" : "0"));
 
484
}
 
485
 
 
486
 
 
487
// Return true if folds are compact.
 
488
bool QsciLexerPerl::foldCompact() const
 
489
{
 
490
    return fold_compact;
 
491
}
 
492
 
 
493
 
 
494
// Set if folds are compact
 
495
void QsciLexerPerl::setFoldCompact(bool fold)
 
496
{
 
497
    fold_compact = fold;
 
498
 
 
499
    setCompactProp();
 
500
}
 
501
 
 
502
 
 
503
// Set the "fold.compact" property.
 
504
void QsciLexerPerl::setCompactProp()
 
505
{
 
506
    emit propertyChanged("fold.compact",(fold_compact ? "1" : "0"));
 
507
}