📄 lexbash.cxx
字号:
} styler.ColourTo(i, SCE_SH_OPERATOR); } else if (ch == '<' && chNext == '<') { state = SCE_SH_HERE_DELIM; HereDoc.State = 0; HereDoc.Indent = false; } else if (ch == '-' // file test operators && isSingleCharOp(chNext) && !isalnum((chNext2 = styler.SafeGetCharAt(i+2)))) { styler.ColourTo(i + 1, SCE_SH_WORD); state = SCE_SH_DEFAULT; i++; ch = chNext; chNext = chNext2; } else if (isBashOperator(ch)) { styler.ColourTo(i, SCE_SH_OPERATOR); } else { // keep colouring defaults to make restart easier styler.ColourTo(i, SCE_SH_DEFAULT); } } else if (state == SCE_SH_NUMBER) { int digit = translateBashDigit(ch); if (numBase == BASH_BASE_DECIMAL) { if (ch == '#') { numBase = getBashNumberBase(styler.GetStartSegment(), i - 1, styler); if (numBase == BASH_BASE_ERROR) // take the rest as comment goto numAtEnd; } else if (!isdigit(ch)) goto numAtEnd; } else if (numBase == BASH_BASE_HEX) { if ((digit < 16) || (digit >= 36 && digit <= 41)) { // hex digit 0-9a-fA-F } else goto numAtEnd; } else if (numBase == BASH_BASE_OCTAL || numBase == BASH_BASE_OCTAL_ERROR) { if (digit > 7) { if (digit <= 9) { numBase = BASH_BASE_OCTAL_ERROR; } else goto numAtEnd; } } else if (numBase == BASH_BASE_ERROR) { if (digit > 9) goto numAtEnd; } else { // DD#DDDD number style handling if (digit != BASH_BASE_ERROR) { if (numBase <= 36) { // case-insensitive if base<=36 if (digit >= 36) digit -= 26; } if (digit >= numBase) { if (digit <= 9) { numBase = BASH_BASE_ERROR; } else goto numAtEnd; } } else { numAtEnd: if (numBase == BASH_BASE_ERROR || numBase == BASH_BASE_OCTAL_ERROR) state = SCE_SH_ERROR; styler.ColourTo(i - 1, state); state = SCE_SH_DEFAULT; goto restartLexer; } } } else if (state == SCE_SH_WORD) { if (!iswordchar(chNext) && chNext != '+' && chNext != '-') { // "." never used in Bash variable names // but used in file names classifyWordBash(styler.GetStartSegment(), i, keywords, styler); state = SCE_SH_DEFAULT; ch = ' '; } } else if (state == SCE_SH_IDENTIFIER) { if (!iswordchar(chNext) && chNext != '+' && chNext != '-') { styler.ColourTo(i, SCE_SH_IDENTIFIER); state = SCE_SH_DEFAULT; ch = ' '; } } else { if (state == SCE_SH_COMMENTLINE) { if (ch == '\\' && isEOLChar(chNext)) { // comment continuation if (chNext == '\r' && chNext2 == '\n') { i += 2; ch = styler.SafeGetCharAt(i); chNext = styler.SafeGetCharAt(i + 1); } else { i++; ch = chNext; chNext = chNext2; } } else if (isEOLChar(ch)) { styler.ColourTo(i - 1, state); state = SCE_SH_DEFAULT; goto restartLexer; } else if (isEOLChar(chNext)) { styler.ColourTo(i, state); state = SCE_SH_DEFAULT; } } else if (state == SCE_SH_HERE_DELIM) { // // From Bash info: // --------------- // Specifier format is: <<[-]WORD // Optional '-' is for removal of leading tabs from here-doc. // Whitespace acceptable after <<[-] operator // if (HereDoc.State == 0) { // '<<' encountered HereDoc.State = 1; HereDoc.Quote = chNext; HereDoc.Quoted = false; HereDoc.DelimiterLength = 0; HereDoc.Delimiter[HereDoc.DelimiterLength] = '\0'; if (chNext == '\'' || chNext == '\"') { // a quoted here-doc delimiter (' or ") i++; ch = chNext; chNext = chNext2; HereDoc.Quoted = true; } else if (!HereDoc.Indent && chNext == '-') { // <<- indent case HereDoc.Indent = true; HereDoc.State = 0; } else if (isalpha(chNext) || chNext == '_' || chNext == '\\' || chNext == '-' || chNext == '+' || chNext == '!') { // an unquoted here-doc delimiter, no special handling // TODO check what exactly bash considers part of the delim } else if (chNext == '<') { // HERE string <<< i++; ch = chNext; chNext = chNext2; styler.ColourTo(i, SCE_SH_HERE_DELIM); state = SCE_SH_DEFAULT; HereDoc.State = 0; } else if (isspacechar(chNext)) { // eat whitespace HereDoc.State = 0; } else if (isdigit(chNext) || chNext == '=' || chNext == '$') { // left shift << or <<= operator cases styler.ColourTo(i, SCE_SH_OPERATOR); state = SCE_SH_DEFAULT; HereDoc.State = 0; } else { // symbols terminates; deprecated zero-length delimiter } } else if (HereDoc.State == 1) { // collect the delimiter if (HereDoc.Quoted) { // a quoted here-doc delimiter if (ch == HereDoc.Quote) { // closing quote => end of delimiter styler.ColourTo(i, state); state = SCE_SH_DEFAULT; } else { if (ch == '\\' && chNext == HereDoc.Quote) { // escaped quote i++; ch = chNext; chNext = chNext2; } HereDoc.Delimiter[HereDoc.DelimiterLength++] = ch; HereDoc.Delimiter[HereDoc.DelimiterLength] = '\0'; } } else { // an unquoted here-doc delimiter if (isalnum(ch) || ch == '_' || ch == '-' || ch == '+' || ch == '!') { HereDoc.Delimiter[HereDoc.DelimiterLength++] = ch; HereDoc.Delimiter[HereDoc.DelimiterLength] = '\0'; } else if (ch == '\\') { // skip escape prefix } else { styler.ColourTo(i - 1, state); state = SCE_SH_DEFAULT; goto restartLexer; } } if (HereDoc.DelimiterLength >= HERE_DELIM_MAX - 1) { styler.ColourTo(i - 1, state); state = SCE_SH_ERROR; goto restartLexer; } } } else if (HereDoc.State == 2) { // state == SCE_SH_HERE_Q if (isMatch(styler, lengthDoc, i, HereDoc.Delimiter)) { if (!HereDoc.Indent && isEOLChar(chPrev)) { endHereDoc: // standard HERE delimiter i += HereDoc.DelimiterLength; chPrev = styler.SafeGetCharAt(i - 1); ch = styler.SafeGetCharAt(i); if (isEOLChar(ch)) { styler.ColourTo(i - 1, state); state = SCE_SH_DEFAULT; HereDoc.State = 0; goto restartLexer; } chNext = styler.SafeGetCharAt(i + 1); } else if (HereDoc.Indent) { // indented HERE delimiter unsigned int bk = (i > 0)? i - 1: 0; while (i > 0) { ch = styler.SafeGetCharAt(bk--); if (isEOLChar(ch)) { goto endHereDoc; } else if (!isspacechar(ch)) { break; // got leading non-whitespace } } } } } else if (state == SCE_SH_SCALAR) { // variable names if (isEndVar(ch)) { if ((state == SCE_SH_SCALAR) && i == (styler.GetStartSegment() + 1)) { // Special variable: $(, $_ etc. styler.ColourTo(i, state); state = SCE_SH_DEFAULT; } else { styler.ColourTo(i - 1, state); state = SCE_SH_DEFAULT; goto restartLexer; } } } else if (state == SCE_SH_STRING || state == SCE_SH_CHARACTER || state == SCE_SH_BACKTICKS || state == SCE_SH_PARAM ) { if (!Quote.Down && !isspacechar(ch)) { Quote.Open(ch); } else if (ch == '\\' && Quote.Up != '\\') { i++; ch = chNext; chNext = styler.SafeGetCharAt(i + 1); } else if (ch == Quote.Down) { Quote.Count--; if (Quote.Count == 0) { Quote.Rep--; if (Quote.Rep <= 0) { styler.ColourTo(i, state); state = SCE_SH_DEFAULT; ch = ' '; } if (Quote.Up == Quote.Down) { Quote.Count++; } } } else if (ch == Quote.Up) { Quote.Count++; } } } if (state == SCE_SH_ERROR) { break; } chPrev = ch; } styler.ColourTo(lengthDoc - 1, state);}static bool IsCommentLine(int line, Accessor &styler) { int pos = styler.LineStart(line); int eol_pos = styler.LineStart(line + 1) - 1; for (int i = pos; i < eol_pos; i++) { char ch = styler[i]; if (ch == '#') return true; else if (ch != ' ' && ch != '\t') return false; } return false;}static void FoldBashDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) { bool foldComment = styler.GetPropertyInt("fold.comment") != 0; bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0; unsigned int endPos = startPos + length; int visibleChars = 0; int lineCurrent = styler.GetLine(startPos); int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK; int levelCurrent = levelPrev; char chNext = styler[startPos]; int styleNext = styler.StyleAt(startPos); for (unsigned int i = startPos; i < endPos; i++) { char ch = chNext; chNext = styler.SafeGetCharAt(i + 1); int style = styleNext; styleNext = styler.StyleAt(i + 1); bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n'); // Comment folding if (foldComment && atEOL && IsCommentLine(lineCurrent, styler)) { if (!IsCommentLine(lineCurrent - 1, styler) && IsCommentLine(lineCurrent + 1, styler)) levelCurrent++; else if (IsCommentLine(lineCurrent - 1, styler) && !IsCommentLine(lineCurrent+1, styler)) levelCurrent--; } if (style == SCE_SH_OPERATOR) { if (ch == '{') { levelCurrent++; } else if (ch == '}') { levelCurrent--; } } if (atEOL) { int lev = levelPrev; if (visibleChars == 0 && foldCompact) lev |= SC_FOLDLEVELWHITEFLAG; if ((levelCurrent > levelPrev) && (visibleChars > 0)) lev |= SC_FOLDLEVELHEADERFLAG; if (lev != styler.LevelAt(lineCurrent)) { styler.SetLevel(lineCurrent, lev); } lineCurrent++; levelPrev = levelCurrent; visibleChars = 0; } if (!isspacechar(ch)) visibleChars++; } // Fill in the real level of the next line, keeping the current flags as they will be filled in later int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK; styler.SetLevel(lineCurrent, levelPrev | flagsNext);}static const char * const bashWordListDesc[] = { "Keywords", 0};LexerModule lmBash(SCLEX_BASH, ColouriseBashDoc, "bash", FoldBashDoc, bashWordListDesc);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -