qscilexerperl.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. // This defines the interface to the QsciLexerPerl 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 QSCILEXERPERL_H
  20. #define QSCILEXERPERL_H
  21. #include <QObject>
  22. #include <Qsci/qsciglobal.h>
  23. #include <Qsci/qscilexer.h>
  24. //! \brief The QsciLexerPerl class encapsulates the Scintilla Perl
  25. //! lexer.
  26. class QSCINTILLA_EXPORT QsciLexerPerl : public QsciLexer
  27. {
  28. Q_OBJECT
  29. public:
  30. //! This enum defines the meanings of the different styles used by the
  31. //! Perl lexer.
  32. enum {
  33. //! The default.
  34. Default = 0,
  35. //! An error.
  36. Error = 1,
  37. //! A comment.
  38. Comment = 2,
  39. //! A POD.
  40. POD = 3,
  41. //! A number.
  42. Number = 4,
  43. //! A keyword.
  44. Keyword = 5,
  45. //! A double-quoted string.
  46. DoubleQuotedString = 6,
  47. //! A single-quoted string.
  48. SingleQuotedString = 7,
  49. //! An operator.
  50. Operator = 10,
  51. //! An identifier
  52. Identifier = 11,
  53. //! A scalar.
  54. Scalar = 12,
  55. //! An array.
  56. Array = 13,
  57. //! A hash.
  58. Hash = 14,
  59. //! A symbol table.
  60. SymbolTable = 15,
  61. //! A regular expression.
  62. Regex = 17,
  63. //! A substitution.
  64. Substitution = 18,
  65. //! Backticks.
  66. Backticks = 20,
  67. //! A data section.
  68. DataSection = 21,
  69. //! A here document delimiter.
  70. HereDocumentDelimiter = 22,
  71. //! A single quoted here document.
  72. SingleQuotedHereDocument = 23,
  73. //! A double quoted here document.
  74. DoubleQuotedHereDocument = 24,
  75. //! A backtick here document.
  76. BacktickHereDocument = 25,
  77. //! A quoted string (q).
  78. QuotedStringQ = 26,
  79. //! A quoted string (qq).
  80. QuotedStringQQ = 27,
  81. //! A quoted string (qx).
  82. QuotedStringQX = 28,
  83. //! A quoted string (qr).
  84. QuotedStringQR = 29,
  85. //! A quoted string (qw).
  86. QuotedStringQW = 30,
  87. //! A verbatim POD.
  88. PODVerbatim = 31,
  89. //! A Subroutine prototype.
  90. SubroutinePrototype = 40,
  91. //! A format identifier.
  92. FormatIdentifier = 41,
  93. //! A format body.
  94. FormatBody = 42,
  95. //! A double-quoted string (interpolated variable).
  96. DoubleQuotedStringVar = 43,
  97. //! A translation.
  98. Translation = 44,
  99. //! A regular expression (interpolated variable).
  100. RegexVar = 54,
  101. //! A substitution (interpolated variable).
  102. SubstitutionVar = 55,
  103. //! Backticks (interpolated variable).
  104. BackticksVar = 57,
  105. //! A double quoted here document (interpolated variable).
  106. DoubleQuotedHereDocumentVar = 61,
  107. //! A backtick here document (interpolated variable).
  108. BacktickHereDocumentVar = 62,
  109. //! A quoted string (qq, interpolated variable).
  110. QuotedStringQQVar = 64,
  111. //! A quoted string (qx, interpolated variable).
  112. QuotedStringQXVar = 65,
  113. //! A quoted string (qr, interpolated variable).
  114. QuotedStringQRVar = 66
  115. };
  116. //! Construct a QsciLexerPerl with parent \a parent. \a parent is
  117. //! typically the QsciScintilla instance.
  118. QsciLexerPerl(QObject *parent = 0);
  119. //! Destroys the QsciLexerPerl instance.
  120. virtual ~QsciLexerPerl();
  121. //! Returns the name of the language.
  122. const char *language() const;
  123. //! Returns the name of the lexer. Some lexers support a number of
  124. //! languages.
  125. const char *lexer() const;
  126. //! \internal Returns the character sequences that can separate
  127. //! auto-completion words.
  128. QStringList autoCompletionWordSeparators() const;
  129. //! \internal Returns a space separated list of words or characters in
  130. //! a particular style that define the end of a block for
  131. //! auto-indentation. The styles is returned via \a style.
  132. const char *blockEnd(int *style = 0) const;
  133. //! \internal Returns a space separated list of words or characters in
  134. //! a particular style that define the start of a block for
  135. //! auto-indentation. The styles is returned via \a style.
  136. const char *blockStart(int *style = 0) const;
  137. //! \internal Returns the style used for braces for brace matching.
  138. int braceStyle() const;
  139. //! Returns the string of characters that comprise a word.
  140. const char *wordCharacters() const;
  141. //! Returns the foreground colour of the text for style number
  142. //! \a style.
  143. //!
  144. //! \sa defaultPaper()
  145. QColor defaultColor(int style) const;
  146. //! Returns the end-of-line fill for style number \a style.
  147. bool defaultEolFill(int style) const;
  148. //! Returns the font for style number \a style.
  149. QFont defaultFont(int style) const;
  150. //! Returns the background colour of the text for style number \a style.
  151. //!
  152. //! \sa defaultColor()
  153. QColor defaultPaper(int style) const;
  154. //! Returns the set of keywords for the keyword set \a set recognised
  155. //! by the lexer as a space separated string.
  156. const char *keywords(int set) const;
  157. //! Returns the descriptive name for style number \a style. If the
  158. //! style is invalid for this language then an empty QString is returned.
  159. //! This is intended to be used in user preference dialogs.
  160. QString description(int style) const;
  161. //! Causes all properties to be refreshed by emitting the
  162. //! propertyChanged() signal as required.
  163. void refreshProperties();
  164. //! If \a fold is true then "} else {" lines can be folded. The default is
  165. //! false.
  166. //!
  167. //! \sa foldAtElse()
  168. void setFoldAtElse(bool fold);
  169. //! Returns true if "} else {" lines can be folded.
  170. //!
  171. //! \sa setFoldAtElse()
  172. bool foldAtElse() const {return fold_atelse;}
  173. //! Returns true if multi-line comment blocks can be folded.
  174. //!
  175. //! \sa setFoldComments()
  176. bool foldComments() const;
  177. //! Returns true if trailing blank lines are included in a fold block.
  178. //!
  179. //! \sa setFoldCompact()
  180. bool foldCompact() const;
  181. //! If \a fold is true then packages can be folded. The default is true.
  182. //!
  183. //! \sa foldPackages()
  184. void setFoldPackages(bool fold);
  185. //! Returns true if packages can be folded.
  186. //!
  187. //! \sa setFoldPackages()
  188. bool foldPackages() const;
  189. //! If \a fold is true then POD blocks can be folded. The default is true.
  190. //!
  191. //! \sa foldPODBlocks()
  192. void setFoldPODBlocks(bool fold);
  193. //! Returns true if POD blocks can be folded.
  194. //!
  195. //! \sa setFoldPODBlocks()
  196. bool foldPODBlocks() const;
  197. public slots:
  198. //! If \a fold is true then multi-line comment blocks can be folded.
  199. //! The default is false.
  200. //!
  201. //! \sa foldComments()
  202. virtual void setFoldComments(bool fold);
  203. //! If \a fold is true then trailing blank lines are included in a fold
  204. //! block. The default is true.
  205. //!
  206. //! \sa foldCompact()
  207. virtual void setFoldCompact(bool fold);
  208. protected:
  209. //! The lexer's properties are read from the settings \a qs. \a prefix
  210. //! (which has a trailing '/') should be used as a prefix to the key of
  211. //! each setting. true is returned if there is no error.
  212. //!
  213. bool readProperties(QSettings &qs,const QString &prefix);
  214. //! The lexer's properties are written to the settings \a qs.
  215. //! \a prefix (which has a trailing '/') should be used as a prefix to
  216. //! the key of each setting. true is returned if there is no error.
  217. //!
  218. bool writeProperties(QSettings &qs,const QString &prefix) const;
  219. private:
  220. void setAtElseProp();
  221. void setCommentProp();
  222. void setCompactProp();
  223. void setPackagesProp();
  224. void setPODBlocksProp();
  225. bool fold_atelse;
  226. bool fold_comments;
  227. bool fold_compact;
  228. bool fold_packages;
  229. bool fold_pod_blocks;
  230. QsciLexerPerl(const QsciLexerPerl &);
  231. QsciLexerPerl &operator=(const QsciLexerPerl &);
  232. };
  233. #endif