diff --git a/uppsrc/CodeEditor/CRegister.icpp b/uppsrc/CodeEditor/CRegister.icpp index 20ed38e9d..6841b840b 100644 --- a/uppsrc/CodeEditor/CRegister.icpp +++ b/uppsrc/CodeEditor/CRegister.icpp @@ -23,6 +23,11 @@ void CreateDiffSyntax(One& e) e.Create(); } +void CreateLogSyntax(One& e) +{ + e.Create(); +} + INITBLOCK { RegisterCSyntax("cpp", CSyntax::HIGHLIGHT_CPP, @@ -44,6 +49,8 @@ INITBLOCK EditorSyntax::Register("html", callback1(CreateTagSyntax, true), "*.html *.htm", "HTML (.html)"); EditorSyntax::Register("diff", callback(CreateDiffSyntax), "*.diff *.patch", "Diff"); + + EditorSyntax::Register("log", callback(CreateLogSyntax), "*.log", "Log (*.log)"); } END_UPP_NAMESPACE diff --git a/uppsrc/CodeEditor/CodeEditor.h b/uppsrc/CodeEditor/CodeEditor.h index 809ac7ee3..9f33ae757 100644 --- a/uppsrc/CodeEditor/CodeEditor.h +++ b/uppsrc/CodeEditor/CodeEditor.h @@ -172,6 +172,7 @@ struct FindReplaceDlg : FrameBottom< WithIDEFindReplaceLayout > { #include "CSyntax.h" #include "DiffSyntax.h" #include "TagSyntax.h" +#include "LogSyntax.h" class CodeEditor : public LineEdit, public HighlightSetup //TODO:SYNTAX diff --git a/uppsrc/CodeEditor/CodeEditor.upp b/uppsrc/CodeEditor/CodeEditor.upp index 46efb9c3f..c9861e2c3 100644 --- a/uppsrc/CodeEditor/CodeEditor.upp +++ b/uppsrc/CodeEditor/CodeEditor.upp @@ -28,6 +28,9 @@ file TagSyntax readonly separator, TagSyntax.h, TagSyntax.cpp, + LogSyntax readonly separator, + LogSyntax.h, + LogSyntax.cpp, Editor readonly separator, EditorBar.cpp, FindReplace.cpp, diff --git a/uppsrc/CodeEditor/DiffSyntax.h b/uppsrc/CodeEditor/DiffSyntax.h index 3542e3cc7..e6bfd0641 100644 --- a/uppsrc/CodeEditor/DiffSyntax.h +++ b/uppsrc/CodeEditor/DiffSyntax.h @@ -14,5 +14,4 @@ protected: private: HighlightOutput *hout; - }; diff --git a/uppsrc/CodeEditor/LogSyntax.cpp b/uppsrc/CodeEditor/LogSyntax.cpp new file mode 100644 index 000000000..23f15dffb --- /dev/null +++ b/uppsrc/CodeEditor/LogSyntax.cpp @@ -0,0 +1,47 @@ +#include "CodeEditor.h" + +NAMESPACE_UPP + +void LogSyntax::Highlight(const wchar *s, const wchar *end, HighlightOutput& hls, CodeEditor *editor, int line, int pos) +{ + const HlStyle& ink = hl_style[INK_NORMAL]; + const HlStyle& paper = hl_style[PAPER_NORMAL]; + HlStyle err = hl_style[INK_ERROR]; + err.bold = true; + bool hl_line = false; + while(s < end) { + if(IsDigit(*s)) { + const wchar *s0 = s; + bool fp = false; + while(IsDigit(*s) || *s == '.' || *s == 'e') { + fp = fp || *s == '.' || *s == 'e'; + s++; + } + hls.Put(int(s - s0), hl_style[fp ? INK_CONST_FLOAT : INK_CONST_INT]); + } + else + if(IsAlpha(*s)) { + static Index rws; + ONCELOCK { + rws << "error" << "errors" << "warning" << "warnings" << "failed" << "exit" << "fatal" + << "failure" << "rejected"; + } + String w; + while(IsAlNum(*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(*s, '[', ']', '(', ')', ':', '-', '=', '{', '}', '/', '<', '>', '*', '#', '@') >= 0; + hls.Put(1, hl ? hl_style[INK_OPERATOR] : ink); + s++; + } + + } + if(hl_line) + hls.SetPaper(0, hls.GetCount(), hl_style[PAPER_WARNING].color); +} + +END_UPP_NAMESPACE diff --git a/uppsrc/CodeEditor/LogSyntax.h b/uppsrc/CodeEditor/LogSyntax.h new file mode 100644 index 000000000..0f6b90899 --- /dev/null +++ b/uppsrc/CodeEditor/LogSyntax.h @@ -0,0 +1,8 @@ +class LogSyntax : public EditorSyntax { +public: + virtual void Highlight(const wchar *s, const wchar *end, HighlightOutput& hls, + CodeEditor *editor, int line, int pos); + +private: + HighlightOutput *hout; +}; diff --git a/uppsrc/CodeEditor/Syntax.h b/uppsrc/CodeEditor/Syntax.h index c1678ae08..10338190e 100644 --- a/uppsrc/CodeEditor/Syntax.h +++ b/uppsrc/CodeEditor/Syntax.h @@ -79,6 +79,7 @@ public: void Put(int count, const HlStyle& ink, const HlStyle& paper); void Put(const HlStyle& ink) { Put(1, ink); } void Put(const HlStyle& ink, word flags) { Put(1, ink); v[pos - 1].flags = flags; } + int GetCount() const { return v.GetCount(); } const wchar *CString(const wchar *p);