1 // This module implements the QsciLexerJavaScript class.
2 //
3 // Copyright (c) 2021 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 License
8 // version 3.0 as published by the Free Software Foundation and appearing in
9 // the file LICENSE included in the packaging of this file.  Please review the
10 // following information to ensure the GNU General Public License version 3.0
11 // requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 //
13 // If you do not wish to use this file under the terms of the GPL version 3.0
14 // then you may purchase a commercial license.  For more information contact
15 // info@riverbankcomputing.com.
16 //
17 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 
20 
21 #include "Qsci/qscilexerjavascript.h"
22 
23 #include <qcolor.h>
24 #include <qfont.h>
25 
26 
27 // The list of JavaScript keywords that can be used by other friendly lexers.
28 const char *QsciLexerJavaScript::keywordClass =
29     "abstract boolean break byte case catch char class const continue "
30     "debugger default delete do double else enum export extends final "
31     "finally float for function goto if implements import in instanceof "
32     "int interface long native new package private protected public "
33     "return short static super switch synchronized this throw throws "
34     "transient try typeof var void volatile while with";
35 
36 
37 // The ctor.
QsciLexerJavaScript(QObject * parent)38 QsciLexerJavaScript::QsciLexerJavaScript(QObject *parent)
39     : QsciLexerCPP(parent)
40 {
41 }
42 
43 
44 // The dtor.
~QsciLexerJavaScript()45 QsciLexerJavaScript::~QsciLexerJavaScript()
46 {
47 }
48 
49 
50 // Returns the language name.
language() const51 const char *QsciLexerJavaScript::language() const
52 {
53     return "JavaScript";
54 }
55 
56 
57 // Returns the foreground colour of the text for a style.
defaultColor(int style) const58 QColor QsciLexerJavaScript::defaultColor(int style) const
59 {
60     if (style == Regex)
61         return QColor(0x3f,0x7f,0x3f);
62 
63     return QsciLexerCPP::defaultColor(style);
64 }
65 
66 
67 // Returns the end-of-line fill for a style.
defaultEolFill(int style) const68 bool QsciLexerJavaScript::defaultEolFill(int style) const
69 {
70     if (style == Regex)
71         return true;
72 
73     return QsciLexerCPP::defaultEolFill(style);
74 }
75 
76 
77 // Returns the font of the text for a style.
defaultFont(int style) const78 QFont QsciLexerJavaScript::defaultFont(int style) const
79 {
80     if (style == Regex)
81 #if defined(Q_OS_WIN)
82         return QFont("Courier New",10);
83 #elif defined(Q_OS_MAC)
84         return QFont("Courier", 12);
85 #else
86         return QFont("Bitstream Vera Sans Mono",9);
87 #endif
88 
89     return QsciLexerCPP::defaultFont(style);
90 }
91 
92 
93 // Returns the set of keywords.
keywords(int set) const94 const char *QsciLexerJavaScript::keywords(int set) const
95 {
96     if (set != 1)
97         return 0;
98 
99     return keywordClass;
100 }
101 
102 
103 // Returns the user name of a style.
description(int style) const104 QString QsciLexerJavaScript::description(int style) const
105 {
106     if (style == Regex)
107         return tr("Regular expression");
108 
109     return QsciLexerCPP::description(style);
110 }
111 
112 
113 // Returns the background colour of the text for a style.
defaultPaper(int style) const114 QColor QsciLexerJavaScript::defaultPaper(int style) const
115 {
116     if (style == Regex)
117         return QColor(0xe0,0xf0,0xff);
118 
119     return QsciLexer::defaultPaper(style);
120 }
121