qscilexercpp.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. // This defines the interface to the QsciLexerCPP class.
  2. //
  3. // Copyright (c) 2017 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. #ifndef QSCILEXERCPP_H
  20. #define QSCILEXERCPP_H
  21. #include <QObject>
  22. #include <Qsci/qsciglobal.h>
  23. #include <Qsci/qscilexer.h>
  24. //! \brief The QsciLexerCPP class encapsulates the Scintilla C++
  25. //! lexer.
  26. class QSCINTILLA_EXPORT QsciLexerCPP : public QsciLexer
  27. {
  28. Q_OBJECT
  29. public:
  30. //! This enum defines the meanings of the different styles used by the
  31. //! C++ lexer.
  32. enum {
  33. //! The default.
  34. Default = 0,
  35. InactiveDefault = Default + 64,
  36. //! A C comment.
  37. Comment = 1,
  38. InactiveComment = Comment + 64,
  39. //! A C++ comment line.
  40. CommentLine = 2,
  41. InactiveCommentLine = CommentLine + 64,
  42. //! A JavaDoc/Doxygen style C comment.
  43. CommentDoc = 3,
  44. InactiveCommentDoc = CommentDoc + 64,
  45. //! A number.
  46. Number = 4,
  47. InactiveNumber = Number + 64,
  48. //! A keyword.
  49. Keyword = 5,
  50. InactiveKeyword = Keyword + 64,
  51. //! A double-quoted string.
  52. DoubleQuotedString = 6,
  53. InactiveDoubleQuotedString = DoubleQuotedString + 64,
  54. //! A single-quoted string.
  55. SingleQuotedString = 7,
  56. InactiveSingleQuotedString = SingleQuotedString + 64,
  57. //! An IDL UUID.
  58. UUID = 8,
  59. InactiveUUID = UUID + 64,
  60. //! A pre-processor block.
  61. PreProcessor = 9,
  62. InactivePreProcessor = PreProcessor + 64,
  63. //! An operator.
  64. Operator = 10,
  65. InactiveOperator = Operator + 64,
  66. //! An identifier
  67. Identifier = 11,
  68. InactiveIdentifier = Identifier + 64,
  69. //! The end of a line where a string is not closed.
  70. UnclosedString = 12,
  71. InactiveUnclosedString = UnclosedString + 64,
  72. //! A C# verbatim string.
  73. VerbatimString = 13,
  74. InactiveVerbatimString = VerbatimString + 64,
  75. //! A JavaScript regular expression.
  76. Regex = 14,
  77. InactiveRegex = Regex + 64,
  78. //! A JavaDoc/Doxygen style C++ comment line.
  79. CommentLineDoc = 15,
  80. InactiveCommentLineDoc = CommentLineDoc + 64,
  81. //! A keyword defined in keyword set number 2. The class must be
  82. //! sub-classed and re-implement keywords() to make use of this style.
  83. KeywordSet2 = 16,
  84. InactiveKeywordSet2 = KeywordSet2 + 64,
  85. //! A JavaDoc/Doxygen keyword.
  86. CommentDocKeyword = 17,
  87. InactiveCommentDocKeyword = CommentDocKeyword + 64,
  88. //! A JavaDoc/Doxygen keyword error.
  89. CommentDocKeywordError = 18,
  90. InactiveCommentDocKeywordError = CommentDocKeywordError + 64,
  91. //! A global class or typedef defined in keyword set number 5. The
  92. //! class must be sub-classed and re-implement keywords() to make use
  93. //! of this style.
  94. GlobalClass = 19,
  95. InactiveGlobalClass = GlobalClass + 64,
  96. //! A C++ raw string.
  97. RawString = 20,
  98. InactiveRawString = RawString + 64,
  99. //! A Vala triple-quoted verbatim string.
  100. TripleQuotedVerbatimString = 21,
  101. InactiveTripleQuotedVerbatimString = TripleQuotedVerbatimString + 64,
  102. //! A Pike hash-quoted string.
  103. HashQuotedString = 22,
  104. InactiveHashQuotedString = HashQuotedString + 64,
  105. //! A pre-processor stream comment.
  106. PreProcessorComment = 23,
  107. InactivePreProcessorComment = PreProcessorComment + 64,
  108. //! A JavaDoc/Doxygen style pre-processor comment.
  109. PreProcessorCommentLineDoc = 24,
  110. InactivePreProcessorCommentLineDoc = PreProcessorCommentLineDoc + 64,
  111. //! A user-defined literal.
  112. UserLiteral = 25,
  113. InactiveUserLiteral = UserLiteral + 64,
  114. //! A task marker.
  115. TaskMarker = 26,
  116. InactiveTaskMarker = TaskMarker + 64,
  117. //! An escape sequence.
  118. EscapeSequence = 27,
  119. InactiveEscapeSequence = EscapeSequence + 64,
  120. };
  121. //! Construct a QsciLexerCPP with parent \a parent. \a parent is typically
  122. //! the QsciScintilla instance. \a caseInsensitiveKeywords is true if the
  123. //! lexer ignores the case of keywords.
  124. QsciLexerCPP(QObject *parent = 0, bool caseInsensitiveKeywords = false);
  125. //! Destroys the QsciLexerCPP instance.
  126. virtual ~QsciLexerCPP();
  127. //! Returns the name of the language.
  128. const char *language() const;
  129. //! Returns the name of the lexer. Some lexers support a number of
  130. //! languages.
  131. const char *lexer() const;
  132. //! \internal Returns the character sequences that can separate
  133. //! auto-completion words.
  134. QStringList autoCompletionWordSeparators() const;
  135. //! \internal Returns a space separated list of words or characters in
  136. //! a particular style that define the end of a block for
  137. //! auto-indentation. The styles is returned via \a style.
  138. const char *blockEnd(int *style = 0) const;
  139. //! \internal Returns a space separated list of words or characters in
  140. //! a particular style that define the start of a block for
  141. //! auto-indentation. The styles is returned via \a style.
  142. const char *blockStart(int *style = 0) const;
  143. //! \internal Returns a space separated list of keywords in a
  144. //! particular style that define the start of a block for
  145. //! auto-indentation. The styles is returned via \a style.
  146. const char *blockStartKeyword(int *style = 0) const;
  147. //! \internal Returns the style used for braces for brace matching.
  148. int braceStyle() const;
  149. //! Returns the string of characters that comprise a word.
  150. const char *wordCharacters() const;
  151. //! Returns the foreground colour of the text for style number \a style.
  152. //!
  153. //! \sa defaultPaper()
  154. QColor defaultColor(int style) const;
  155. //! Returns the end-of-line fill for style number \a style.
  156. bool defaultEolFill(int style) const;
  157. //! Returns the font for style number \a style.
  158. QFont defaultFont(int style) const;
  159. //! Returns the background colour of the text for style number \a style.
  160. //!
  161. //! \sa defaultColor()
  162. QColor defaultPaper(int style) const;
  163. //! Returns the set of keywords for the keyword set \a set recognised
  164. //! by the lexer as a space separated string. Set 1 is normally used for
  165. //! primary keywords and identifiers. Set 2 is normally used for secondary
  166. //! keywords and identifiers. Set 3 is normally used for documentation
  167. //! comment keywords. Set 4 is normally used for global classes and
  168. //! typedefs.
  169. const char *keywords(int set) const;
  170. //! Returns the descriptive name for style number \a style. If the
  171. //! style is invalid for this language then an empty QString is returned.
  172. //! This is intended to be used in user preference dialogs.
  173. QString description(int style) const;
  174. //! Causes all properties to be refreshed by emitting the
  175. //! propertyChanged() signal as required.
  176. void refreshProperties();
  177. //! Returns true if "} else {" lines can be folded.
  178. //!
  179. //! \sa setFoldAtElse()
  180. bool foldAtElse() const {return fold_atelse;}
  181. //! Returns true if multi-line comment blocks can be folded.
  182. //!
  183. //! \sa setFoldComments()
  184. bool foldComments() const {return fold_comments;}
  185. //! Returns true if trailing blank lines are included in a fold block.
  186. //!
  187. //! \sa setFoldCompact()
  188. bool foldCompact() const {return fold_compact;}
  189. //! Returns true if preprocessor blocks can be folded.
  190. //!
  191. //! \sa setFoldPreprocessor()
  192. bool foldPreprocessor() const {return fold_preproc;}
  193. //! Returns true if preprocessor lines (after the preprocessor
  194. //! directive) are styled.
  195. //!
  196. //! \sa setStylePreprocessor()
  197. bool stylePreprocessor() const {return style_preproc;}
  198. //! If \a allowed is true then '$' characters are allowed in identifier
  199. //! names. The default is true.
  200. //!
  201. //! \sa dollarsAllowed()
  202. void setDollarsAllowed(bool allowed);
  203. //! Returns true if '$' characters are allowed in identifier names.
  204. //!
  205. //! \sa setDollarsAllowed()
  206. bool dollarsAllowed() const {return dollars;}
  207. //! If \a enabled is true then triple quoted strings are highlighted. The
  208. //! default is false.
  209. //!
  210. //! \sa highlightTripleQuotedStrings()
  211. void setHighlightTripleQuotedStrings(bool enabled);
  212. //! Returns true if triple quoted strings should be highlighted.
  213. //!
  214. //! \sa setHighlightTripleQuotedStrings()
  215. bool highlightTripleQuotedStrings() const {return highlight_triple;}
  216. //! If \a enabled is true then hash quoted strings are highlighted. The
  217. //! default is false.
  218. //!
  219. //! \sa highlightHashQuotedStrings()
  220. void setHighlightHashQuotedStrings(bool enabled);
  221. //! Returns true if hash quoted strings should be highlighted.
  222. //!
  223. //! \sa setHighlightHashQuotedStrings()
  224. bool highlightHashQuotedStrings() const {return highlight_hash;}
  225. //! If \a enabled is true then back-quoted raw strings are highlighted.
  226. //! The default is false.
  227. //!
  228. //! \sa highlightBackQuotedStrings()
  229. void setHighlightBackQuotedStrings(bool enabled);
  230. //! Returns true if back-quoted raw strings should be highlighted.
  231. //!
  232. //! \sa setHighlightBackQuotedStrings()
  233. bool highlightBackQuotedStrings() const {return highlight_back;}
  234. //! If \a enabled is true then escape sequences in strings are highlighted.
  235. //! The default is false.
  236. //!
  237. //! \sa highlightEscapeSequences()
  238. void setHighlightEscapeSequences(bool enabled);
  239. //! Returns true if escape sequences in strings should be highlighted.
  240. //!
  241. //! \sa setHighlightEscapeSequences()
  242. bool highlightEscapeSequences() const {return highlight_escape;}
  243. //! If \a allowed is true then escape sequences are allowed in verbatim
  244. //! strings. The default is false.
  245. //!
  246. //! \sa verbatimStringEscapeSequencesAllowed()
  247. void setVerbatimStringEscapeSequencesAllowed(bool allowed);
  248. //! Returns true if hash quoted strings should be highlighted.
  249. //!
  250. //! \sa setVerbatimStringEscapeSequencesAllowed()
  251. bool verbatimStringEscapeSequencesAllowed() const {return vs_escape;}
  252. public slots:
  253. //! If \a fold is true then "} else {" lines can be folded. The
  254. //! default is false.
  255. //!
  256. //! \sa foldAtElse()
  257. virtual void setFoldAtElse(bool fold);
  258. //! If \a fold is true then multi-line comment blocks can be folded.
  259. //! The default is false.
  260. //!
  261. //! \sa foldComments()
  262. virtual void setFoldComments(bool fold);
  263. //! If \a fold is true then trailing blank lines are included in a fold
  264. //! block. The default is true.
  265. //!
  266. //! \sa foldCompact()
  267. virtual void setFoldCompact(bool fold);
  268. //! If \a fold is true then preprocessor blocks can be folded. The
  269. //! default is true.
  270. //!
  271. //! \sa foldPreprocessor()
  272. virtual void setFoldPreprocessor(bool fold);
  273. //! If \a style is true then preprocessor lines (after the preprocessor
  274. //! directive) are styled. The default is false.
  275. //!
  276. //! \sa stylePreprocessor()
  277. virtual void setStylePreprocessor(bool style);
  278. protected:
  279. //! The lexer's properties are read from the settings \a qs. \a prefix
  280. //! (which has a trailing '/') should be used as a prefix to the key of
  281. //! each setting. true is returned if there is no error.
  282. //!
  283. //! \sa writeProperties()
  284. bool readProperties(QSettings &qs,const QString &prefix);
  285. //! The lexer's properties are written to the settings \a qs.
  286. //! \a prefix (which has a trailing '/') should be used as a prefix to
  287. //! the key of each setting. true is returned if there is no error.
  288. //!
  289. //! \sa readProperties()
  290. bool writeProperties(QSettings &qs,const QString &prefix) const;
  291. private:
  292. void setAtElseProp();
  293. void setCommentProp();
  294. void setCompactProp();
  295. void setPreprocProp();
  296. void setStylePreprocProp();
  297. void setDollarsProp();
  298. void setHighlightTripleProp();
  299. void setHighlightHashProp();
  300. void setHighlightBackProp();
  301. void setHighlightEscapeProp();
  302. void setVerbatimStringEscapeProp();
  303. bool fold_atelse;
  304. bool fold_comments;
  305. bool fold_compact;
  306. bool fold_preproc;
  307. bool style_preproc;
  308. bool dollars;
  309. bool highlight_triple;
  310. bool highlight_hash;
  311. bool highlight_back;
  312. bool highlight_escape;
  313. bool vs_escape;
  314. bool nocase;
  315. QsciLexerCPP(const QsciLexerCPP &);
  316. QsciLexerCPP &operator=(const QsciLexerCPP &);
  317. };
  318. #endif