LexFortran.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. // Scintilla source code edit control
  2. /** @file LexFortran.cxx
  3. ** Lexer for Fortran.
  4. ** Written by Chuan-jian Shen, Last changed Sep. 2003
  5. **/
  6. // Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
  7. // The License.txt file describes the conditions under which this software may be distributed.
  8. /***************************************/
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <stdio.h>
  12. #include <stdarg.h>
  13. #include <assert.h>
  14. #include <ctype.h>
  15. /***************************************/
  16. #include "ILexer.h"
  17. #include "Scintilla.h"
  18. #include "SciLexer.h"
  19. #include "WordList.h"
  20. #include "LexAccessor.h"
  21. #include "Accessor.h"
  22. #include "StyleContext.h"
  23. #include "CharacterSet.h"
  24. #include "LexerModule.h"
  25. /***************************************/
  26. #ifdef SCI_NAMESPACE
  27. using namespace Scintilla;
  28. #endif
  29. /***********************************************/
  30. static inline bool IsAWordChar(const int ch) {
  31. return (ch < 0x80) && (isalnum(ch) || ch == '_' || ch == '%');
  32. }
  33. /**********************************************/
  34. static inline bool IsAWordStart(const int ch) {
  35. return (ch < 0x80) && (isalnum(ch));
  36. }
  37. /***************************************/
  38. static inline bool IsABlank(unsigned int ch) {
  39. return (ch == ' ') || (ch == 0x09) || (ch == 0x0b) ;
  40. }
  41. /***************************************/
  42. static inline bool IsALineEnd(char ch) {
  43. return ((ch == '\n') || (ch == '\r')) ;
  44. }
  45. /***************************************/
  46. static Sci_PositionU GetContinuedPos(Sci_PositionU pos, Accessor &styler) {
  47. while (!IsALineEnd(styler.SafeGetCharAt(pos++))) continue;
  48. if (styler.SafeGetCharAt(pos) == '\n') pos++;
  49. while (IsABlank(styler.SafeGetCharAt(pos++))) continue;
  50. char chCur = styler.SafeGetCharAt(pos);
  51. if (chCur == '&') {
  52. while (IsABlank(styler.SafeGetCharAt(++pos))) continue;
  53. return pos;
  54. } else {
  55. return pos;
  56. }
  57. }
  58. /***************************************/
  59. static void ColouriseFortranDoc(Sci_PositionU startPos, Sci_Position length, int initStyle,
  60. WordList *keywordlists[], Accessor &styler, bool isFixFormat) {
  61. WordList &keywords = *keywordlists[0];
  62. WordList &keywords2 = *keywordlists[1];
  63. WordList &keywords3 = *keywordlists[2];
  64. /***************************************/
  65. Sci_Position posLineStart = 0;
  66. int numNonBlank = 0, prevState = 0;
  67. Sci_Position endPos = startPos + length;
  68. /***************************************/
  69. // backtrack to the nearest keyword
  70. while ((startPos > 1) && (styler.StyleAt(startPos) != SCE_F_WORD)) {
  71. startPos--;
  72. }
  73. startPos = styler.LineStart(styler.GetLine(startPos));
  74. initStyle = styler.StyleAt(startPos - 1);
  75. StyleContext sc(startPos, endPos-startPos, initStyle, styler);
  76. /***************************************/
  77. for (; sc.More(); sc.Forward()) {
  78. // remember the start position of the line
  79. if (sc.atLineStart) {
  80. posLineStart = sc.currentPos;
  81. numNonBlank = 0;
  82. sc.SetState(SCE_F_DEFAULT);
  83. }
  84. if (!IsASpaceOrTab(sc.ch)) numNonBlank ++;
  85. /***********************************************/
  86. // Handle the fix format generically
  87. Sci_Position toLineStart = sc.currentPos - posLineStart;
  88. if (isFixFormat && (toLineStart < 6 || toLineStart >= 72)) {
  89. if ((toLineStart == 0 && (tolower(sc.ch) == 'c' || sc.ch == '*')) || sc.ch == '!') {
  90. if (sc.MatchIgnoreCase("cdec$") || sc.MatchIgnoreCase("*dec$") || sc.MatchIgnoreCase("!dec$") ||
  91. sc.MatchIgnoreCase("cdir$") || sc.MatchIgnoreCase("*dir$") || sc.MatchIgnoreCase("!dir$") ||
  92. sc.MatchIgnoreCase("cms$") || sc.MatchIgnoreCase("*ms$") || sc.MatchIgnoreCase("!ms$") ||
  93. sc.chNext == '$') {
  94. sc.SetState(SCE_F_PREPROCESSOR);
  95. } else {
  96. sc.SetState(SCE_F_COMMENT);
  97. }
  98. while (!sc.atLineEnd && sc.More()) sc.Forward(); // Until line end
  99. } else if (toLineStart >= 72) {
  100. sc.SetState(SCE_F_COMMENT);
  101. while (!sc.atLineEnd && sc.More()) sc.Forward(); // Until line end
  102. } else if (toLineStart < 5) {
  103. if (IsADigit(sc.ch))
  104. sc.SetState(SCE_F_LABEL);
  105. else
  106. sc.SetState(SCE_F_DEFAULT);
  107. } else if (toLineStart == 5) {
  108. //if (!IsASpace(sc.ch) && sc.ch != '0') {
  109. if (sc.ch != '\r' && sc.ch != '\n') {
  110. sc.SetState(SCE_F_CONTINUATION);
  111. if (!IsASpace(sc.ch) && sc.ch != '0')
  112. sc.ForwardSetState(prevState);
  113. } else
  114. sc.SetState(SCE_F_DEFAULT);
  115. }
  116. continue;
  117. }
  118. /***************************************/
  119. // Hanndle preprocessor directives
  120. if (sc.ch == '#' && numNonBlank == 1)
  121. {
  122. sc.SetState(SCE_F_PREPROCESSOR);
  123. while (!sc.atLineEnd && sc.More())
  124. sc.Forward(); // Until line end
  125. }
  126. /***************************************/
  127. // Handle line continuation generically.
  128. if (!isFixFormat && sc.ch == '&' && sc.state != SCE_F_COMMENT) {
  129. char chTemp = ' ';
  130. Sci_Position j = 1;
  131. while (IsABlank(chTemp) && j<132) {
  132. chTemp = static_cast<char>(sc.GetRelative(j));
  133. j++;
  134. }
  135. if (chTemp == '!') {
  136. sc.SetState(SCE_F_CONTINUATION);
  137. if (sc.chNext == '!') sc.ForwardSetState(SCE_F_COMMENT);
  138. } else if (chTemp == '\r' || chTemp == '\n') {
  139. int currentState = sc.state;
  140. sc.SetState(SCE_F_CONTINUATION);
  141. sc.ForwardSetState(SCE_F_DEFAULT);
  142. while (IsASpace(sc.ch) && sc.More()) sc.Forward();
  143. if (sc.ch == '&') {
  144. sc.SetState(SCE_F_CONTINUATION);
  145. sc.Forward();
  146. }
  147. sc.SetState(currentState);
  148. }
  149. }
  150. /***************************************/
  151. // Determine if the current state should terminate.
  152. if (sc.state == SCE_F_OPERATOR) {
  153. sc.SetState(SCE_F_DEFAULT);
  154. } else if (sc.state == SCE_F_NUMBER) {
  155. if (!(IsAWordChar(sc.ch) || sc.ch=='\'' || sc.ch=='\"' || sc.ch=='.')) {
  156. sc.SetState(SCE_F_DEFAULT);
  157. }
  158. } else if (sc.state == SCE_F_IDENTIFIER) {
  159. if (!IsAWordChar(sc.ch) || (sc.ch == '%')) {
  160. char s[100];
  161. sc.GetCurrentLowered(s, sizeof(s));
  162. if (keywords.InList(s)) {
  163. sc.ChangeState(SCE_F_WORD);
  164. } else if (keywords2.InList(s)) {
  165. sc.ChangeState(SCE_F_WORD2);
  166. } else if (keywords3.InList(s)) {
  167. sc.ChangeState(SCE_F_WORD3);
  168. }
  169. sc.SetState(SCE_F_DEFAULT);
  170. }
  171. } else if (sc.state == SCE_F_COMMENT || sc.state == SCE_F_PREPROCESSOR) {
  172. if (sc.ch == '\r' || sc.ch == '\n') {
  173. sc.SetState(SCE_F_DEFAULT);
  174. }
  175. } else if (sc.state == SCE_F_STRING1) {
  176. prevState = sc.state;
  177. if (sc.ch == '\'') {
  178. if (sc.chNext == '\'') {
  179. sc.Forward();
  180. } else {
  181. sc.ForwardSetState(SCE_F_DEFAULT);
  182. prevState = SCE_F_DEFAULT;
  183. }
  184. } else if (sc.atLineEnd) {
  185. sc.ChangeState(SCE_F_STRINGEOL);
  186. sc.ForwardSetState(SCE_F_DEFAULT);
  187. }
  188. } else if (sc.state == SCE_F_STRING2) {
  189. prevState = sc.state;
  190. if (sc.atLineEnd) {
  191. sc.ChangeState(SCE_F_STRINGEOL);
  192. sc.ForwardSetState(SCE_F_DEFAULT);
  193. } else if (sc.ch == '\"') {
  194. if (sc.chNext == '\"') {
  195. sc.Forward();
  196. } else {
  197. sc.ForwardSetState(SCE_F_DEFAULT);
  198. prevState = SCE_F_DEFAULT;
  199. }
  200. }
  201. } else if (sc.state == SCE_F_OPERATOR2) {
  202. if (sc.ch == '.') {
  203. sc.ForwardSetState(SCE_F_DEFAULT);
  204. }
  205. } else if (sc.state == SCE_F_CONTINUATION) {
  206. sc.SetState(SCE_F_DEFAULT);
  207. } else if (sc.state == SCE_F_LABEL) {
  208. if (!IsADigit(sc.ch)) {
  209. sc.SetState(SCE_F_DEFAULT);
  210. } else {
  211. if (isFixFormat && sc.currentPos-posLineStart > 4)
  212. sc.SetState(SCE_F_DEFAULT);
  213. else if (numNonBlank > 5)
  214. sc.SetState(SCE_F_DEFAULT);
  215. }
  216. }
  217. /***************************************/
  218. // Determine if a new state should be entered.
  219. if (sc.state == SCE_F_DEFAULT) {
  220. if (sc.ch == '!') {
  221. if (sc.MatchIgnoreCase("!dec$") || sc.MatchIgnoreCase("!dir$") ||
  222. sc.MatchIgnoreCase("!ms$") || sc.chNext == '$') {
  223. sc.SetState(SCE_F_PREPROCESSOR);
  224. } else {
  225. sc.SetState(SCE_F_COMMENT);
  226. }
  227. } else if ((!isFixFormat) && IsADigit(sc.ch) && numNonBlank == 1) {
  228. sc.SetState(SCE_F_LABEL);
  229. } else if (IsADigit(sc.ch) || (sc.ch == '.' && IsADigit(sc.chNext))) {
  230. sc.SetState(SCE_F_NUMBER);
  231. } else if ((tolower(sc.ch) == 'b' || tolower(sc.ch) == 'o' ||
  232. tolower(sc.ch) == 'z') && (sc.chNext == '\"' || sc.chNext == '\'')) {
  233. sc.SetState(SCE_F_NUMBER);
  234. sc.Forward();
  235. } else if (sc.ch == '.' && isalpha(sc.chNext)) {
  236. sc.SetState(SCE_F_OPERATOR2);
  237. } else if (IsAWordStart(sc.ch)) {
  238. sc.SetState(SCE_F_IDENTIFIER);
  239. } else if (sc.ch == '\"') {
  240. sc.SetState(SCE_F_STRING2);
  241. } else if (sc.ch == '\'') {
  242. sc.SetState(SCE_F_STRING1);
  243. } else if (isoperator(static_cast<char>(sc.ch))) {
  244. sc.SetState(SCE_F_OPERATOR);
  245. }
  246. }
  247. }
  248. sc.Complete();
  249. }
  250. /***************************************/
  251. // To determine the folding level depending on keywords
  252. static int classifyFoldPointFortran(const char* s, const char* prevWord, const char chNextNonBlank) {
  253. int lev = 0;
  254. if ((strcmp(prevWord, "module") == 0 && strcmp(s, "subroutine") == 0)
  255. || (strcmp(prevWord, "module") == 0 && strcmp(s, "function") == 0)) {
  256. lev = 0;
  257. } else if (strcmp(s, "associate") == 0 || strcmp(s, "block") == 0
  258. || strcmp(s, "blockdata") == 0 || strcmp(s, "select") == 0
  259. || strcmp(s, "selecttype") == 0 || strcmp(s, "selectcase") == 0
  260. || strcmp(s, "do") == 0 || strcmp(s, "enum") ==0
  261. || strcmp(s, "function") == 0 || strcmp(s, "interface") == 0
  262. || strcmp(s, "module") == 0 || strcmp(s, "program") == 0
  263. || strcmp(s, "subroutine") == 0 || strcmp(s, "then") == 0
  264. || (strcmp(s, "type") == 0 && chNextNonBlank != '(')
  265. || strcmp(s, "critical") == 0 || strcmp(s, "submodule") == 0){
  266. if (strcmp(prevWord, "end") == 0)
  267. lev = 0;
  268. else
  269. lev = 1;
  270. } else if ((strcmp(s, "end") == 0 && chNextNonBlank != '=')
  271. || strcmp(s, "endassociate") == 0 || strcmp(s, "endblock") == 0
  272. || strcmp(s, "endblockdata") == 0 || strcmp(s, "endselect") == 0
  273. || strcmp(s, "enddo") == 0 || strcmp(s, "endenum") ==0
  274. || strcmp(s, "endif") == 0 || strcmp(s, "endforall") == 0
  275. || strcmp(s, "endfunction") == 0 || strcmp(s, "endinterface") == 0
  276. || strcmp(s, "endmodule") == 0 || strcmp(s, "endprogram") == 0
  277. || strcmp(s, "endsubroutine") == 0 || strcmp(s, "endtype") == 0
  278. || strcmp(s, "endwhere") == 0 || strcmp(s, "endcritical") == 0
  279. || (strcmp(prevWord, "module") == 0 && strcmp(s, "procedure") == 0) // Take care of the "module procedure" statement
  280. || strcmp(s, "endsubmodule") == 0) {
  281. lev = -1;
  282. } else if (strcmp(prevWord, "end") == 0 && strcmp(s, "if") == 0){ // end if
  283. lev = 0;
  284. } else if (strcmp(prevWord, "type") == 0 && strcmp(s, "is") == 0){ // type is
  285. lev = -1;
  286. } else if ((strcmp(prevWord, "end") == 0 && strcmp(s, "procedure") == 0)
  287. || strcmp(s, "endprocedure") == 0) {
  288. lev = 1; // level back to 0, because no folding support for "module procedure" in submodule
  289. }
  290. return lev;
  291. }
  292. /***************************************/
  293. // Folding the code
  294. static void FoldFortranDoc(Sci_PositionU startPos, Sci_Position length, int initStyle,
  295. Accessor &styler, bool isFixFormat) {
  296. //
  297. // bool foldComment = styler.GetPropertyInt("fold.comment") != 0;
  298. // Do not know how to fold the comment at the moment.
  299. //
  300. bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
  301. Sci_PositionU endPos = startPos + length;
  302. int visibleChars = 0;
  303. Sci_Position lineCurrent = styler.GetLine(startPos);
  304. int levelCurrent;
  305. bool isPrevLine;
  306. if (lineCurrent > 0) {
  307. lineCurrent--;
  308. startPos = styler.LineStart(lineCurrent);
  309. levelCurrent = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK;
  310. isPrevLine = true;
  311. } else {
  312. levelCurrent = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK;
  313. isPrevLine = false;
  314. }
  315. char chNext = styler[startPos];
  316. int styleNext = styler.StyleAt(startPos);
  317. int style = initStyle;
  318. int levelDeltaNext = 0;
  319. /***************************************/
  320. Sci_Position lastStart = 0;
  321. char prevWord[32] = "";
  322. /***************************************/
  323. for (Sci_PositionU i = startPos; i < endPos; i++) {
  324. char ch = chNext;
  325. chNext = styler.SafeGetCharAt(i + 1);
  326. char chNextNonBlank = chNext;
  327. bool nextEOL = false;
  328. if (IsALineEnd(chNextNonBlank)) {
  329. nextEOL = true;
  330. }
  331. Sci_PositionU j=i+1;
  332. while(IsABlank(chNextNonBlank) && j<endPos) {
  333. j ++ ;
  334. chNextNonBlank = styler.SafeGetCharAt(j);
  335. if (IsALineEnd(chNextNonBlank)) {
  336. nextEOL = true;
  337. }
  338. }
  339. if (!nextEOL && j == endPos) {
  340. nextEOL = true;
  341. }
  342. int stylePrev = style;
  343. style = styleNext;
  344. styleNext = styler.StyleAt(i + 1);
  345. bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n');
  346. //
  347. if (((isFixFormat && stylePrev == SCE_F_CONTINUATION) || stylePrev == SCE_F_DEFAULT
  348. || stylePrev == SCE_F_OPERATOR) && (style == SCE_F_WORD || style == SCE_F_LABEL)) {
  349. // Store last word and label start point.
  350. lastStart = i;
  351. }
  352. /***************************************/
  353. if (style == SCE_F_WORD) {
  354. if(iswordchar(ch) && !iswordchar(chNext)) {
  355. char s[32];
  356. Sci_PositionU k;
  357. for(k=0; (k<31 ) && (k<i-lastStart+1 ); k++) {
  358. s[k] = static_cast<char>(tolower(styler[lastStart+k]));
  359. }
  360. s[k] = '\0';
  361. // Handle the forall and where statement and structure.
  362. if (strcmp(s, "forall") == 0 || (strcmp(s, "where") == 0 && strcmp(prevWord, "else") != 0)) {
  363. if (strcmp(prevWord, "end") != 0) {
  364. j = i + 1;
  365. char chBrace = '(', chSeek = ')', ch1 = styler.SafeGetCharAt(j);
  366. // Find the position of the first (
  367. while (ch1 != chBrace && j<endPos) {
  368. j++;
  369. ch1 = styler.SafeGetCharAt(j);
  370. }
  371. char styBrace = styler.StyleAt(j);
  372. int depth = 1;
  373. char chAtPos;
  374. char styAtPos;
  375. while (j<endPos) {
  376. j++;
  377. chAtPos = styler.SafeGetCharAt(j);
  378. styAtPos = styler.StyleAt(j);
  379. if (styAtPos == styBrace) {
  380. if (chAtPos == chBrace) depth++;
  381. if (chAtPos == chSeek) depth--;
  382. if (depth == 0) break;
  383. }
  384. }
  385. Sci_Position tmpLineCurrent = lineCurrent;
  386. while (j<endPos) {
  387. j++;
  388. chAtPos = styler.SafeGetCharAt(j);
  389. styAtPos = styler.StyleAt(j);
  390. if (!IsALineEnd(chAtPos) && (styAtPos == SCE_F_COMMENT || IsABlank(chAtPos))) continue;
  391. if (isFixFormat) {
  392. if (!IsALineEnd(chAtPos)) {
  393. break;
  394. } else {
  395. if (tmpLineCurrent < styler.GetLine(styler.Length()-1)) {
  396. tmpLineCurrent++;
  397. j = styler.LineStart(tmpLineCurrent);
  398. if (styler.StyleAt(j+5) == SCE_F_CONTINUATION
  399. && !IsABlank(styler.SafeGetCharAt(j+5)) && styler.SafeGetCharAt(j+5) != '0') {
  400. j += 5;
  401. continue;
  402. } else {
  403. levelDeltaNext++;
  404. break;
  405. }
  406. }
  407. }
  408. } else {
  409. if (chAtPos == '&' && styler.StyleAt(j) == SCE_F_CONTINUATION) {
  410. j = GetContinuedPos(j+1, styler);
  411. continue;
  412. } else if (IsALineEnd(chAtPos)) {
  413. levelDeltaNext++;
  414. break;
  415. } else {
  416. break;
  417. }
  418. }
  419. }
  420. }
  421. } else {
  422. int wordLevelDelta = classifyFoldPointFortran(s, prevWord, chNextNonBlank);
  423. levelDeltaNext += wordLevelDelta;
  424. if (((strcmp(s, "else") == 0) && (nextEOL || chNextNonBlank == '!')) ||
  425. (strcmp(prevWord, "else") == 0 && strcmp(s, "where") == 0) || strcmp(s, "elsewhere") == 0) {
  426. if (!isPrevLine) {
  427. levelCurrent--;
  428. }
  429. levelDeltaNext++;
  430. } else if ((strcmp(prevWord, "else") == 0 && strcmp(s, "if") == 0) || strcmp(s, "elseif") == 0) {
  431. if (!isPrevLine) {
  432. levelCurrent--;
  433. }
  434. } else if ((strcmp(prevWord, "select") == 0 && strcmp(s, "case") == 0) || strcmp(s, "selectcase") == 0 ||
  435. (strcmp(prevWord, "select") == 0 && strcmp(s, "type") == 0) || strcmp(s, "selecttype") == 0) {
  436. levelDeltaNext += 2;
  437. } else if ((strcmp(s, "case") == 0 && chNextNonBlank == '(') || (strcmp(prevWord, "case") == 0 && strcmp(s, "default") == 0) ||
  438. (strcmp(prevWord, "type") == 0 && strcmp(s, "is") == 0) ||
  439. (strcmp(prevWord, "class") == 0 && strcmp(s, "is") == 0) ||
  440. (strcmp(prevWord, "class") == 0 && strcmp(s, "default") == 0) ) {
  441. if (!isPrevLine) {
  442. levelCurrent--;
  443. }
  444. levelDeltaNext++;
  445. } else if ((strcmp(prevWord, "end") == 0 && strcmp(s, "select") == 0) || strcmp(s, "endselect") == 0) {
  446. levelDeltaNext -= 2;
  447. }
  448. // There are multiple forms of "do" loop. The older form with a label "do 100 i=1,10" would require matching
  449. // labels to ensure the folding level does not decrease too far when labels are used for other purposes.
  450. // Since this is difficult, do-label constructs are not folded.
  451. if (strcmp(s, "do") == 0 && IsADigit(chNextNonBlank)) {
  452. // Remove delta for do-label
  453. levelDeltaNext -= wordLevelDelta;
  454. }
  455. }
  456. strcpy(prevWord, s);
  457. }
  458. }
  459. if (atEOL) {
  460. int lev = levelCurrent;
  461. if (visibleChars == 0 && foldCompact)
  462. lev |= SC_FOLDLEVELWHITEFLAG;
  463. if ((levelDeltaNext > 0) && (visibleChars > 0))
  464. lev |= SC_FOLDLEVELHEADERFLAG;
  465. if (lev != styler.LevelAt(lineCurrent))
  466. styler.SetLevel(lineCurrent, lev);
  467. lineCurrent++;
  468. levelCurrent += levelDeltaNext;
  469. levelDeltaNext = 0;
  470. visibleChars = 0;
  471. strcpy(prevWord, "");
  472. isPrevLine = false;
  473. }
  474. /***************************************/
  475. if (!isspacechar(ch)) visibleChars++;
  476. }
  477. /***************************************/
  478. }
  479. /***************************************/
  480. static const char * const FortranWordLists[] = {
  481. "Primary keywords and identifiers",
  482. "Intrinsic functions",
  483. "Extended and user defined functions",
  484. 0,
  485. };
  486. /***************************************/
  487. static void ColouriseFortranDocFreeFormat(Sci_PositionU startPos, Sci_Position length, int initStyle, WordList *keywordlists[],
  488. Accessor &styler) {
  489. ColouriseFortranDoc(startPos, length, initStyle, keywordlists, styler, false);
  490. }
  491. /***************************************/
  492. static void ColouriseFortranDocFixFormat(Sci_PositionU startPos, Sci_Position length, int initStyle, WordList *keywordlists[],
  493. Accessor &styler) {
  494. ColouriseFortranDoc(startPos, length, initStyle, keywordlists, styler, true);
  495. }
  496. /***************************************/
  497. static void FoldFortranDocFreeFormat(Sci_PositionU startPos, Sci_Position length, int initStyle,
  498. WordList *[], Accessor &styler) {
  499. FoldFortranDoc(startPos, length, initStyle,styler, false);
  500. }
  501. /***************************************/
  502. static void FoldFortranDocFixFormat(Sci_PositionU startPos, Sci_Position length, int initStyle,
  503. WordList *[], Accessor &styler) {
  504. FoldFortranDoc(startPos, length, initStyle,styler, true);
  505. }
  506. /***************************************/
  507. LexerModule lmFortran(SCLEX_FORTRAN, ColouriseFortranDocFreeFormat, "fortran", FoldFortranDocFreeFormat, FortranWordLists);
  508. LexerModule lmF77(SCLEX_F77, ColouriseFortranDocFixFormat, "f77", FoldFortranDocFixFormat, FortranWordLists);