qscilexerhtml.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. // This defines the interface to the QsciLexerHTML 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 QSCILEXERHTML_H
  20. #define QSCILEXERHTML_H
  21. #include <QObject>
  22. #include <Qsci/qsciglobal.h>
  23. #include <Qsci/qscilexer.h>
  24. //! \brief The QsciLexerHTML class encapsulates the Scintilla HTML lexer.
  25. class QSCINTILLA_EXPORT QsciLexerHTML : public QsciLexer
  26. {
  27. Q_OBJECT
  28. public:
  29. //! This enum defines the meanings of the different styles used by the
  30. //! HTML lexer.
  31. enum {
  32. //! The default.
  33. Default = 0,
  34. //! A tag.
  35. Tag = 1,
  36. //! An unknown tag.
  37. UnknownTag = 2,
  38. //! An attribute.
  39. Attribute = 3,
  40. //! An unknown attribute.
  41. UnknownAttribute = 4,
  42. //! An HTML number.
  43. HTMLNumber = 5,
  44. //! An HTML double-quoted string.
  45. HTMLDoubleQuotedString = 6,
  46. //! An HTML single-quoted string.
  47. HTMLSingleQuotedString = 7,
  48. //! Other text within a tag.
  49. OtherInTag = 8,
  50. //! An HTML comment.
  51. HTMLComment = 9,
  52. //! An entity.
  53. Entity = 10,
  54. //! The end of an XML style tag.
  55. XMLTagEnd = 11,
  56. //! The start of an XML fragment.
  57. XMLStart = 12,
  58. //! The end of an XML fragment.
  59. XMLEnd = 13,
  60. //! A script tag.
  61. Script = 14,
  62. //! The start of an ASP fragment with @.
  63. ASPAtStart = 15,
  64. //! The start of an ASP fragment.
  65. ASPStart = 16,
  66. //! CDATA.
  67. CDATA = 17,
  68. //! The start of a PHP fragment.
  69. PHPStart = 18,
  70. //! An unquoted HTML value.
  71. HTMLValue = 19,
  72. //! An ASP X-Code comment.
  73. ASPXCComment = 20,
  74. //! The default for SGML.
  75. SGMLDefault = 21,
  76. //! An SGML command.
  77. SGMLCommand = 22,
  78. //! The first parameter of an SGML command.
  79. SGMLParameter = 23,
  80. //! An SGML double-quoted string.
  81. SGMLDoubleQuotedString = 24,
  82. //! An SGML single-quoted string.
  83. SGMLSingleQuotedString = 25,
  84. //! An SGML error.
  85. SGMLError = 26,
  86. //! An SGML special entity.
  87. SGMLSpecial = 27,
  88. //! An SGML entity.
  89. SGMLEntity = 28,
  90. //! An SGML comment.
  91. SGMLComment = 29,
  92. //! A comment with the first parameter of an SGML command.
  93. SGMLParameterComment = 30,
  94. //! The default for an SGML block.
  95. SGMLBlockDefault = 31,
  96. //! The start of a JavaScript fragment.
  97. JavaScriptStart = 40,
  98. //! The default for JavaScript.
  99. JavaScriptDefault = 41,
  100. //! A JavaScript comment.
  101. JavaScriptComment = 42,
  102. //! A JavaScript line comment.
  103. JavaScriptCommentLine = 43,
  104. //! A JavaDoc style JavaScript comment.
  105. JavaScriptCommentDoc = 44,
  106. //! A JavaScript number.
  107. JavaScriptNumber = 45,
  108. //! A JavaScript word.
  109. JavaScriptWord = 46,
  110. //! A JavaScript keyword.
  111. JavaScriptKeyword = 47,
  112. //! A JavaScript double-quoted string.
  113. JavaScriptDoubleQuotedString = 48,
  114. //! A JavaScript single-quoted string.
  115. JavaScriptSingleQuotedString = 49,
  116. //! A JavaScript symbol.
  117. JavaScriptSymbol = 50,
  118. //! The end of a JavaScript line where a string is not closed.
  119. JavaScriptUnclosedString = 51,
  120. //! A JavaScript regular expression.
  121. JavaScriptRegex = 52,
  122. //! The start of an ASP JavaScript fragment.
  123. ASPJavaScriptStart = 55,
  124. //! The default for ASP JavaScript.
  125. ASPJavaScriptDefault = 56,
  126. //! An ASP JavaScript comment.
  127. ASPJavaScriptComment = 57,
  128. //! An ASP JavaScript line comment.
  129. ASPJavaScriptCommentLine = 58,
  130. //! An ASP JavaDoc style JavaScript comment.
  131. ASPJavaScriptCommentDoc = 59,
  132. //! An ASP JavaScript number.
  133. ASPJavaScriptNumber = 60,
  134. //! An ASP JavaScript word.
  135. ASPJavaScriptWord = 61,
  136. //! An ASP JavaScript keyword.
  137. ASPJavaScriptKeyword = 62,
  138. //! An ASP JavaScript double-quoted string.
  139. ASPJavaScriptDoubleQuotedString = 63,
  140. //! An ASP JavaScript single-quoted string.
  141. ASPJavaScriptSingleQuotedString = 64,
  142. //! An ASP JavaScript symbol.
  143. ASPJavaScriptSymbol = 65,
  144. //! The end of an ASP JavaScript line where a string is not
  145. //! closed.
  146. ASPJavaScriptUnclosedString = 66,
  147. //! An ASP JavaScript regular expression.
  148. ASPJavaScriptRegex = 67,
  149. //! The start of a VBScript fragment.
  150. VBScriptStart = 70,
  151. //! The default for VBScript.
  152. VBScriptDefault = 71,
  153. //! A VBScript comment.
  154. VBScriptComment = 72,
  155. //! A VBScript number.
  156. VBScriptNumber = 73,
  157. //! A VBScript keyword.
  158. VBScriptKeyword = 74,
  159. //! A VBScript string.
  160. VBScriptString = 75,
  161. //! A VBScript identifier.
  162. VBScriptIdentifier = 76,
  163. //! The end of a VBScript line where a string is not closed.
  164. VBScriptUnclosedString = 77,
  165. //! The start of an ASP VBScript fragment.
  166. ASPVBScriptStart = 80,
  167. //! The default for ASP VBScript.
  168. ASPVBScriptDefault = 81,
  169. //! An ASP VBScript comment.
  170. ASPVBScriptComment = 82,
  171. //! An ASP VBScript number.
  172. ASPVBScriptNumber = 83,
  173. //! An ASP VBScript keyword.
  174. ASPVBScriptKeyword = 84,
  175. //! An ASP VBScript string.
  176. ASPVBScriptString = 85,
  177. //! An ASP VBScript identifier.
  178. ASPVBScriptIdentifier = 86,
  179. //! The end of an ASP VBScript line where a string is not
  180. //! closed.
  181. ASPVBScriptUnclosedString = 87,
  182. //! The start of a Python fragment.
  183. PythonStart = 90,
  184. //! The default for Python.
  185. PythonDefault = 91,
  186. //! A Python comment.
  187. PythonComment = 92,
  188. //! A Python number.
  189. PythonNumber = 93,
  190. //! A Python double-quoted string.
  191. PythonDoubleQuotedString = 94,
  192. //! A Python single-quoted string.
  193. PythonSingleQuotedString = 95,
  194. //! A Python keyword.
  195. PythonKeyword = 96,
  196. //! A Python triple single-quoted string.
  197. PythonTripleSingleQuotedString = 97,
  198. //! A Python triple double-quoted string.
  199. PythonTripleDoubleQuotedString = 98,
  200. //! The name of a Python class.
  201. PythonClassName = 99,
  202. //! The name of a Python function or method.
  203. PythonFunctionMethodName = 100,
  204. //! A Python operator.
  205. PythonOperator = 101,
  206. //! A Python identifier.
  207. PythonIdentifier = 102,
  208. //! The start of an ASP Python fragment.
  209. ASPPythonStart = 105,
  210. //! The default for ASP Python.
  211. ASPPythonDefault = 106,
  212. //! An ASP Python comment.
  213. ASPPythonComment = 107,
  214. //! An ASP Python number.
  215. ASPPythonNumber = 108,
  216. //! An ASP Python double-quoted string.
  217. ASPPythonDoubleQuotedString = 109,
  218. //! An ASP Python single-quoted string.
  219. ASPPythonSingleQuotedString = 110,
  220. //! An ASP Python keyword.
  221. ASPPythonKeyword = 111,
  222. //! An ASP Python triple single-quoted string.
  223. ASPPythonTripleSingleQuotedString = 112,
  224. //! An ASP Python triple double-quoted string.
  225. ASPPythonTripleDoubleQuotedString = 113,
  226. //! The name of an ASP Python class.
  227. ASPPythonClassName = 114,
  228. //! The name of an ASP Python function or method.
  229. ASPPythonFunctionMethodName = 115,
  230. //! An ASP Python operator.
  231. ASPPythonOperator = 116,
  232. //! An ASP Python identifier
  233. ASPPythonIdentifier = 117,
  234. //! The default for PHP.
  235. PHPDefault = 118,
  236. //! A PHP double-quoted string.
  237. PHPDoubleQuotedString = 119,
  238. //! A PHP single-quoted string.
  239. PHPSingleQuotedString = 120,
  240. //! A PHP keyword.
  241. PHPKeyword = 121,
  242. //! A PHP number.
  243. PHPNumber = 122,
  244. //! A PHP variable.
  245. PHPVariable = 123,
  246. //! A PHP comment.
  247. PHPComment = 124,
  248. //! A PHP line comment.
  249. PHPCommentLine = 125,
  250. //! A PHP double-quoted variable.
  251. PHPDoubleQuotedVariable = 126,
  252. //! A PHP operator.
  253. PHPOperator = 127
  254. };
  255. //! Construct a QsciLexerHTML with parent \a parent. \a parent is
  256. //! typically the QsciScintilla instance.
  257. QsciLexerHTML(QObject *parent = 0);
  258. //! Destroys the QsciLexerHTML instance.
  259. virtual ~QsciLexerHTML();
  260. //! Returns the name of the language.
  261. const char *language() const;
  262. //! Returns the name of the lexer. Some lexers support a number of
  263. //! languages.
  264. const char *lexer() const;
  265. //! \internal Returns the auto-completion fillup characters.
  266. const char *autoCompletionFillups() const;
  267. //! Returns the string of characters that comprise a word.
  268. const char *wordCharacters() const;
  269. //! Returns the foreground colour of the text for style number \a style.
  270. //!
  271. //! \sa defaultPaper()
  272. QColor defaultColor(int style) const;
  273. //! Returns the end-of-line fill for style number \a style.
  274. bool defaultEolFill(int style) const;
  275. //! Returns the font for style number \a style.
  276. QFont defaultFont(int style) const;
  277. //! Returns the background colour of the text for style number \a style.
  278. //!
  279. //! \sa defaultColor()
  280. QColor defaultPaper(int style) const;
  281. //! Returns the set of keywords for the keyword set \a set recognised
  282. //! by the lexer as a space separated string.
  283. const char *keywords(int set) const;
  284. //! Returns the descriptive name for style number \a style. If the
  285. //! style is invalid for this language then an empty QString is returned.
  286. //! This is intended to be used in user preference dialogs.
  287. QString description(int style) const;
  288. //! Causes all properties to be refreshed by emitting the
  289. //! propertyChanged() signal as required.
  290. void refreshProperties();
  291. //! Returns true if tags are case sensitive.
  292. //!
  293. //! \sa setCaseSensitiveTags()
  294. bool caseSensitiveTags() const {return case_sens_tags;}
  295. //! If \a enabled is true then Django templates are enabled. The default
  296. //! is false.
  297. //!
  298. //! \sa djangoTemplates()
  299. void setDjangoTemplates(bool enabled);
  300. //! Returns true if support for Django templates is enabled.
  301. //!
  302. //! \sa setDjangoTemplates()
  303. bool djangoTemplates() const {return django_templates;}
  304. //! Returns true if trailing blank lines are included in a fold block.
  305. //!
  306. //! \sa setFoldCompact()
  307. bool foldCompact() const {return fold_compact;}
  308. //! Returns true if preprocessor blocks can be folded.
  309. //!
  310. //! \sa setFoldPreprocessor()
  311. bool foldPreprocessor() const {return fold_preproc;}
  312. //! If \a fold is true then script comments can be folded. The default is
  313. //! false.
  314. //!
  315. //! \sa foldScriptComments()
  316. void setFoldScriptComments(bool fold);
  317. //! Returns true if script comments can be folded.
  318. //!
  319. //! \sa setFoldScriptComments()
  320. bool foldScriptComments() const {return fold_script_comments;}
  321. //! If \a fold is true then script heredocs can be folded. The default is
  322. //! false.
  323. //!
  324. //! \sa foldScriptHeredocs()
  325. void setFoldScriptHeredocs(bool fold);
  326. //! Returns true if script heredocs can be folded.
  327. //!
  328. //! \sa setFoldScriptHeredocs()
  329. bool foldScriptHeredocs() const {return fold_script_heredocs;}
  330. //! If \a enabled is true then Mako templates are enabled. The default is
  331. //! false.
  332. //!
  333. //! \sa makoTemplates()
  334. void setMakoTemplates(bool enabled);
  335. //! Returns true if support for Mako templates is enabled.
  336. //!
  337. //! \sa setMakoTemplates()
  338. bool makoTemplates() const {return mako_templates;}
  339. public slots:
  340. //! If \a fold is true then trailing blank lines are included in a fold
  341. //! block. The default is true.
  342. //!
  343. //! \sa foldCompact()
  344. virtual void setFoldCompact(bool fold);
  345. //! If \a fold is true then preprocessor blocks can be folded. The
  346. //! default is false.
  347. //!
  348. //! \sa foldPreprocessor()
  349. virtual void setFoldPreprocessor(bool fold);
  350. //! If \a sens is true then tags are case sensitive. The default is false.
  351. //!
  352. //! \sa caseSensitiveTags()
  353. virtual void setCaseSensitiveTags(bool sens);
  354. protected:
  355. //! The lexer's properties are read from the settings \a qs. \a prefix
  356. //! (which has a trailing '/') should be used as a prefix to the key of
  357. //! each setting. true is returned if there is no error.
  358. //!
  359. bool readProperties(QSettings &qs,const QString &prefix);
  360. //! The lexer's properties are written to the settings \a qs.
  361. //! \a prefix (which has a trailing '/') should be used as a prefix to
  362. //! the key of each setting. true is returned if there is no error.
  363. //!
  364. bool writeProperties(QSettings &qs,const QString &prefix) const;
  365. private:
  366. void setCompactProp();
  367. void setPreprocProp();
  368. void setCaseSensTagsProp();
  369. void setScriptCommentsProp();
  370. void setScriptHeredocsProp();
  371. void setDjangoProp();
  372. void setMakoProp();
  373. bool fold_compact;
  374. bool fold_preproc;
  375. bool case_sens_tags;
  376. bool fold_script_comments;
  377. bool fold_script_heredocs;
  378. bool django_templates;
  379. bool mako_templates;
  380. QsciLexerHTML(const QsciLexerHTML &);
  381. QsciLexerHTML &operator=(const QsciLexerHTML &);
  382. };
  383. #endif