PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/cssed-0.4.0/scintilla/src/LexBash.cxx

#
C++ | 661 lines | 607 code | 28 blank | 26 comment | 166 complexity | 71b792ab0cd2c8e5ea08bc6e121d2b57 MD5 | raw file
Possible License(s): GPL-2.0
  1. // Scintilla source code edit control
  2. /** @file LexBash.cxx
  3. ** Lexer for Bash.
  4. **/
  5. // Copyright 2004-2005 by Neil Hodgson <neilh@scintilla.org>
  6. // Adapted from LexPerl by Kein-Hong Man <mkh@pl.jaring.my> 2004
  7. // The License.txt file describes the conditions under which this software may be distributed.
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <ctype.h>
  11. #include <stdio.h>
  12. #include <stdarg.h>
  13. #include "Platform.h"
  14. #include "PropSet.h"
  15. #include "Accessor.h"
  16. #include "KeyWords.h"
  17. #include "Scintilla.h"
  18. #include "SciLexer.h"
  19. #define BASH_BASE_ERROR 65
  20. #define BASH_BASE_DECIMAL 66
  21. #define BASH_BASE_HEX 67
  22. #define BASH_BASE_OCTAL 68
  23. #define BASH_BASE_OCTAL_ERROR 69
  24. #define HERE_DELIM_MAX 256
  25. static inline int translateBashDigit(char ch) {
  26. if (ch >= '0' && ch <= '9') {
  27. return ch - '0';
  28. } else if (ch >= 'a' && ch <= 'z') {
  29. return ch - 'a' + 10;
  30. } else if (ch >= 'A' && ch <= 'Z') {
  31. return ch - 'A' + 36;
  32. } else if (ch == '@') {
  33. return 62;
  34. } else if (ch == '_') {
  35. return 63;
  36. }
  37. return BASH_BASE_ERROR;
  38. }
  39. static inline bool isEOLChar(char ch) {
  40. return (ch == '\r') || (ch == '\n');
  41. }
  42. static bool isSingleCharOp(char ch) {
  43. char strCharSet[2];
  44. strCharSet[0] = ch;
  45. strCharSet[1] = '\0';
  46. return (NULL != strstr("rwxoRWXOezsfdlpSbctugkTBMACahGLNn", strCharSet));
  47. }
  48. static inline bool isBashOperator(char ch) {
  49. if (ch == '^' || ch == '&' || ch == '\\' || ch == '%' ||
  50. ch == '(' || ch == ')' || ch == '-' || ch == '+' ||
  51. ch == '=' || ch == '|' || ch == '{' || ch == '}' ||
  52. ch == '[' || ch == ']' || ch == ':' || ch == ';' ||
  53. ch == '>' || ch == ',' || ch == '/' || ch == '<' ||
  54. ch == '?' || ch == '!' || ch == '.' || ch == '~' ||
  55. ch == '@')
  56. return true;
  57. return false;
  58. }
  59. static int classifyWordBash(unsigned int start, unsigned int end, WordList &keywords, Accessor &styler) {
  60. char s[100];
  61. for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
  62. s[i] = styler[start + i];
  63. s[i + 1] = '\0';
  64. }
  65. char chAttr = SCE_SH_IDENTIFIER;
  66. if (keywords.InList(s))
  67. chAttr = SCE_SH_WORD;
  68. styler.ColourTo(end, chAttr);
  69. return chAttr;
  70. }
  71. static inline int getBashNumberBase(unsigned int start, unsigned int end, Accessor &styler) {
  72. int base = 0;
  73. for (unsigned int i = 0; i < end - start + 1 && i < 10; i++) {
  74. base = base * 10 + (styler[start + i] - '0');
  75. }
  76. if (base > 64 || (end - start) > 1) {
  77. return BASH_BASE_ERROR;
  78. }
  79. return base;
  80. }
  81. static inline bool isEndVar(char ch) {
  82. return !isalnum(ch) && ch != '$' && ch != '_';
  83. }
  84. static inline bool isNonQuote(char ch) {
  85. return isalnum(ch) || ch == '_';
  86. }
  87. static bool isMatch(Accessor &styler, int lengthDoc, int pos, const char *val) {
  88. if ((pos + static_cast<int>(strlen(val))) >= lengthDoc) {
  89. return false;
  90. }
  91. while (*val) {
  92. if (*val != styler[pos++]) {
  93. return false;
  94. }
  95. val++;
  96. }
  97. return true;
  98. }
  99. static char opposite(char ch) {
  100. if (ch == '(')
  101. return ')';
  102. if (ch == '[')
  103. return ']';
  104. if (ch == '{')
  105. return '}';
  106. if (ch == '<')
  107. return '>';
  108. return ch;
  109. }
  110. static void ColouriseBashDoc(unsigned int startPos, int length, int initStyle,
  111. WordList *keywordlists[], Accessor &styler) {
  112. // Lexer for bash often has to backtrack to start of current style to determine
  113. // which characters are being used as quotes, how deeply nested is the
  114. // start position and what the termination string is for here documents
  115. WordList &keywords = *keywordlists[0];
  116. class HereDocCls {
  117. public:
  118. int State; // 0: '<<' encountered
  119. // 1: collect the delimiter
  120. // 2: here doc text (lines after the delimiter)
  121. char Quote; // the char after '<<'
  122. bool Quoted; // true if Quote in ('\'','"','`')
  123. bool Indent; // indented delimiter (for <<-)
  124. int DelimiterLength; // strlen(Delimiter)
  125. char *Delimiter; // the Delimiter, 256: sizeof PL_tokenbuf
  126. HereDocCls() {
  127. State = 0;
  128. Quote = 0;
  129. Quoted = false;
  130. Indent = 0;
  131. DelimiterLength = 0;
  132. Delimiter = new char[HERE_DELIM_MAX];
  133. Delimiter[0] = '\0';
  134. }
  135. ~HereDocCls() {
  136. delete []Delimiter;
  137. }
  138. };
  139. HereDocCls HereDoc;
  140. class QuoteCls {
  141. public:
  142. int Rep;
  143. int Count;
  144. char Up;
  145. char Down;
  146. QuoteCls() {
  147. this->New(1);
  148. }
  149. void New(int r) {
  150. Rep = r;
  151. Count = 0;
  152. Up = '\0';
  153. Down = '\0';
  154. }
  155. void Open(char u) {
  156. Count++;
  157. Up = u;
  158. Down = opposite(Up);
  159. }
  160. };
  161. QuoteCls Quote;
  162. int state = initStyle;
  163. int numBase = 0;
  164. unsigned int lengthDoc = startPos + length;
  165. // If in a long distance lexical state, seek to the beginning to find quote characters
  166. // Bash strings can be multi-line with embedded newlines, so backtrack.
  167. // Bash numbers have additional state during lexing, so backtrack too.
  168. if (state == SCE_SH_HERE_Q) {
  169. while ((startPos > 1) && (styler.StyleAt(startPos) != SCE_SH_HERE_DELIM)) {
  170. startPos--;
  171. }
  172. startPos = styler.LineStart(styler.GetLine(startPos));
  173. state = styler.StyleAt(startPos - 1);
  174. }
  175. if (state == SCE_SH_STRING
  176. || state == SCE_SH_BACKTICKS
  177. || state == SCE_SH_CHARACTER
  178. || state == SCE_SH_NUMBER
  179. || state == SCE_SH_IDENTIFIER
  180. || state == SCE_SH_COMMENTLINE
  181. ) {
  182. while ((startPos > 1) && (styler.StyleAt(startPos - 1) == state)) {
  183. startPos--;
  184. }
  185. state = SCE_SH_DEFAULT;
  186. }
  187. styler.StartAt(startPos);
  188. char chPrev = styler.SafeGetCharAt(startPos - 1);
  189. if (startPos == 0)
  190. chPrev = '\n';
  191. char chNext = styler[startPos];
  192. styler.StartSegment(startPos);
  193. for (unsigned int i = startPos; i < lengthDoc; i++) {
  194. char ch = chNext;
  195. // if the current character is not consumed due to the completion of an
  196. // earlier style, lexing can be restarted via a simple goto
  197. restartLexer:
  198. chNext = styler.SafeGetCharAt(i + 1);
  199. char chNext2 = styler.SafeGetCharAt(i + 2);
  200. if (styler.IsLeadByte(ch)) {
  201. chNext = styler.SafeGetCharAt(i + 2);
  202. chPrev = ' ';
  203. i += 1;
  204. continue;
  205. }
  206. if ((chPrev == '\r' && ch == '\n')) { // skip on DOS/Windows
  207. styler.ColourTo(i, state);
  208. chPrev = ch;
  209. continue;
  210. }
  211. if (HereDoc.State == 1 && isEOLChar(ch)) {
  212. // Begin of here-doc (the line after the here-doc delimiter):
  213. // Lexically, the here-doc starts from the next line after the >>, but the
  214. // first line of here-doc seem to follow the style of the last EOL sequence
  215. HereDoc.State = 2;
  216. if (HereDoc.Quoted) {
  217. if (state == SCE_SH_HERE_DELIM) {
  218. // Missing quote at end of string! We are stricter than bash.
  219. // Colour here-doc anyway while marking this bit as an error.
  220. state = SCE_SH_ERROR;
  221. }
  222. styler.ColourTo(i - 1, state);
  223. // HereDoc.Quote always == '\''
  224. state = SCE_SH_HERE_Q;
  225. } else {
  226. styler.ColourTo(i - 1, state);
  227. // always switch
  228. state = SCE_SH_HERE_Q;
  229. }
  230. }
  231. if (state == SCE_SH_DEFAULT) {
  232. if (ch == '\\') { // escaped character
  233. i++;
  234. ch = chNext;
  235. chNext = chNext2;
  236. styler.ColourTo(i, SCE_SH_IDENTIFIER);
  237. } else if (isdigit(ch)) {
  238. state = SCE_SH_NUMBER;
  239. numBase = BASH_BASE_DECIMAL;
  240. if (ch == '0') { // hex,octal
  241. if (chNext == 'x' || chNext == 'X') {
  242. numBase = BASH_BASE_HEX;
  243. i++;
  244. ch = chNext;
  245. chNext = chNext2;
  246. } else if (isdigit(chNext)) {
  247. numBase = BASH_BASE_OCTAL;
  248. }
  249. }
  250. } else if (iswordstart(ch)) {
  251. state = SCE_SH_WORD;
  252. if (!iswordchar(chNext) && chNext != '+' && chNext != '-') {
  253. // We need that if length of word == 1!
  254. // This test is copied from the SCE_SH_WORD handler.
  255. classifyWordBash(styler.GetStartSegment(), i, keywords, styler);
  256. state = SCE_SH_DEFAULT;
  257. }
  258. } else if (ch == '#') {
  259. state = SCE_SH_COMMENTLINE;
  260. } else if (ch == '\"') {
  261. state = SCE_SH_STRING;
  262. Quote.New(1);
  263. Quote.Open(ch);
  264. } else if (ch == '\'') {
  265. state = SCE_SH_CHARACTER;
  266. Quote.New(1);
  267. Quote.Open(ch);
  268. } else if (ch == '`') {
  269. state = SCE_SH_BACKTICKS;
  270. Quote.New(1);
  271. Quote.Open(ch);
  272. } else if (ch == '$') {
  273. if (chNext == '{') {
  274. state = SCE_SH_PARAM;
  275. goto startQuote;
  276. } else if (chNext == '\'') {
  277. state = SCE_SH_CHARACTER;
  278. goto startQuote;
  279. } else if (chNext == '"') {
  280. state = SCE_SH_STRING;
  281. goto startQuote;
  282. } else if (chNext == '(' && chNext2 == '(') {
  283. styler.ColourTo(i, SCE_SH_OPERATOR);
  284. state = SCE_SH_DEFAULT;
  285. goto skipChar;
  286. } else if (chNext == '(' || chNext == '`') {
  287. state = SCE_SH_BACKTICKS;
  288. startQuote:
  289. Quote.New(1);
  290. Quote.Open(chNext);
  291. goto skipChar;
  292. } else {
  293. state = SCE_SH_SCALAR;
  294. skipChar:
  295. i++;
  296. ch = chNext;
  297. chNext = chNext2;
  298. }
  299. } else if (ch == '*') {
  300. if (chNext == '*') { // exponentiation
  301. i++;
  302. ch = chNext;
  303. chNext = chNext2;
  304. }
  305. styler.ColourTo(i, SCE_SH_OPERATOR);
  306. } else if (ch == '<' && chNext == '<') {
  307. state = SCE_SH_HERE_DELIM;
  308. HereDoc.State = 0;
  309. HereDoc.Indent = false;
  310. } else if (ch == '-' // file test operators
  311. && isSingleCharOp(chNext)
  312. && !isalnum((chNext2 = styler.SafeGetCharAt(i+2)))) {
  313. styler.ColourTo(i + 1, SCE_SH_WORD);
  314. state = SCE_SH_DEFAULT;
  315. i++;
  316. ch = chNext;
  317. chNext = chNext2;
  318. } else if (isBashOperator(ch)) {
  319. styler.ColourTo(i, SCE_SH_OPERATOR);
  320. } else {
  321. // keep colouring defaults to make restart easier
  322. styler.ColourTo(i, SCE_SH_DEFAULT);
  323. }
  324. } else if (state == SCE_SH_NUMBER) {
  325. int digit = translateBashDigit(ch);
  326. if (numBase == BASH_BASE_DECIMAL) {
  327. if (ch == '#') {
  328. numBase = getBashNumberBase(styler.GetStartSegment(), i - 1, styler);
  329. if (numBase == BASH_BASE_ERROR) // take the rest as comment
  330. goto numAtEnd;
  331. } else if (!isdigit(ch))
  332. goto numAtEnd;
  333. } else if (numBase == BASH_BASE_HEX) {
  334. if ((digit < 16) || (digit >= 36 && digit <= 41)) {
  335. // hex digit 0-9a-fA-F
  336. } else
  337. goto numAtEnd;
  338. } else if (numBase == BASH_BASE_OCTAL ||
  339. numBase == BASH_BASE_OCTAL_ERROR) {
  340. if (digit > 7) {
  341. if (digit <= 9) {
  342. numBase = BASH_BASE_OCTAL_ERROR;
  343. } else
  344. goto numAtEnd;
  345. }
  346. } else if (numBase == BASH_BASE_ERROR) {
  347. if (digit > 9)
  348. goto numAtEnd;
  349. } else { // DD#DDDD number style handling
  350. if (digit != BASH_BASE_ERROR) {
  351. if (numBase <= 36) {
  352. // case-insensitive if base<=36
  353. if (digit >= 36) digit -= 26;
  354. }
  355. if (digit >= numBase) {
  356. if (digit <= 9) {
  357. numBase = BASH_BASE_ERROR;
  358. } else
  359. goto numAtEnd;
  360. }
  361. } else {
  362. numAtEnd:
  363. if (numBase == BASH_BASE_ERROR ||
  364. numBase == BASH_BASE_OCTAL_ERROR)
  365. state = SCE_SH_ERROR;
  366. styler.ColourTo(i - 1, state);
  367. state = SCE_SH_DEFAULT;
  368. goto restartLexer;
  369. }
  370. }
  371. } else if (state == SCE_SH_WORD) {
  372. if (!iswordchar(chNext) && chNext != '+' && chNext != '-') {
  373. // "." never used in Bash variable names
  374. // but used in file names
  375. classifyWordBash(styler.GetStartSegment(), i, keywords, styler);
  376. state = SCE_SH_DEFAULT;
  377. ch = ' ';
  378. }
  379. } else if (state == SCE_SH_IDENTIFIER) {
  380. if (!iswordchar(chNext) && chNext != '+' && chNext != '-') {
  381. styler.ColourTo(i, SCE_SH_IDENTIFIER);
  382. state = SCE_SH_DEFAULT;
  383. ch = ' ';
  384. }
  385. } else {
  386. if (state == SCE_SH_COMMENTLINE) {
  387. if (ch == '\\' && isEOLChar(chNext)) {
  388. // comment continuation
  389. if (chNext == '\r' && chNext2 == '\n') {
  390. i += 2;
  391. ch = styler.SafeGetCharAt(i);
  392. chNext = styler.SafeGetCharAt(i + 1);
  393. } else {
  394. i++;
  395. ch = chNext;
  396. chNext = chNext2;
  397. }
  398. } else if (isEOLChar(ch)) {
  399. styler.ColourTo(i - 1, state);
  400. state = SCE_SH_DEFAULT;
  401. goto restartLexer;
  402. } else if (isEOLChar(chNext)) {
  403. styler.ColourTo(i, state);
  404. state = SCE_SH_DEFAULT;
  405. }
  406. } else if (state == SCE_SH_HERE_DELIM) {
  407. //
  408. // From Bash info:
  409. // ---------------
  410. // Specifier format is: <<[-]WORD
  411. // Optional '-' is for removal of leading tabs from here-doc.
  412. // Whitespace acceptable after <<[-] operator
  413. //
  414. if (HereDoc.State == 0) { // '<<' encountered
  415. HereDoc.State = 1;
  416. HereDoc.Quote = chNext;
  417. HereDoc.Quoted = false;
  418. HereDoc.DelimiterLength = 0;
  419. HereDoc.Delimiter[HereDoc.DelimiterLength] = '\0';
  420. if (chNext == '\'') { // a quoted here-doc delimiter (' only)
  421. i++;
  422. ch = chNext;
  423. chNext = chNext2;
  424. HereDoc.Quoted = true;
  425. } else if (!HereDoc.Indent && chNext == '-') { // <<- indent case
  426. HereDoc.Indent = true;
  427. HereDoc.State = 0;
  428. } else if (isalpha(chNext) || chNext == '_' || chNext == '\\'
  429. || chNext == '-' || chNext == '+') {
  430. // an unquoted here-doc delimiter, no special handling
  431. } else if (chNext == '<') { // HERE string <<<
  432. i++;
  433. ch = chNext;
  434. chNext = chNext2;
  435. styler.ColourTo(i, SCE_SH_HERE_DELIM);
  436. state = SCE_SH_DEFAULT;
  437. HereDoc.State = 0;
  438. } else if (isspacechar(chNext)) {
  439. // eat whitespace
  440. HereDoc.State = 0;
  441. } else if (isdigit(chNext) || chNext == '=' || chNext == '$') {
  442. // left shift << or <<= operator cases
  443. styler.ColourTo(i, SCE_SH_OPERATOR);
  444. state = SCE_SH_DEFAULT;
  445. HereDoc.State = 0;
  446. } else {
  447. // symbols terminates; deprecated zero-length delimiter
  448. }
  449. } else if (HereDoc.State == 1) { // collect the delimiter
  450. if (HereDoc.Quoted) { // a quoted here-doc delimiter
  451. if (ch == HereDoc.Quote) { // closing quote => end of delimiter
  452. styler.ColourTo(i, state);
  453. state = SCE_SH_DEFAULT;
  454. } else {
  455. if (ch == '\\' && chNext == HereDoc.Quote) { // escaped quote
  456. i++;
  457. ch = chNext;
  458. chNext = chNext2;
  459. }
  460. HereDoc.Delimiter[HereDoc.DelimiterLength++] = ch;
  461. HereDoc.Delimiter[HereDoc.DelimiterLength] = '\0';
  462. }
  463. } else { // an unquoted here-doc delimiter
  464. if (isalnum(ch) || ch == '_' || ch == '-' || ch == '+') {
  465. HereDoc.Delimiter[HereDoc.DelimiterLength++] = ch;
  466. HereDoc.Delimiter[HereDoc.DelimiterLength] = '\0';
  467. } else if (ch == '\\') {
  468. // skip escape prefix
  469. } else {
  470. styler.ColourTo(i - 1, state);
  471. state = SCE_SH_DEFAULT;
  472. goto restartLexer;
  473. }
  474. }
  475. if (HereDoc.DelimiterLength >= HERE_DELIM_MAX - 1) {
  476. styler.ColourTo(i - 1, state);
  477. state = SCE_SH_ERROR;
  478. goto restartLexer;
  479. }
  480. }
  481. } else if (HereDoc.State == 2) {
  482. // state == SCE_SH_HERE_Q
  483. if (isMatch(styler, lengthDoc, i, HereDoc.Delimiter)) {
  484. if (!HereDoc.Indent && isEOLChar(chPrev)) {
  485. endHereDoc:
  486. // standard HERE delimiter
  487. i += HereDoc.DelimiterLength;
  488. chPrev = styler.SafeGetCharAt(i - 1);
  489. ch = styler.SafeGetCharAt(i);
  490. if (isEOLChar(ch)) {
  491. styler.ColourTo(i - 1, state);
  492. state = SCE_SH_DEFAULT;
  493. HereDoc.State = 0;
  494. goto restartLexer;
  495. }
  496. chNext = styler.SafeGetCharAt(i + 1);
  497. } else if (HereDoc.Indent) {
  498. // indented HERE delimiter
  499. unsigned int bk = (i > 0)? i - 1: 0;
  500. while (i > 0) {
  501. ch = styler.SafeGetCharAt(bk--);
  502. if (isEOLChar(ch)) {
  503. goto endHereDoc;
  504. } else if (!isspacechar(ch)) {
  505. break; // got leading non-whitespace
  506. }
  507. }
  508. }
  509. }
  510. } else if (state == SCE_SH_SCALAR) { // variable names
  511. if (isEndVar(ch)) {
  512. if ((state == SCE_SH_SCALAR)
  513. && i == (styler.GetStartSegment() + 1)) {
  514. // Special variable: $(, $_ etc.
  515. styler.ColourTo(i, state);
  516. state = SCE_SH_DEFAULT;
  517. } else {
  518. styler.ColourTo(i - 1, state);
  519. state = SCE_SH_DEFAULT;
  520. goto restartLexer;
  521. }
  522. }
  523. } else if (state == SCE_SH_STRING
  524. || state == SCE_SH_CHARACTER
  525. || state == SCE_SH_BACKTICKS
  526. || state == SCE_SH_PARAM
  527. ) {
  528. if (!Quote.Down && !isspacechar(ch)) {
  529. Quote.Open(ch);
  530. } else if (ch == '\\' && Quote.Up != '\\') {
  531. i++;
  532. ch = chNext;
  533. chNext = styler.SafeGetCharAt(i + 1);
  534. } else if (ch == Quote.Down) {
  535. Quote.Count--;
  536. if (Quote.Count == 0) {
  537. Quote.Rep--;
  538. if (Quote.Rep <= 0) {
  539. styler.ColourTo(i, state);
  540. state = SCE_SH_DEFAULT;
  541. ch = ' ';
  542. }
  543. if (Quote.Up == Quote.Down) {
  544. Quote.Count++;
  545. }
  546. }
  547. } else if (ch == Quote.Up) {
  548. Quote.Count++;
  549. }
  550. }
  551. }
  552. if (state == SCE_SH_ERROR) {
  553. break;
  554. }
  555. chPrev = ch;
  556. }
  557. styler.ColourTo(lengthDoc - 1, state);
  558. }
  559. static bool IsCommentLine(int line, Accessor &styler) {
  560. int pos = styler.LineStart(line);
  561. int eol_pos = styler.LineStart(line + 1) - 1;
  562. for (int i = pos; i < eol_pos; i++) {
  563. char ch = styler[i];
  564. if (ch == '#')
  565. return true;
  566. else if (ch != ' ' && ch != '\t')
  567. return false;
  568. }
  569. return false;
  570. }
  571. static void FoldBashDoc(unsigned int startPos, int length, int, WordList *[],
  572. Accessor &styler) {
  573. bool foldComment = styler.GetPropertyInt("fold.comment") != 0;
  574. bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
  575. unsigned int endPos = startPos + length;
  576. int visibleChars = 0;
  577. int lineCurrent = styler.GetLine(startPos);
  578. int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK;
  579. int levelCurrent = levelPrev;
  580. char chNext = styler[startPos];
  581. int styleNext = styler.StyleAt(startPos);
  582. for (unsigned int i = startPos; i < endPos; i++) {
  583. char ch = chNext;
  584. chNext = styler.SafeGetCharAt(i + 1);
  585. int style = styleNext;
  586. styleNext = styler.StyleAt(i + 1);
  587. bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n');
  588. // Comment folding
  589. if (foldComment && atEOL && IsCommentLine(lineCurrent, styler))
  590. {
  591. if (!IsCommentLine(lineCurrent - 1, styler)
  592. && IsCommentLine(lineCurrent + 1, styler))
  593. levelCurrent++;
  594. else if (IsCommentLine(lineCurrent - 1, styler)
  595. && !IsCommentLine(lineCurrent+1, styler))
  596. levelCurrent--;
  597. }
  598. if (style == SCE_C_OPERATOR) {
  599. if (ch == '{') {
  600. levelCurrent++;
  601. } else if (ch == '}') {
  602. levelCurrent--;
  603. }
  604. }
  605. if (atEOL) {
  606. int lev = levelPrev;
  607. if (visibleChars == 0 && foldCompact)
  608. lev |= SC_FOLDLEVELWHITEFLAG;
  609. if ((levelCurrent > levelPrev) && (visibleChars > 0))
  610. lev |= SC_FOLDLEVELHEADERFLAG;
  611. if (lev != styler.LevelAt(lineCurrent)) {
  612. styler.SetLevel(lineCurrent, lev);
  613. }
  614. lineCurrent++;
  615. levelPrev = levelCurrent;
  616. visibleChars = 0;
  617. }
  618. if (!isspacechar(ch))
  619. visibleChars++;
  620. }
  621. // Fill in the real level of the next line, keeping the current flags as they will be filled in later
  622. int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK;
  623. styler.SetLevel(lineCurrent, levelPrev | flagsNext);
  624. }
  625. static const char * const bashWordListDesc[] = {
  626. "Keywords",
  627. 0
  628. };
  629. LexerModule lmBash(SCLEX_BASH, ColouriseBashDoc, "bash", FoldBashDoc, bashWordListDesc);