1
// This module implements the QsciLexerPerl class.
3
// Copyright (c) 2008 Riverbank Computing Limited <info@riverbankcomputing.com>
5
// This file is part of QScintilla.
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.
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.
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
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.
36
#include "Qsci/qscilexerperl.h"
40
#include <qsettings.h>
44
QsciLexerPerl::QsciLexerPerl(QObject *parent)
46
fold_comments(false), fold_compact(true)
52
QsciLexerPerl::~QsciLexerPerl()
57
// Returns the language name.
58
const char *QsciLexerPerl::language() const
64
// Returns the lexer name.
65
const char *QsciLexerPerl::lexer() const
71
// Return the set of character sequences that can separate auto-completion
73
QStringList QsciLexerPerl::autoCompletionWordSeparators() const
83
// Return the style used for braces.
84
int QsciLexerPerl::braceStyle() const
90
// Return the string of characters that comprise a word.
91
const char *QsciLexerPerl::wordCharacters() const
93
return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$@%&";
97
// Returns the foreground colour of the text for a style.
98
QColor QsciLexerPerl::defaultColor(int style) const
103
return QColor(0x80,0x80,0x80);
108
return QColor(0xff,0xff,0x00);
111
return QColor(0x00,0x7f,0x00);
115
return QColor(0x00,0x40,0x00);
118
return QColor(0x00,0x7f,0x7f);
121
return QColor(0x00,0x00,0x7f);
123
case DoubleQuotedString:
124
case SingleQuotedString:
125
case SingleQuotedHereDocument:
126
case DoubleQuotedHereDocument:
127
case BacktickHereDocument:
130
return QColor(0x7f,0x00,0x7f);
140
case HereDocumentDelimiter:
143
case SubroutinePrototype:
144
return QColor(0x00,0x00,0x00);
147
return QColor(0x60,0x00,0x00);
149
case FormatIdentifier:
151
return QColor(0xc0,0x00,0xc0);
154
return QsciLexer::defaultColor(style);
158
// Returns the end-of-line fill for a style.
159
bool QsciLexerPerl::defaultEolFill(int style) const
165
case SingleQuotedHereDocument:
166
case DoubleQuotedHereDocument:
167
case BacktickHereDocument:
173
return QsciLexer::defaultEolFill(style);
177
// Returns the font of the text for a style.
178
QFont QsciLexerPerl::defaultFont(int style) const
185
#if defined(Q_OS_WIN)
186
f = QFont("Comic Sans MS",9);
188
f = QFont("Bitstream Vera Serif",9);
193
#if defined(Q_OS_WIN)
194
f = QFont("Times New Roman",11);
196
f = QFont("Bitstream Charter",10);
202
case DoubleQuotedHereDocument:
203
case FormatIdentifier:
204
f = QsciLexer::defaultFont(style);
208
case DoubleQuotedString:
209
case SingleQuotedString:
212
#if defined(Q_OS_WIN)
213
f = QFont("Courier New",10);
215
f = QFont("Bitstream Vera Sans Mono",9);
219
case BacktickHereDocument:
220
case SubroutinePrototype:
221
f = QsciLexer::defaultFont(style);
226
f = QsciLexer::defaultFont(style);
233
// Returns the set of keywords.
234
const char *QsciLexerPerl::keywords(int set) const
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";
277
// Returns the user name of a style.
278
QString QsciLexerPerl::description(int style) const
283
return tr("Default");
289
return tr("Comment");
298
return tr("Keyword");
300
case DoubleQuotedString:
301
return tr("Double-quoted string");
303
case SingleQuotedString:
304
return tr("Single-quoted string");
307
return tr("Operator");
310
return tr("Identifier");
322
return tr("Symbol table");
325
return tr("Regular expression");
328
return tr("Substitution");
331
return tr("Backticks");
334
return tr("Data section");
336
case HereDocumentDelimiter:
337
return tr("Here document delimiter");
339
case SingleQuotedHereDocument:
340
return tr("Single-quoted here document");
342
case DoubleQuotedHereDocument:
343
return tr("Double-quoted here document");
345
case BacktickHereDocument:
346
return tr("Backtick here document");
349
return tr("Quoted string (q)");
352
return tr("Quoted string (qq)");
355
return tr("Quoted string (qx)");
358
return tr("Quoted string (qr)");
361
return tr("Quoted string (qw)");
364
return tr("POD verbatim");
366
case SubroutinePrototype:
367
return tr("Subroutine prototype");
369
case FormatIdentifier:
370
return tr("Format identifier");
373
return tr("Format body");
380
// Returns the background colour of the text for a style.
381
QColor QsciLexerPerl::defaultPaper(int style) const
386
return QColor(0xff,0x00,0x00);
389
return QColor(0xe0,0xff,0xe0);
392
return QColor(0xff,0xe0,0xe0);
395
return QColor(0xff,0xff,0xe0);
398
return QColor(0xff,0xe0,0xff);
401
return QColor(0xe0,0xe0,0xe0);
404
return QColor(0xa0,0xff,0xa0);
407
return QColor(0xf0,0xe0,0x80);
410
return QColor(0xa0,0x80,0x80);
413
return QColor(0xff,0xf0,0xd8);
415
case HereDocumentDelimiter:
416
case SingleQuotedHereDocument:
417
case DoubleQuotedHereDocument:
418
case BacktickHereDocument:
419
return QColor(0xdd,0xd0,0xdd);
422
return QColor(0xc0,0xff,0xc0);
425
return QColor(0xff,0xf0,0xff);
428
return QsciLexer::defaultPaper(style);
432
// Refresh all properties.
433
void QsciLexerPerl::refreshProperties()
440
// Read properties from the settings.
441
bool QsciLexerPerl::readProperties(QSettings &qs,const QString &prefix)
445
fold_comments = qs.value(prefix + "foldcomments", false).toBool();
446
fold_compact = qs.value(prefix + "foldcompact", true).toBool();
452
// Write properties to the settings.
453
bool QsciLexerPerl::writeProperties(QSettings &qs,const QString &prefix) const
457
qs.setValue(prefix + "foldcomments", fold_comments);
458
qs.setValue(prefix + "foldcompact", fold_compact);
464
// Return true if comments can be folded.
465
bool QsciLexerPerl::foldComments() const
467
return fold_comments;
471
// Set if comments can be folded.
472
void QsciLexerPerl::setFoldComments(bool fold)
474
fold_comments = fold;
480
// Set the "fold.comment" property.
481
void QsciLexerPerl::setCommentProp()
483
emit propertyChanged("fold.comment",(fold_comments ? "1" : "0"));
487
// Return true if folds are compact.
488
bool QsciLexerPerl::foldCompact() const
494
// Set if folds are compact
495
void QsciLexerPerl::setFoldCompact(bool fold)
503
// Set the "fold.compact" property.
504
void QsciLexerPerl::setCompactProp()
506
emit propertyChanged("fold.compact",(fold_compact ? "1" : "0"));