void LogSyntax::Highlight(const wchar *s, const wchar *end, HighlightOutput& hls, CodeEditor *editor, int line, int pos) { const HlStyle& ink = hl_style[INK_NORMAL]; HlStyle err = hl_style[INK_ERROR]; err.bold = true; bool hl_line = false; bool sep_line = false; while(s < end) { int c = *s; const wchar *s0 = s; if(s + 3 <= end && (Is3(s, '-') || Is3(s, '*') || Is3(s, '=') || Is3(s, '+') || Is3(s, '#') || Is3(s, ':') || Is3(s, '%') || Is3(s, '$'))) sep_line = true; if(IsDigit(c)) s = HighlightNumber(hls, s, thousands_separator, false, false); else if(c == '\'' || c == '\"') { s++; for(;;) { if(s >= end) { hls.Put(1, ink); s = s0 + 1; break; } if(*s == c) { s++; hls.Put((int)(s - s0), hl_style[INK_CONST_STRING]); break; } s += 1 + (s[0] == '\\' && s[1] == c); } } else if(IsAlpha(c) || c == '_') { static Index<String> rws; ONCELOCK { rws << "error" << "errors" << "warning" << "warnings" << "failed" << "exit" << "fatal" << "failure" << "rejected"; } String w; while(s < end && IsAlNum(*s) || *s == '_') w.Cat(ToLower(*s++)); bool hl = rws.Find(w) >= 0; hls.Put(w.GetCount(), hl ? err : ink); hl_line = hl_line || hl; } else { bool hl = findarg(c, '[', ']', '(', ')', ':', '-', '=', '{', '}', '/', '<', '>', '*', '#', '@', '\\', '.') >= 0; hls.Put(1, hl ? hl_style[INK_OPERATOR] : ink); s++; } }
void PythonSyntax::Highlight(const wchar *start, const wchar *end, HighlightOutput& hls, CodeEditor *editor, int line, int pos) { InitKeywords(); bool isComment = false; bool isStr = false; char strOpening; const wchar* p = start; while(p < end) { if((*p == '#' || isComment) && !isStr) { isComment = true; hls.Put(hl_style[INK_COMMENT]); } else if(*p == '\'' || *p == '\"' || isStr) { hls.Put(hl_style[INK_CONST_STRING]); if((*p == '\'' || *p == '\"') && p - 1 != start && *(p - 1) != '\\') if (!isStr || strOpening == *p) { isStr = !isStr; strOpening = (char)*p; } } else if(IsSeparator(p) || p == start) { WString w; bool isW = false; const wchar* bp = (p == start && !IsSeparator(p)) ? p : p + 1; while (bp != end && !IsSeparator(bp)) w += *bp++; bool isPutted = false; if(IsSeparator(p)) { hls.Put(hl_style[INK_NORMAL]); isPutted = true; } if(IsKeyword(w)) { hls.Put(w.GetLength(), hl_style[INK_KEYWORD]); isW = true; } else if(IsSpecialVar(w)) { hls.Put(w.GetLength(), hl_style[INK_UPP]); isW = true; } else if(IsNumber(w)) { hls.Put(w.GetLength(), hl_style[INK_CONST_INT]); isW = true; } if(isW) { p += w.GetLength() - (isPutted ? 0 : 1); } } else hls.Put(hl_style[INK_NORMAL]); p++; } }