qscilexerfortran77.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. // This module implements the QsciLexerFortran77 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/qscilexerfortran77.h"
  20. #include <qcolor.h>
  21. #include <qfont.h>
  22. #include <qsettings.h>
  23. // The ctor.
  24. QsciLexerFortran77::QsciLexerFortran77(QObject *parent)
  25. : QsciLexer(parent), fold_compact(true)
  26. {
  27. }
  28. // The dtor.
  29. QsciLexerFortran77::~QsciLexerFortran77()
  30. {
  31. }
  32. // Returns the language name.
  33. const char *QsciLexerFortran77::language() const
  34. {
  35. return "Fortran77";
  36. }
  37. // Returns the lexer name.
  38. const char *QsciLexerFortran77::lexer() const
  39. {
  40. return "f77";
  41. }
  42. // Return the style used for braces.
  43. int QsciLexerFortran77::braceStyle() const
  44. {
  45. return Default;
  46. }
  47. // Returns the foreground colour of the text for a style.
  48. QColor QsciLexerFortran77::defaultColor(int style) const
  49. {
  50. switch (style)
  51. {
  52. case Default:
  53. return QColor(0x80,0x80,0x80);
  54. case Comment:
  55. return QColor(0x00,0x7f,0x00);
  56. case Number:
  57. return QColor(0x00,0x7f,0x7f);
  58. case SingleQuotedString:
  59. case DoubleQuotedString:
  60. return QColor(0x7f,0x00,0x7f);
  61. case UnclosedString:
  62. case Operator:
  63. case DottedOperator:
  64. case Continuation:
  65. return QColor(0x00,0x00,0x00);
  66. case Identifier:
  67. break;
  68. case Keyword:
  69. return QColor(0x00,0x00,0x7f);
  70. case IntrinsicFunction:
  71. return QColor(0xb0,0x00,0x40);
  72. case ExtendedFunction:
  73. return QColor(0xb0,0x40,0x80);
  74. case PreProcessor:
  75. return QColor(0x7f,0x7f,0x00);
  76. case Label:
  77. return QColor(0xe0,0xc0,0xe0);
  78. }
  79. return QsciLexer::defaultColor(style);
  80. }
  81. // Returns the end-of-line fill for a style.
  82. bool QsciLexerFortran77::defaultEolFill(int style) const
  83. {
  84. if (style == UnclosedString)
  85. return true;
  86. return QsciLexer::defaultEolFill(style);
  87. }
  88. // Returns the font of the text for a style.
  89. QFont QsciLexerFortran77::defaultFont(int style) const
  90. {
  91. QFont f;
  92. switch (style)
  93. {
  94. case Comment:
  95. #if defined(Q_OS_WIN)
  96. f = QFont("Comic Sans MS",9);
  97. #elif defined(Q_OS_MAC)
  98. f = QFont("Comic Sans MS", 12);
  99. #else
  100. f = QFont("Bitstream Vera Serif",9);
  101. #endif
  102. break;
  103. case Operator:
  104. case DottedOperator:
  105. f = QsciLexer::defaultFont(style);
  106. f.setBold(true);
  107. break;
  108. default:
  109. f = QsciLexer::defaultFont(style);
  110. }
  111. return f;
  112. }
  113. // Returns the set of keywords.
  114. const char *QsciLexerFortran77::keywords(int set) const
  115. {
  116. if (set == 1)
  117. return
  118. "access action advance allocatable allocate apostrophe assign "
  119. "assignment associate asynchronous backspace bind blank blockdata "
  120. "call case character class close common complex contains continue "
  121. "cycle data deallocate decimal delim default dimension direct do "
  122. "dowhile double doubleprecision else elseif elsewhere encoding "
  123. "end endassociate endblockdata enddo endfile endforall "
  124. "endfunction endif endinterface endmodule endprogram endselect "
  125. "endsubroutine endtype endwhere entry eor equivalence err errmsg "
  126. "exist exit external file flush fmt forall form format formatted "
  127. "function go goto id if implicit in include inout integer inquire "
  128. "intent interface intrinsic iomsg iolength iostat kind len "
  129. "logical module name named namelist nextrec nml none nullify "
  130. "number only open opened operator optional out pad parameter pass "
  131. "pause pending pointer pos position precision print private "
  132. "program protected public quote read readwrite real rec recl "
  133. "recursive result return rewind save select selectcase selecttype "
  134. "sequential sign size stat status stop stream subroutine target "
  135. "then to type unformatted unit use value volatile wait where "
  136. "while write";
  137. return 0;
  138. }
  139. // Returns the user name of a style.
  140. QString QsciLexerFortran77::description(int style) const
  141. {
  142. switch (style)
  143. {
  144. case Default:
  145. return tr("Default");
  146. case Comment:
  147. return tr("Comment");
  148. case Number:
  149. return tr("Number");
  150. case SingleQuotedString:
  151. return tr("Single-quoted string");
  152. case DoubleQuotedString:
  153. return tr("Double-quoted string");
  154. case UnclosedString:
  155. return tr("Unclosed string");
  156. case Operator:
  157. return tr("Operator");
  158. case Identifier:
  159. return tr("Identifier");
  160. case Keyword:
  161. return tr("Keyword");
  162. case IntrinsicFunction:
  163. return tr("Intrinsic function");
  164. case ExtendedFunction:
  165. return tr("Extended function");
  166. case PreProcessor:
  167. return tr("Pre-processor block");
  168. case DottedOperator:
  169. return tr("Dotted operator");
  170. case Label:
  171. return tr("Label");
  172. case Continuation:
  173. return tr("Continuation");
  174. }
  175. return QString();
  176. }
  177. // Returns the background colour of the text for a style.
  178. QColor QsciLexerFortran77::defaultPaper(int style) const
  179. {
  180. if (style == UnclosedString)
  181. return QColor(0xe0,0xc0,0xe0);
  182. if (style == Continuation)
  183. return QColor(0xf0,0xe0,0x80);
  184. return QsciLexer::defaultPaper(style);
  185. }
  186. // Refresh all properties.
  187. void QsciLexerFortran77::refreshProperties()
  188. {
  189. setCompactProp();
  190. }
  191. // Read properties from the settings.
  192. bool QsciLexerFortran77::readProperties(QSettings &qs, const QString &prefix)
  193. {
  194. int rc = true;
  195. fold_compact = qs.value(prefix + "foldcompact", true).toBool();
  196. return rc;
  197. }
  198. // Write properties to the settings.
  199. bool QsciLexerFortran77::writeProperties(QSettings &qs,const QString &prefix) const
  200. {
  201. int rc = true;
  202. qs.setValue(prefix + "foldcompact", fold_compact);
  203. return rc;
  204. }
  205. // Return true if folds are compact.
  206. bool QsciLexerFortran77::foldCompact() const
  207. {
  208. return fold_compact;
  209. }
  210. // Set if folds are compact
  211. void QsciLexerFortran77::setFoldCompact(bool fold)
  212. {
  213. fold_compact = fold;
  214. setCompactProp();
  215. }
  216. // Set the "fold.compact" property.
  217. void QsciLexerFortran77::setCompactProp()
  218. {
  219. emit propertyChanged("fold.compact",(fold_compact ? "1" : "0"));
  220. }