qscilexercmake.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. // This module implements the QsciLexerCMake 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/qscilexercmake.h"
  20. #include <qcolor.h>
  21. #include <qfont.h>
  22. #include <qsettings.h>
  23. // The ctor.
  24. QsciLexerCMake::QsciLexerCMake(QObject *parent)
  25. : QsciLexer(parent), fold_atelse(false)
  26. {
  27. }
  28. // The dtor.
  29. QsciLexerCMake::~QsciLexerCMake()
  30. {
  31. }
  32. // Returns the language name.
  33. const char *QsciLexerCMake::language() const
  34. {
  35. return "CMake";
  36. }
  37. // Returns the lexer name.
  38. const char *QsciLexerCMake::lexer() const
  39. {
  40. return "cmake";
  41. }
  42. // Returns the foreground colour of the text for a style.
  43. QColor QsciLexerCMake::defaultColor(int style) const
  44. {
  45. switch (style)
  46. {
  47. case Default:
  48. case KeywordSet3:
  49. return QColor(0x00,0x00,0x00);
  50. case Comment:
  51. return QColor(0x00,0x7f,0x00);
  52. case String:
  53. case StringLeftQuote:
  54. case StringRightQuote:
  55. return QColor(0x7f,0x00,0x7f);
  56. case Function:
  57. case BlockWhile:
  58. case BlockForeach:
  59. case BlockIf:
  60. case BlockMacro:
  61. return QColor(0x00,0x00,0x7f);
  62. case Variable:
  63. return QColor(0x80,0x00,0x00);
  64. case Label:
  65. case StringVariable:
  66. return QColor(0xcc,0x33,0x00);
  67. case Number:
  68. return QColor(0x00,0x7f,0x7f);
  69. }
  70. return QsciLexer::defaultColor(style);
  71. }
  72. // Returns the font of the text for a style.
  73. QFont QsciLexerCMake::defaultFont(int style) const
  74. {
  75. QFont f;
  76. switch (style)
  77. {
  78. case Comment:
  79. #if defined(Q_OS_WIN)
  80. f = QFont("Comic Sans MS",9);
  81. #elif defined(Q_OS_MAC)
  82. f = QFont("Comic Sans MS", 12);
  83. #else
  84. f = QFont("Bitstream Vera Serif",9);
  85. #endif
  86. break;
  87. case Function:
  88. case BlockWhile:
  89. case BlockForeach:
  90. case BlockIf:
  91. case BlockMacro:
  92. f = QsciLexer::defaultFont(style);
  93. f.setBold(true);
  94. break;
  95. default:
  96. f = QsciLexer::defaultFont(style);
  97. }
  98. return f;
  99. }
  100. // Returns the set of keywords.
  101. const char *QsciLexerCMake::keywords(int set) const
  102. {
  103. if (set == 1)
  104. return
  105. "add_custom_command add_custom_target add_definitions "
  106. "add_dependencies add_executable add_library add_subdirectory "
  107. "add_test aux_source_directory build_command build_name "
  108. "cmake_minimum_required configure_file create_test_sourcelist "
  109. "else elseif enable_language enable_testing endforeach endif "
  110. "endmacro endwhile exec_program execute_process "
  111. "export_library_dependencies file find_file find_library "
  112. "find_package find_path find_program fltk_wrap_ui foreach "
  113. "get_cmake_property get_directory_property get_filename_component "
  114. "get_source_file_property get_target_property get_test_property "
  115. "if include include_directories include_external_msproject "
  116. "include_regular_expression install install_files "
  117. "install_programs install_targets link_directories link_libraries "
  118. "list load_cache load_command macro make_directory "
  119. "mark_as_advanced math message option output_required_files "
  120. "project qt_wrap_cpp qt_wrap_ui remove remove_definitions "
  121. "separate_arguments set set_directory_properties "
  122. "set_source_files_properties set_target_properties "
  123. "set_tests_properties site_name source_group string "
  124. "subdir_depends subdirs target_link_libraries try_compile try_run "
  125. "use_mangled_mesa utility_source variable_requires "
  126. "vtk_make_instantiator vtk_wrap_java vtk_wrap_python vtk_wrap_tcl "
  127. "while write_file";
  128. if (set == 2)
  129. return
  130. "ABSOLUTE ABSTRACT ADDITIONAL_MAKE_CLEAN_FILES ALL AND APPEND "
  131. "ARGS ASCII BEFORE CACHE CACHE_VARIABLES CLEAR COMMAND COMMANDS "
  132. "COMMAND_NAME COMMENT COMPARE COMPILE_FLAGS COPYONLY DEFINED "
  133. "DEFINE_SYMBOL DEPENDS DOC EQUAL ESCAPE_QUOTES EXCLUDE "
  134. "EXCLUDE_FROM_ALL EXISTS EXPORT_MACRO EXT EXTRA_INCLUDE "
  135. "FATAL_ERROR FILE FILES FORCE FUNCTION GENERATED GLOB "
  136. "GLOB_RECURSE GREATER GROUP_SIZE HEADER_FILE_ONLY HEADER_LOCATION "
  137. "IMMEDIATE INCLUDES INCLUDE_DIRECTORIES INCLUDE_INTERNALS "
  138. "INCLUDE_REGULAR_EXPRESSION LESS LINK_DIRECTORIES LINK_FLAGS "
  139. "LOCATION MACOSX_BUNDLE MACROS MAIN_DEPENDENCY MAKE_DIRECTORY "
  140. "MATCH MATCHALL MATCHES MODULE NAME NAME_WE NOT NOTEQUAL "
  141. "NO_SYSTEM_PATH OBJECT_DEPENDS OPTIONAL OR OUTPUT OUTPUT_VARIABLE "
  142. "PATH PATHS POST_BUILD POST_INSTALL_SCRIPT PREFIX PREORDER "
  143. "PRE_BUILD PRE_INSTALL_SCRIPT PRE_LINK PROGRAM PROGRAM_ARGS "
  144. "PROPERTIES QUIET RANGE READ REGEX REGULAR_EXPRESSION REPLACE "
  145. "REQUIRED RETURN_VALUE RUNTIME_DIRECTORY SEND_ERROR SHARED "
  146. "SOURCES STATIC STATUS STREQUAL STRGREATER STRLESS SUFFIX TARGET "
  147. "TOLOWER TOUPPER VAR VARIABLES VERSION WIN32 WRAP_EXCLUDE WRITE "
  148. "APPLE MINGW MSYS CYGWIN BORLAND WATCOM MSVC MSVC_IDE MSVC60 "
  149. "MSVC70 MSVC71 MSVC80 CMAKE_COMPILER_2005 OFF ON";
  150. return 0;
  151. }
  152. // Returns the user name of a style.
  153. QString QsciLexerCMake::description(int style) const
  154. {
  155. switch (style)
  156. {
  157. case Default:
  158. return tr("Default");
  159. case Comment:
  160. return tr("Comment");
  161. case String:
  162. return tr("String");
  163. case StringLeftQuote:
  164. return tr("Left quoted string");
  165. case StringRightQuote:
  166. return tr("Right quoted string");
  167. case Function:
  168. return tr("Function");
  169. case Variable:
  170. return tr("Variable");
  171. case Label:
  172. return tr("Label");
  173. case KeywordSet3:
  174. return tr("User defined");
  175. case BlockWhile:
  176. return tr("WHILE block");
  177. case BlockForeach:
  178. return tr("FOREACH block");
  179. case BlockIf:
  180. return tr("IF block");
  181. case BlockMacro:
  182. return tr("MACRO block");
  183. case StringVariable:
  184. return tr("Variable within a string");
  185. case Number:
  186. return tr("Number");
  187. }
  188. return QString();
  189. }
  190. // Returns the background colour of the text for a style.
  191. QColor QsciLexerCMake::defaultPaper(int style) const
  192. {
  193. switch (style)
  194. {
  195. case String:
  196. case StringLeftQuote:
  197. case StringRightQuote:
  198. case StringVariable:
  199. return QColor(0xee,0xee,0xee);
  200. }
  201. return QsciLexer::defaultPaper(style);
  202. }
  203. // Refresh all properties.
  204. void QsciLexerCMake::refreshProperties()
  205. {
  206. setAtElseProp();
  207. }
  208. // Read properties from the settings.
  209. bool QsciLexerCMake::readProperties(QSettings &qs,const QString &prefix)
  210. {
  211. int rc = true;
  212. fold_atelse = qs.value(prefix + "foldatelse", false).toBool();
  213. return rc;
  214. }
  215. // Write properties to the settings.
  216. bool QsciLexerCMake::writeProperties(QSettings &qs,const QString &prefix) const
  217. {
  218. int rc = true;
  219. qs.setValue(prefix + "foldatelse", fold_atelse);
  220. return rc;
  221. }
  222. // Return true if ELSE blocks can be folded.
  223. bool QsciLexerCMake::foldAtElse() const
  224. {
  225. return fold_atelse;
  226. }
  227. // Set if ELSE blocks can be folded.
  228. void QsciLexerCMake::setFoldAtElse(bool fold)
  229. {
  230. fold_atelse = fold;
  231. setAtElseProp();
  232. }
  233. // Set the "fold.at.else" property.
  234. void QsciLexerCMake::setAtElseProp()
  235. {
  236. emit propertyChanged("fold.at.else",(fold_atelse ? "1" : "0"));
  237. }