qscilexerverilog.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. // This defines the interface to the QsciLexerVerilog 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 QSCILEXERVERILOG_H
  20. #define QSCILEXERVERILOG_H
  21. #include <QObject>
  22. #include <Qsci/qsciglobal.h>
  23. #include <Qsci/qscilexer.h>
  24. //! \brief The QsciLexerVerilog class encapsulates the Scintilla Verilog
  25. //! lexer.
  26. class QSCINTILLA_EXPORT QsciLexerVerilog : public QsciLexer
  27. {
  28. Q_OBJECT
  29. public:
  30. //! This enum defines the meanings of the different styles used by the
  31. //! Verilog lexer.
  32. enum {
  33. //! The default.
  34. Default = 0,
  35. InactiveDefault = Default + 64,
  36. //! A comment.
  37. Comment = 1,
  38. InactiveComment = Comment + 64,
  39. //! A line comment.
  40. CommentLine = 2,
  41. InactiveCommentLine = CommentLine + 64,
  42. //! A bang comment.
  43. CommentBang = 3,
  44. InactiveCommentBang = CommentBang + 64,
  45. //! A number
  46. Number = 4,
  47. InactiveNumber = Number + 64,
  48. //! A keyword.
  49. Keyword = 5,
  50. InactiveKeyword = Keyword + 64,
  51. //! A string.
  52. String = 6,
  53. InactiveString = String + 64,
  54. //! A keyword defined in keyword set number 2. The class must
  55. //! be sub-classed and re-implement keywords() to make use of
  56. //! this style.
  57. KeywordSet2 = 7,
  58. InactiveKeywordSet2 = KeywordSet2 + 64,
  59. //! A system task.
  60. SystemTask = 8,
  61. InactiveSystemTask = SystemTask + 64,
  62. //! A pre-processor block.
  63. Preprocessor = 9,
  64. InactivePreprocessor = Preprocessor + 64,
  65. //! An operator.
  66. Operator = 10,
  67. InactiveOperator = Operator + 64,
  68. //! An identifier.
  69. Identifier = 11,
  70. InactiveIdentifier = Identifier + 64,
  71. //! The end of a line where a string is not closed.
  72. UnclosedString = 12,
  73. InactiveUnclosedString = UnclosedString + 64,
  74. //! A keyword defined in keyword set number 4. The class must
  75. //! be sub-classed and re-implement keywords() to make use of
  76. //! this style. This set is intended to be used for user defined
  77. //! identifiers and tasks.
  78. UserKeywordSet = 19,
  79. InactiveUserKeywordSet = UserKeywordSet + 64,
  80. //! A keyword comment.
  81. CommentKeyword = 20,
  82. InactiveCommentKeyword = CommentKeyword + 64,
  83. //! An input port declaration.
  84. DeclareInputPort = 21,
  85. InactiveDeclareInputPort = DeclareInputPort + 64,
  86. //! An output port declaration.
  87. DeclareOutputPort = 22,
  88. InactiveDeclareOutputPort = DeclareOutputPort + 64,
  89. //! An input/output port declaration.
  90. DeclareInputOutputPort = 23,
  91. InactiveDeclareInputOutputPort = DeclareInputOutputPort + 64,
  92. //! A port connection.
  93. PortConnection = 24,
  94. InactivePortConnection = PortConnection + 64,
  95. };
  96. //! Construct a QsciLexerVerilog with parent \a parent. \a parent is
  97. //! typically the QsciScintilla instance.
  98. QsciLexerVerilog(QObject *parent = 0);
  99. //! Destroys the QsciLexerVerilog instance.
  100. virtual ~QsciLexerVerilog();
  101. //! Returns the name of the language.
  102. const char *language() const;
  103. //! Returns the name of the lexer. Some lexers support a number of
  104. //! languages.
  105. const char *lexer() const;
  106. //! \internal Returns the style used for braces for brace matching.
  107. int braceStyle() const;
  108. //! Returns the string of characters that comprise a word.
  109. const char *wordCharacters() const;
  110. //! Returns the foreground colour of the text for style number \a style.
  111. //!
  112. //! \sa defaultPaper()
  113. QColor defaultColor(int style) const;
  114. //! Returns the end-of-line fill for style number \a style.
  115. bool defaultEolFill(int style) const;
  116. //! Returns the font for style number \a style.
  117. QFont defaultFont(int style) const;
  118. //! Returns the background colour of the text for style number \a style.
  119. //!
  120. //! \sa defaultColor()
  121. QColor defaultPaper(int style) const;
  122. //! Returns the set of keywords for the keyword set \a set recognised
  123. //! by the lexer as a space separated string.
  124. const char *keywords(int set) const;
  125. //! Returns the descriptive name for style number \a style. If the
  126. //! style is invalid for this language then an empty QString is returned.
  127. //! This is intended to be used in user preference dialogs.
  128. QString description(int style) const;
  129. //! Causes all properties to be refreshed by emitting the
  130. //! propertyChanged() signal as required.
  131. void refreshProperties();
  132. //! If \a fold is true then "} else {" lines can be folded. The
  133. //! default is false.
  134. //!
  135. //! \sa foldAtElse()
  136. void setFoldAtElse(bool fold);
  137. //! Returns true if "} else {" lines can be folded.
  138. //!
  139. //! \sa setFoldAtElse()
  140. bool foldAtElse() const {return fold_atelse;}
  141. //! If \a fold is true then multi-line comment blocks can be folded.
  142. //! The default is false.
  143. //!
  144. //! \sa foldComments()
  145. void setFoldComments(bool fold);
  146. //! Returns true if multi-line comment blocks can be folded.
  147. //!
  148. //! \sa setFoldComments()
  149. bool foldComments() const {return fold_comments;}
  150. //! If \a fold is true then trailing blank lines are included in a fold
  151. //! block. The default is true.
  152. //!
  153. //! \sa foldCompact()
  154. void setFoldCompact(bool fold);
  155. //! Returns true if trailing blank lines are included in a fold block.
  156. //!
  157. //! \sa setFoldCompact()
  158. bool foldCompact() const {return fold_compact;};
  159. //! If \a fold is true then preprocessor blocks can be folded. The
  160. //! default is true.
  161. //!
  162. //! \sa foldPreprocessor()
  163. void setFoldPreprocessor(bool fold);
  164. //! Returns true if preprocessor blocks can be folded.
  165. //!
  166. //! \sa setFoldPreprocessor()
  167. bool foldPreprocessor() const {return fold_preproc;};
  168. //! If \a fold is true then modules can be folded. The default is false.
  169. //!
  170. //! \sa foldAtModule()
  171. void setFoldAtModule(bool fold);
  172. //! Returns true if modules can be folded.
  173. //!
  174. //! \sa setFoldAtModule()
  175. bool foldAtModule() const {return fold_atmodule;};
  176. protected:
  177. //! The lexer's properties are read from the settings \a qs. \a prefix
  178. //! (which has a trailing '/') should be used as a prefix to the key of
  179. //! each setting. true is returned if there is no error.
  180. //!
  181. //! \sa writeProperties()
  182. bool readProperties(QSettings &qs,const QString &prefix);
  183. //! The lexer's properties are written to the settings \a qs.
  184. //! \a prefix (which has a trailing '/') should be used as a prefix to
  185. //! the key of each setting. true is returned if there is no error.
  186. //!
  187. //! \sa readProperties()
  188. bool writeProperties(QSettings &qs,const QString &prefix) const;
  189. private:
  190. void setAtElseProp();
  191. void setCommentProp();
  192. void setCompactProp();
  193. void setPreprocProp();
  194. void setAtModuleProp();
  195. bool fold_atelse;
  196. bool fold_comments;
  197. bool fold_compact;
  198. bool fold_preproc;
  199. bool fold_atmodule;
  200. QsciLexerVerilog(const QsciLexerVerilog &);
  201. QsciLexerVerilog &operator=(const QsciLexerVerilog &);
  202. };
  203. #endif