qscilexervhdl.cpp 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. // This module implements the QsciLexerVHDL 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. #include "Qsci/qscilexervhdl.h"
  20. #include <qcolor.h>
  21. #include <qfont.h>
  22. #include <qsettings.h>
  23. // The ctor.
  24. QsciLexerVHDL::QsciLexerVHDL(QObject *parent)
  25. : QsciLexer(parent),
  26. fold_comments(true), fold_compact(true), fold_atelse(true),
  27. fold_atbegin(true), fold_atparenth(true)
  28. {
  29. }
  30. // The dtor.
  31. QsciLexerVHDL::~QsciLexerVHDL()
  32. {
  33. }
  34. // Returns the language name.
  35. const char *QsciLexerVHDL::language() const
  36. {
  37. return "VHDL";
  38. }
  39. // Returns the lexer name.
  40. const char *QsciLexerVHDL::lexer() const
  41. {
  42. return "vhdl";
  43. }
  44. // Return the style used for braces.
  45. int QsciLexerVHDL::braceStyle() const
  46. {
  47. return Attribute;
  48. }
  49. // Returns the foreground colour of the text for a style.
  50. QColor QsciLexerVHDL::defaultColor(int style) const
  51. {
  52. switch (style)
  53. {
  54. case Default:
  55. return QColor(0x80,0x00,0x80);
  56. case Comment:
  57. return QColor(0x00,0x7f,0x00);
  58. case CommentLine:
  59. return QColor(0x3f,0x7f,0x3f);
  60. case Number:
  61. case StandardOperator:
  62. return QColor(0x00,0x7f,0x7f);
  63. case String:
  64. return QColor(0x7f,0x00,0x7f);
  65. case UnclosedString:
  66. return QColor(0x00,0x00,0x00);
  67. case Keyword:
  68. return QColor(0x00,0x00,0x7f);
  69. case Attribute:
  70. return QColor(0x80,0x40,0x20);
  71. case StandardFunction:
  72. return QColor(0x80,0x80,0x20);
  73. case StandardPackage:
  74. return QColor(0x20,0x80,0x20);
  75. case StandardType:
  76. return QColor(0x20,0x80,0x80);
  77. case KeywordSet7:
  78. return QColor(0x80,0x40,0x20);
  79. }
  80. return QsciLexer::defaultColor(style);
  81. }
  82. // Returns the end-of-line fill for a style.
  83. bool QsciLexerVHDL::defaultEolFill(int style) const
  84. {
  85. if (style == UnclosedString)
  86. return true;
  87. return QsciLexer::defaultEolFill(style);
  88. }
  89. // Returns the font of the text for a style.
  90. QFont QsciLexerVHDL::defaultFont(int style) const
  91. {
  92. QFont f;
  93. switch (style)
  94. {
  95. case Comment:
  96. case CommentLine:
  97. case KeywordSet7:
  98. #if defined(Q_OS_WIN)
  99. f = QFont("Comic Sans MS",9);
  100. #elif defined(Q_OS_MAC)
  101. f = QFont("Comic Sans MS", 12);
  102. #else
  103. f = QFont("Bitstream Vera Serif",9);
  104. #endif
  105. break;
  106. default:
  107. f = QsciLexer::defaultFont(style);
  108. }
  109. return f;
  110. }
  111. // Returns the set of keywords.
  112. const char *QsciLexerVHDL::keywords(int set) const
  113. {
  114. if (set == 1)
  115. return
  116. "access after alias all architecture array assert attribute begin "
  117. "block body buffer bus case component configuration constant "
  118. "disconnect downto else elsif end entity exit file for function "
  119. "generate generic group guarded if impure in inertial inout is "
  120. "label library linkage literal loop map new next null of on open "
  121. "others out package port postponed procedure process pure range "
  122. "record register reject report return select severity shared "
  123. "signal subtype then to transport type unaffected units until use "
  124. "variable wait when while with";
  125. if (set == 2)
  126. return
  127. "abs and mod nand nor not or rem rol ror sla sll sra srl xnor xor";
  128. if (set == 3)
  129. return
  130. "left right low high ascending image value pos val succ pred "
  131. "leftof rightof base range reverse_range length delayed stable "
  132. "quiet transaction event active last_event last_active last_value "
  133. "driving driving_value simple_name path_name instance_name";
  134. if (set == 4)
  135. return
  136. "now readline read writeline write endfile resolved to_bit "
  137. "to_bitvector to_stdulogic to_stdlogicvector to_stdulogicvector "
  138. "to_x01 to_x01z to_UX01 rising_edge falling_edge is_x shift_left "
  139. "shift_right rotate_left rotate_right resize to_integer "
  140. "to_unsigned to_signed std_match to_01";
  141. if (set == 5)
  142. return
  143. "std ieee work standard textio std_logic_1164 std_logic_arith "
  144. "std_logic_misc std_logic_signed std_logic_textio "
  145. "std_logic_unsigned numeric_bit numeric_std math_complex "
  146. "math_real vital_primitives vital_timing";
  147. if (set == 6)
  148. return
  149. "boolean bit character severity_level integer real time "
  150. "delay_length natural positive string bit_vector file_open_kind "
  151. "file_open_status line text side width std_ulogic "
  152. "std_ulogic_vector std_logic std_logic_vector X01 X01Z UX01 UX01Z "
  153. "unsigned signed";
  154. return 0;
  155. }
  156. // Returns the user name of a style.
  157. QString QsciLexerVHDL::description(int style) const
  158. {
  159. switch (style)
  160. {
  161. case Default:
  162. return tr("Default");
  163. case Comment:
  164. return tr("Comment");
  165. case CommentLine:
  166. return tr("Comment line");
  167. case Number:
  168. return tr("Number");
  169. case String:
  170. return tr("String");
  171. case Operator:
  172. return tr("Operator");
  173. case Identifier:
  174. return tr("Identifier");
  175. case UnclosedString:
  176. return tr("Unclosed string");
  177. case Keyword:
  178. return tr("Keyword");
  179. case StandardOperator:
  180. return tr("Standard operator");
  181. case Attribute:
  182. return tr("Attribute");
  183. case StandardFunction:
  184. return tr("Standard function");
  185. case StandardPackage:
  186. return tr("Standard package");
  187. case StandardType:
  188. return tr("Standard type");
  189. case KeywordSet7:
  190. return tr("User defined");
  191. case CommentBlock:
  192. return tr("Comment block");
  193. }
  194. return QString();
  195. }
  196. // Returns the background colour of the text for a style.
  197. QColor QsciLexerVHDL::defaultPaper(int style) const
  198. {
  199. if (style == UnclosedString)
  200. return QColor(0xe0,0xc0,0xe0);
  201. return QsciLexer::defaultPaper(style);
  202. }
  203. // Refresh all properties.
  204. void QsciLexerVHDL::refreshProperties()
  205. {
  206. setCommentProp();
  207. setCompactProp();
  208. setAtElseProp();
  209. setAtBeginProp();
  210. setAtParenthProp();
  211. }
  212. // Read properties from the settings.
  213. bool QsciLexerVHDL::readProperties(QSettings &qs,const QString &prefix)
  214. {
  215. fold_comments = qs.value(prefix + "foldcomments", true).toBool();
  216. fold_compact = qs.value(prefix + "foldcompact", true).toBool();
  217. fold_atelse = qs.value(prefix + "foldatelse", true).toBool();
  218. fold_atbegin = qs.value(prefix + "foldatbegin", true).toBool();
  219. fold_atparenth = qs.value(prefix + "foldatparenthesis", true).toBool();
  220. return true;
  221. }
  222. // Write properties to the settings.
  223. bool QsciLexerVHDL::writeProperties(QSettings &qs,const QString &prefix) const
  224. {
  225. qs.setValue(prefix + "foldcomments", fold_comments);
  226. qs.setValue(prefix + "foldcompact", fold_compact);
  227. qs.setValue(prefix + "foldatelse", fold_atelse);
  228. qs.setValue(prefix + "foldatbegin", fold_atbegin);
  229. qs.setValue(prefix + "foldatparenthesis", fold_atparenth);
  230. return true;
  231. }
  232. // Return true if comments can be folded.
  233. bool QsciLexerVHDL::foldComments() const
  234. {
  235. return fold_comments;
  236. }
  237. // Set if comments can be folded.
  238. void QsciLexerVHDL::setFoldComments(bool fold)
  239. {
  240. fold_comments = fold;
  241. setCommentProp();
  242. }
  243. // Set the "fold.comment" property.
  244. void QsciLexerVHDL::setCommentProp()
  245. {
  246. emit propertyChanged("fold.comment",(fold_comments ? "1" : "0"));
  247. }
  248. // Return true if folds are compact.
  249. bool QsciLexerVHDL::foldCompact() const
  250. {
  251. return fold_compact;
  252. }
  253. // Set if folds are compact
  254. void QsciLexerVHDL::setFoldCompact(bool fold)
  255. {
  256. fold_compact = fold;
  257. setCompactProp();
  258. }
  259. // Set the "fold.compact" property.
  260. void QsciLexerVHDL::setCompactProp()
  261. {
  262. emit propertyChanged("fold.compact",(fold_compact ? "1" : "0"));
  263. }
  264. // Return true if else blocks can be folded.
  265. bool QsciLexerVHDL::foldAtElse() const
  266. {
  267. return fold_atelse;
  268. }
  269. // Set if else blocks can be folded.
  270. void QsciLexerVHDL::setFoldAtElse(bool fold)
  271. {
  272. fold_atelse = fold;
  273. setAtElseProp();
  274. }
  275. // Set the "fold.at.else" property.
  276. void QsciLexerVHDL::setAtElseProp()
  277. {
  278. emit propertyChanged("fold.at.else",(fold_atelse ? "1" : "0"));
  279. }
  280. // Return true if begin blocks can be folded.
  281. bool QsciLexerVHDL::foldAtBegin() const
  282. {
  283. return fold_atbegin;
  284. }
  285. // Set if begin blocks can be folded.
  286. void QsciLexerVHDL::setFoldAtBegin(bool fold)
  287. {
  288. fold_atbegin = fold;
  289. setAtBeginProp();
  290. }
  291. // Set the "fold.at.Begin" property.
  292. void QsciLexerVHDL::setAtBeginProp()
  293. {
  294. emit propertyChanged("fold.at.Begin",(fold_atelse ? "1" : "0"));
  295. }
  296. // Return true if blocks can be folded at a parenthesis.
  297. bool QsciLexerVHDL::foldAtParenthesis() const
  298. {
  299. return fold_atparenth;
  300. }
  301. // Set if blocks can be folded at a parenthesis.
  302. void QsciLexerVHDL::setFoldAtParenthesis(bool fold)
  303. {
  304. fold_atparenth = fold;
  305. setAtParenthProp();
  306. }
  307. // Set the "fold.at.Parenthese" property.
  308. void QsciLexerVHDL::setAtParenthProp()
  309. {
  310. emit propertyChanged("fold.at.Parenthese",(fold_atparenth ? "1" : "0"));
  311. }