1 // This defines the interface to the QsciLexerD 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 #ifndef QSCILEXERD_H
22 #define QSCILEXERD_H
23 
24 #include <QObject>
25 
26 #include <Qsci/qsciglobal.h>
27 #include <Qsci/qscilexer.h>
28 
29 
30 //! \brief The QsciLexerD class encapsulates the Scintilla D lexer.
31 class QSCINTILLA_EXPORT QsciLexerD : public QsciLexer
32 {
33     Q_OBJECT
34 
35 public:
36     //! This enum defines the meanings of the different styles used by the D
37     //! lexer.
38     enum {
39         //! The default.
40         Default = 0,
41 
42         //! A comment.
43         Comment = 1,
44 
45         //! A comment line.
46         CommentLine = 2,
47 
48         //! A JavaDoc and Doxygen comment.
49         CommentDoc = 3,
50 
51         //! A nested comment.
52         CommentNested = 4,
53 
54         //! A number.
55         Number = 5,
56 
57         //! A keyword.
58         Keyword = 6,
59 
60         //! A secondary keyword.
61         KeywordSecondary = 7,
62 
63         //! A doc keyword
64         KeywordDoc = 8,
65 
66         //! Typedefs and aliases
67         Typedefs = 9,
68 
69         //! A string.
70         String = 10,
71 
72         //! The end of a line where a string is not closed.
73         UnclosedString = 11,
74 
75         //! A character
76         Character = 12,
77 
78         //! An operator.
79         Operator = 13,
80 
81         //! An identifier
82         Identifier = 14,
83 
84         //! A JavaDoc and Doxygen line.
85         CommentLineDoc = 15,
86 
87         //! A JavaDoc and Doxygen  keyword.
88         CommentDocKeyword = 16,
89 
90         //! A JavaDoc and Doxygen keyword error.
91         CommentDocKeywordError = 17,
92 
93         //! A backquoted string.
94         BackquoteString = 18,
95 
96         //! A raw, hexadecimal or delimited string.
97         RawString = 19,
98 
99         //! A keyword defined in keyword set number 5.  The class must be
100         //! sub-classed and re-implement keywords() to make use of this style.
101         KeywordSet5 = 20,
102 
103         //! A keyword defined in keyword set number 6.  The class must be
104         //! sub-classed and re-implement keywords() to make use of this style.
105         KeywordSet6 = 21,
106 
107         //! A keyword defined in keyword set number 7.  The class must be
108         //! sub-classed and re-implement keywords() to make use of this style.
109         KeywordSet7 = 22,
110     };
111 
112     //! Construct a QsciLexerD with parent \a parent.  \a parent is typically
113     //! the QsciScintilla instance.
114     QsciLexerD(QObject *parent = 0);
115 
116     //! Destroys the QsciLexerD instance.
117     virtual ~QsciLexerD();
118 
119     //! Returns the name of the language.
120     const char *language() const;
121 
122     //! Returns the name of the lexer.  Some lexers support a number of
123     //! languages.
124     const char *lexer() const;
125 
126     //! \internal Returns the character sequences that can separate
127     //! auto-completion words.
128     QStringList autoCompletionWordSeparators() const;
129 
130     //! \internal Returns a space separated list of words or characters in a
131     //! particular style that define the end of a block for auto-indentation.
132     //! The styles is returned via \a style.
133     const char *blockEnd(int *style = 0) const;
134 
135     //! \internal Returns a space separated list of words or characters in a
136     //! particular style that define the start of a block for auto-indentation.
137     //! The styles is returned via \a style.
138     const char *blockStart(int *style = 0) const;
139 
140     //! \internal Returns a space separated list of keywords in a particular
141     //! style that define the start of a block for auto-indentation.  The
142     //! styles is returned via \a style.
143     const char *blockStartKeyword(int *style = 0) const;
144 
145     //! \internal Returns the style used for braces for brace matching.
146     int braceStyle() const;
147 
148     //! Returns the string of characters that comprise a word.
149     const char *wordCharacters() const;
150 
151     //! Returns the foreground colour of the text for style number \a style.
152     //!
153     //! \sa defaultPaper()
154     QColor defaultColor(int style) const;
155 
156     //! Returns the end-of-line fill for style number \a style.
157     bool defaultEolFill(int style) const;
158 
159     //! Returns the font for style number \a style.
160     QFont defaultFont(int style) const;
161 
162     //! Returns the background colour of the text for style number \a style.
163     //!
164     //! \sa defaultColor()
165     QColor defaultPaper(int style) const;
166 
167     //! Returns the set of keywords for the keyword set \a set recognised by
168     //! the lexer as a space separated string.
169     const char *keywords(int set) const;
170 
171     //! Returns the descriptive name for style number \a style.  If the style
172     //! is invalid for this language then an empty QString is returned.  This
173     //! is intended to be used in user preference dialogs.
174     QString description(int style) const;
175 
176     //! Causes all properties to be refreshed by emitting the propertyChanged()
177     //! signal as required.
178     void refreshProperties();
179 
180     //! Returns true if "} else {" lines can be folded.
181     //!
182     //! \sa setFoldAtElse()
183     bool foldAtElse() const;
184 
185     //! Returns true if multi-line comment blocks can be folded.
186     //!
187     //! \sa setFoldComments()
188     bool foldComments() const;
189 
190     //! Returns true if trailing blank lines are included in a fold block.
191     //!
192     //! \sa setFoldCompact()
193     bool foldCompact() const;
194 
195 public slots:
196     //! If \a fold is true then "} else {" lines can be folded.  The default is
197     //! false.
198     //!
199     //! \sa foldAtElse()
200     virtual void setFoldAtElse(bool fold);
201 
202     //! If \a fold is true then multi-line comment blocks can be folded.  The
203     //! default is false.
204     //!
205     //! \sa foldComments()
206     virtual void setFoldComments(bool fold);
207 
208     //! If \a fold is true then trailing blank lines are included in a fold
209     //! block. The default is true.
210     //!
211     //! \sa foldCompact()
212     virtual void setFoldCompact(bool fold);
213 
214 protected:
215     //! The lexer's properties are read from the settings \a qs.  \a prefix
216     //! (which has a trailing '/') should be used as a prefix to the key of
217     //! each setting.  true is returned if there is no error.
218     //!
219     //! \sa writeProperties()
220     bool readProperties(QSettings &qs,const QString &prefix);
221 
222     //! The lexer's properties are written to the settings \a qs.  \a prefix
223     //! (which has a trailing '/') should be used as a prefix to the key of
224     //! each setting.  true is returned if there is no error.
225     //!
226     //! \sa readProperties()
227     bool writeProperties(QSettings &qs,const QString &prefix) const;
228 
229 private:
230     void setAtElseProp();
231     void setCommentProp();
232     void setCompactProp();
233 
234     bool fold_atelse;
235     bool fold_comments;
236     bool fold_compact;
237 
238     QsciLexerD(const QsciLexerD &);
239     QsciLexerD &operator=(const QsciLexerD &);
240 };
241 
242 #endif
243