📄 lexperl.cxx
字号:
goto restartLexer; } } } } } else if (state == SCE_PL_SCALAR // variable names || state == SCE_PL_ARRAY || state == SCE_PL_HASH || state == SCE_PL_SYMBOLTABLE) { if (ch == ':' && chNext == ':') { // skip :: i++; ch = chNext; chNext = chNext2; } else if (isEndVar(ch)) { if (i == (styler.GetStartSegment() + 1)) { // Special variable: $(, $_ etc. styler.ColourTo(i, state); state = SCE_PL_DEFAULT; } else { styler.ColourTo(i - 1, state); state = SCE_PL_DEFAULT; goto restartLexer; } } } else if (state == SCE_PL_REGEX || state == SCE_PL_STRING_QR ) { if (!Quote.Up && !isspacechar(ch)) { Quote.Open(ch); } else if (ch == '\\' && Quote.Up != '\\') { // SG: Is it save to skip *every* escaped char? i++; ch = chNext; chNext = styler.SafeGetCharAt(i + 1); } else { if (ch == Quote.Down /*&& chPrev != '\\'*/) { Quote.Count--; if (Quote.Count == 0) { Quote.Rep--; if (Quote.Up == Quote.Down) { Quote.Count++; } } if (!isalpha(chNext)) { if (Quote.Rep <= 0) { styler.ColourTo(i, state); state = SCE_PL_DEFAULT; ch = ' '; } } } else if (ch == Quote.Up /*&& chPrev != '\\'*/) { Quote.Count++; } else if (!isascii(chNext) || !isalpha(chNext)) { if (Quote.Rep <= 0) { styler.ColourTo(i, state); state = SCE_PL_DEFAULT; ch = ' '; } } } } else if (state == SCE_PL_REGSUBST) { if (!Quote.Up && !isspacechar(ch)) { Quote.Open(ch); } else if (ch == '\\' && Quote.Up != '\\') { // SG: Is it save to skip *every* escaped char? i++; ch = chNext; chNext = styler.SafeGetCharAt(i + 1); } else { if (Quote.Count == 0 && Quote.Rep == 1) { /* We matched something like s(...) or tr{...} * and are looking for the next matcher characters, * which could be either bracketed ({...}) or non-bracketed * (/.../). * * Number-signs are problematic. If they occur after * the close of the first part, treat them like * a Quote.Up char, even if they actually start comments. * * If we find an alnum, we end the regsubst, and punt. * * Eric Promislow ericp@activestate.com Aug 9,2000 */ if (isspacechar(ch)) { // Keep going } else if (!isascii(ch) || isalnum(ch)) { styler.ColourTo(i, state); state = SCE_PL_DEFAULT; ch = ' '; } else { Quote.Open(ch); } } else if (ch == Quote.Down /*&& chPrev != '\\'*/) { Quote.Count--; if (Quote.Count == 0) { Quote.Rep--; } if (!isascii(chNext) || !isalpha(chNext)) { if (Quote.Rep <= 0) { styler.ColourTo(i, state); state = SCE_PL_DEFAULT; ch = ' '; } } if (Quote.Up == Quote.Down) { Quote.Count++; } } else if (ch == Quote.Up /*&& chPrev != '\\'*/) { Quote.Count++; } else if (!isascii(chNext) || !isalpha(chNext)) { if (Quote.Rep <= 0) { styler.ColourTo(i, state); state = SCE_PL_DEFAULT; ch = ' '; } } } } else if (state == SCE_PL_STRING_Q || state == SCE_PL_STRING_QQ || state == SCE_PL_STRING_QX || state == SCE_PL_STRING_QW || state == SCE_PL_STRING || state == SCE_PL_CHARACTER || state == SCE_PL_BACKTICKS ) { 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_PL_DEFAULT; ch = ' '; } if (Quote.Up == Quote.Down) { Quote.Count++; } } } else if (ch == Quote.Up) { Quote.Count++; } } else if (state == SCE_PL_SUB_PROTOTYPE) { char strch[2]; strch[0] = ch; strch[1] = '\0'; if (NULL != strstr("\\[$@%&*];", strch)) { // keep going } else if (ch == ')') { styler.ColourTo(i, state); state = SCE_PL_DEFAULT; } else { // abandon prototype, restart from '(' i = backPos; styler.ColourTo(i, SCE_PL_OPERATOR); ch = styler.SafeGetCharAt(i); chNext = styler.SafeGetCharAt(i + 1); state = SCE_PL_DEFAULT; } } else if (state == SCE_PL_FORMAT_IDENT) { // occupies different HereDoc states to avoid clashing with HERE docs if (HereDoc.State == 0) { if ((isascii(ch) && isalpha(ch)) || ch == '_' // probable identifier || ch == '=') { // no identifier HereDoc.State = 3; HereDoc.Quoted = false; // whitespace flag } else if (ch == ' ' || ch == '\t') { styler.ColourTo(i, SCE_PL_DEFAULT); } else { state = SCE_PL_DEFAULT; HereDoc.State = 0; goto restartLexer; } } if (HereDoc.State == 3) { // with just a '=', state goes 0->3->4 if (ch == '=') { styler.ColourTo(i, SCE_PL_FORMAT_IDENT); state = SCE_PL_DEFAULT; HereDoc.State = 4; } else if (ch == ' ' || ch == '\t') { HereDoc.Quoted = true; } else if (isEOLChar(ch) || (HereDoc.Quoted && ch != '=')) { // abandon format, restart from after 'format' i = backPos + 1; ch = styler.SafeGetCharAt(i); chNext = styler.SafeGetCharAt(i + 1); state = SCE_PL_DEFAULT; HereDoc.State = 0; } } } else if (state == SCE_PL_FORMAT) { if (isEOLChar(chPrev)) { styler.ColourTo(i - 1, state); if (ch == '.' && isEOLChar(chNext)) { styler.ColourTo(i, state); state = SCE_PL_DEFAULT; } } } } if (state == SCE_PL_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]; int style = styler.StyleAt(i); if (ch == '#' && style == SCE_PL_COMMENTLINE) return true; else if (ch != ' ' && ch != '\t') return false; } return false;}static void FoldPerlDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) { bool foldComment = styler.GetPropertyInt("fold.comment") != 0; bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0; // Custom folding of POD and packages bool foldPOD = styler.GetPropertyInt("fold.perl.pod", 1) != 0; bool foldPackage = styler.GetPropertyInt("fold.perl.package", 1) != 0; unsigned int endPos = startPos + length; int visibleChars = 0; int lineCurrent = styler.GetLine(startPos); int levelPrev = SC_FOLDLEVELBASE; if (lineCurrent > 0) levelPrev = styler.LevelAt(lineCurrent - 1) >> 16; int levelCurrent = levelPrev; char chNext = styler[startPos]; char chPrev = styler.SafeGetCharAt(startPos - 1); int styleNext = styler.StyleAt(startPos); // Used at end of line to determine if the line was a package definition bool isPackageLine = false; bool isPodHeading = false; 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'); bool atLineStart = isEOLChar(chPrev) || i == 0; // 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_C_OPERATOR) { if (ch == '{') { levelCurrent++; } else if (ch == '}') { levelCurrent--; } } // Custom POD folding if (foldPOD && atLineStart) { int stylePrevCh = (i) ? styler.StyleAt(i - 1):SCE_PL_DEFAULT; if (style == SCE_PL_POD) { if (stylePrevCh != SCE_PL_POD && stylePrevCh != SCE_PL_POD_VERB) levelCurrent++; else if (styler.Match(i, "=cut")) levelCurrent--; else if (styler.Match(i, "=head")) isPodHeading = true; } else if (style == SCE_PL_DATASECTION) { if (ch == '=' && isalpha(chNext) && levelCurrent == SC_FOLDLEVELBASE) levelCurrent++; else if (styler.Match(i, "=cut") && levelCurrent > SC_FOLDLEVELBASE) levelCurrent--; else if (styler.Match(i, "=head")) isPodHeading = true; // if package used or unclosed brace, level > SC_FOLDLEVELBASE! // reset needed as level test is vs. SC_FOLDLEVELBASE else if (styler.Match(i, "__END__")) levelCurrent = SC_FOLDLEVELBASE; } } // Custom package folding if (foldPackage && atLineStart) { if (style == SCE_PL_WORD && styler.Match(i, "package")) { isPackageLine = true; } } if (atEOL) { int lev = levelPrev; if (isPodHeading) { lev = levelPrev - 1; lev |= SC_FOLDLEVELHEADERFLAG; isPodHeading = false; } // Check if line was a package declaration // because packages need "special" treatment if (isPackageLine) { lev = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG; levelCurrent = SC_FOLDLEVELBASE + 1; isPackageLine = false; } lev |= levelCurrent << 16; 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++; chPrev = ch; } // 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 perlWordListDesc[] = { "Keywords", 0};LexerModule lmPerl(SCLEX_PERL, ColourisePerlDoc, "perl", FoldPerlDoc, perlWordListDesc, 8);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -