qscilexersql.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. // This defines the interface to the QsciLexerSQL 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 QSCILEXERSQL_H
  20. #define QSCILEXERSQL_H
  21. #include <QObject>
  22. #include <Qsci/qsciglobal.h>
  23. #include <Qsci/qscilexer.h>
  24. //! \brief The QsciLexerSQL class encapsulates the Scintilla SQL lexer.
  25. class QSCINTILLA_EXPORT QsciLexerSQL : public QsciLexer
  26. {
  27. Q_OBJECT
  28. public:
  29. //! This enum defines the meanings of the different styles used by the
  30. //! SQL lexer.
  31. enum {
  32. //! The default.
  33. Default = 0,
  34. //! A comment.
  35. Comment = 1,
  36. //! A line comment.
  37. CommentLine = 2,
  38. //! A JavaDoc/Doxygen style comment.
  39. CommentDoc = 3,
  40. //! A number.
  41. Number = 4,
  42. //! A keyword.
  43. Keyword = 5,
  44. //! A double-quoted string.
  45. DoubleQuotedString = 6,
  46. //! A single-quoted string.
  47. SingleQuotedString = 7,
  48. //! An SQL*Plus keyword.
  49. PlusKeyword = 8,
  50. //! An SQL*Plus prompt.
  51. PlusPrompt = 9,
  52. //! An operator.
  53. Operator = 10,
  54. //! An identifier
  55. Identifier = 11,
  56. //! An SQL*Plus comment.
  57. PlusComment = 13,
  58. //! A '#' line comment.
  59. CommentLineHash = 15,
  60. //! A JavaDoc/Doxygen keyword.
  61. CommentDocKeyword = 17,
  62. //! A JavaDoc/Doxygen keyword error.
  63. CommentDocKeywordError = 18,
  64. //! A keyword defined in keyword set number 5. The class must be
  65. //! sub-classed and re-implement keywords() to make use of this style.
  66. //! Note that keywords must be defined using lower case.
  67. KeywordSet5 = 19,
  68. //! A keyword defined in keyword set number 6. The class must be
  69. //! sub-classed and re-implement keywords() to make use of this style.
  70. //! Note that keywords must be defined using lower case.
  71. KeywordSet6 = 20,
  72. //! A keyword defined in keyword set number 7. The class must be
  73. //! sub-classed and re-implement keywords() to make use of this style.
  74. //! Note that keywords must be defined using lower case.
  75. KeywordSet7 = 21,
  76. //! A keyword defined in keyword set number 8. The class must be
  77. //! sub-classed and re-implement keywords() to make use of this style.
  78. //! Note that keywords must be defined using lower case.
  79. KeywordSet8 = 22,
  80. //! A quoted identifier.
  81. QuotedIdentifier = 23,
  82. //! A quoted operator.
  83. QuotedOperator = 24,
  84. };
  85. //! Construct a QsciLexerSQL with parent \a parent. \a parent is typically
  86. //! the QsciScintilla instance.
  87. QsciLexerSQL(QObject *parent = 0);
  88. //! Destroys the QsciLexerSQL instance.
  89. virtual ~QsciLexerSQL();
  90. //! Returns the name of the language.
  91. const char *language() const;
  92. //! Returns the name of the lexer. Some lexers support a number of
  93. //! languages.
  94. const char *lexer() const;
  95. //! \internal Returns the style used for braces for brace matching.
  96. int braceStyle() const;
  97. //! Returns the foreground colour of the text for style number \a style.
  98. //!
  99. //! \sa defaultPaper()
  100. QColor defaultColor(int style) const;
  101. //! Returns the end-of-line fill for style number \a style.
  102. bool defaultEolFill(int style) const;
  103. //! Returns the font for style number \a style.
  104. QFont defaultFont(int style) const;
  105. //! Returns the background colour of the text for style number \a style.
  106. //!
  107. //! \sa defaultColor()
  108. QColor defaultPaper(int style) const;
  109. //! Returns the set of keywords for the keyword set \a set recognised by
  110. //! the lexer as a space separated string.
  111. const char *keywords(int set) const;
  112. //! Returns the descriptive name for style number \a style. If the style
  113. //! is invalid for this language then an empty QString is returned. This
  114. //! is intended to be used in user preference dialogs.
  115. QString description(int style) const;
  116. //! Causes all properties to be refreshed by emitting the
  117. //! propertyChanged() signal as required.
  118. void refreshProperties();
  119. //! Returns true if backslash escapes are enabled.
  120. //!
  121. //! \sa setBackslashEscapes()
  122. bool backslashEscapes() const {return backslash_escapes;}
  123. //! If \a enable is true then words may contain dots (i.e. periods or full
  124. //! stops). The default is false.
  125. //!
  126. //! \sa dottedWords()
  127. void setDottedWords(bool enable);
  128. //! Returns true if words may contain dots (i.e. periods or full stops).
  129. //!
  130. //! \sa setDottedWords()
  131. bool dottedWords() const {return allow_dotted_word;}
  132. //! If \a fold is true then ELSE blocks can be folded. The default is
  133. //! false.
  134. //!
  135. //! \sa foldAtElse()
  136. void setFoldAtElse(bool fold);
  137. //! Returns true if ELSE blocks can be folded.
  138. //!
  139. //! \sa setFoldAtElse()
  140. bool foldAtElse() const {return at_else;}
  141. //! Returns true if multi-line comment blocks can be folded.
  142. //!
  143. //! \sa setFoldComments()
  144. bool foldComments() const {return fold_comments;}
  145. //! Returns true if trailing blank lines are included in a fold block.
  146. //!
  147. //! \sa setFoldCompact()
  148. bool foldCompact() const {return fold_compact;}
  149. //! If \a fold is true then only BEGIN blocks can be folded. The default
  150. //! is false.
  151. //!
  152. //! \sa foldOnlyBegin()
  153. void setFoldOnlyBegin(bool fold);
  154. //! Returns true if BEGIN blocks only can be folded.
  155. //!
  156. //! \sa setFoldOnlyBegin()
  157. bool foldOnlyBegin() const {return only_begin;}
  158. //! If \a enable is true then '#' is used as a comment character. It is
  159. //! typically enabled for MySQL and disabled for Oracle. The default is
  160. //! false.
  161. //!
  162. //! \sa hashComments()
  163. void setHashComments(bool enable);
  164. //! Returns true if '#' is used as a comment character.
  165. //!
  166. //! \sa setHashComments()
  167. bool hashComments() const {return numbersign_comment;}
  168. //! If \a enable is true then quoted identifiers are enabled. The default
  169. //! is false.
  170. //!
  171. //! \sa quotedIdentifiers()
  172. void setQuotedIdentifiers(bool enable);
  173. //! Returns true if quoted identifiers are enabled.
  174. //!
  175. //! \sa setQuotedIdentifiers()
  176. bool quotedIdentifiers() const {return backticks_identifier;}
  177. public slots:
  178. //! If \a enable is true then backslash escapes are enabled. The
  179. //! default is false.
  180. //!
  181. //! \sa backslashEscapes()
  182. virtual void setBackslashEscapes(bool enable);
  183. //! If \a fold is true then multi-line comment blocks can be folded. The
  184. //! default is false.
  185. //!
  186. //! \sa foldComments()
  187. virtual void setFoldComments(bool fold);
  188. //! If \a fold is true then trailing blank lines are included in a fold
  189. //! block. The default is true.
  190. //!
  191. //! \sa foldCompact()
  192. virtual void setFoldCompact(bool fold);
  193. protected:
  194. //! The lexer's properties are read from the settings \a qs. \a prefix
  195. //! (which has a trailing '/') should be used as a prefix to the key of
  196. //! each setting. true is returned if there is no error.
  197. //!
  198. bool readProperties(QSettings &qs, const QString &prefix);
  199. //! The lexer's properties are written to the settings \a qs.
  200. //! \a prefix (which has a trailing '/') should be used as a prefix to
  201. //! the key of each setting. true is returned if there is no error.
  202. //!
  203. bool writeProperties(QSettings &qs, const QString &prefix) const;
  204. private:
  205. void setAtElseProp();
  206. void setCommentProp();
  207. void setCompactProp();
  208. void setOnlyBeginProp();
  209. void setBackticksIdentifierProp();
  210. void setNumbersignCommentProp();
  211. void setBackslashEscapesProp();
  212. void setAllowDottedWordProp();
  213. bool at_else;
  214. bool fold_comments;
  215. bool fold_compact;
  216. bool only_begin;
  217. bool backticks_identifier;
  218. bool numbersign_comment;
  219. bool backslash_escapes;
  220. bool allow_dotted_word;
  221. QsciLexerSQL(const QsciLexerSQL &);
  222. QsciLexerSQL &operator=(const QsciLexerSQL &);
  223. };
  224. #endif