diff options
Diffstat (limited to '')
-rw-r--r-- | src/textfile_highlighters.cc | 118 |
1 files changed, 115 insertions, 3 deletions
diff --git a/src/textfile_highlighters.cc b/src/textfile_highlighters.cc index b0d2c52..46db3f1 100644 --- a/src/textfile_highlighters.cc +++ b/src/textfile_highlighters.cc @@ -37,7 +37,8 @@ template<typename T, std::size_t N> static std::shared_ptr<lnav::pcre2pp::code> xpcre_compile(const T (&pattern)[N], int options = 0) { - return lnav::pcre2pp::code::from_const(pattern, options).to_shared(); + return lnav::pcre2pp::code::from_const(pattern, options | PCRE2_MULTILINE) + .to_shared(); } void @@ -93,6 +94,7 @@ setup_highlights(highlight_map_t& hm) "\\bconst\\b|" "\\bcontinue\\b|" "\\bcrate\\b|" + "\\bdyn\\b|" "\\belse\\b|" "\\bif\\b|" "\\bif let\\b|" @@ -242,6 +244,16 @@ setup_highlights(highlight_map_t& hm) .with_text_format(text_format_t::TF_JAVA) .with_role(role_t::VCR_KEYWORD); + hm[{highlight_source_t::INTERNAL, "json.keyword"}] + = highlighter(xpcre_compile(R"((?:null|true|false))")) + .with_nestable(false) + .with_text_format(text_format_t::TF_JSON) + .with_role(role_t::VCR_KEYWORD); + hm[{highlight_source_t::INTERNAL, "json.number"}] + = highlighter(xpcre_compile(R"(-?\d+(?:\.\d+(?:[eE][+\-]?\d+)?)?)")) + .with_nestable(false) + .with_text_format(text_format_t::TF_JSON) + .with_role(role_t::VCR_NUMBER); hm[{highlight_source_t::INTERNAL, "sql.0.comment"}] = highlighter(xpcre_compile("(?:(?<=[\\s;])|^)--.*")) .with_text_format(text_format_t::TF_SQL) @@ -397,6 +409,14 @@ setup_highlights(highlight_map_t& hm) hm[{highlight_source_t::INTERNAL, "1.strings"}] = highlighter(xpcre_compile(R"((?<![A-WY-Za-qstv-z])'(?:\\.|[^'])*')")) .with_nestable(false) + .with_text_format(text_format_t::TF_C_LIKE) + .with_text_format(text_format_t::TF_JAVA) + .with_text_format(text_format_t::TF_MARKDOWN) + .with_text_format(text_format_t::TF_PYTHON) + .with_text_format(text_format_t::TF_SQL) + .with_text_format(text_format_t::TF_XML) + .with_text_format(text_format_t::TF_YAML) + .with_text_format(text_format_t::TF_TOML) .with_role(role_t::VCR_STRING); hm[{highlight_source_t::INTERNAL, "1.stringb"}] = highlighter(xpcre_compile("`(?:\\\\.|[^`])*`")) @@ -411,10 +431,22 @@ setup_highlights(highlight_map_t& hm) = highlighter(xpcre_compile("^\\@@ .*")) .with_role(role_t::VCR_DIFF_SECTION); hm[{highlight_source_t::INTERNAL, "0.comment"}] + = highlighter(xpcre_compile(R"((?<=[\s;]|^)//.*|/\*.*\*/|\(\*.*\*\))")) + .with_nestable(false) + .with_text_format(text_format_t::TF_C_LIKE) + .with_text_format(text_format_t::TF_JAVA) + .with_text_format(text_format_t::TF_RUST) + .with_role(role_t::VCR_COMMENT); + hm[{highlight_source_t::INTERNAL, ".comment"}] = highlighter( xpcre_compile( - R"((?<=[\s;])//.*|/\*.*\*/|\(\*.*\*\)|^#\s*(?!include|if|ifndef|elif|else|endif|error|pragma|define|undef).*|\s+#.*|dnl.*)")) + R"((?:\s+#.*|^\s*#(?!\s*(?:include|if|ifndef|elif|else|endif|error|pragma|define|undef)\b).*|dnl.*))")) .with_nestable(false) + .with_text_format(text_format_t::TF_SHELL_SCRIPT) + .with_text_format(text_format_t::TF_PYTHON) + .with_text_format(text_format_t::TF_MAKEFILE) + .with_text_format(text_format_t::TF_YAML) + .with_text_format(text_format_t::TF_TOML) .with_role(role_t::VCR_COMMENT); hm[{highlight_source_t::INTERNAL, "javadoc"}] = highlighter( @@ -431,6 +463,11 @@ setup_highlights(highlight_map_t& hm) ")")) .with_nestable(false) .with_role(role_t::VCR_VARIABLE); + hm[{highlight_source_t::INTERNAL, "yaml.var"}] + = highlighter(xpcre_compile("^\\s*(?:- )?[a-zA-Z_\\-]+:(?:\\s+|$)")) + .with_nestable(false) + .with_text_format(text_format_t::TF_YAML) + .with_role(role_t::VCR_VARIABLE); hm[{highlight_source_t::INTERNAL, "rust.sym"}] = highlighter(xpcre_compile("\\b[A-Z_][A-Z0-9_]+\\b")) .with_nestable(false) @@ -450,15 +487,90 @@ setup_highlights(highlight_map_t& hm) hm[{highlight_source_t::INTERNAL, "cpp"}] = highlighter( xpcre_compile( - R"(^#\s*(?:include|ifdef|ifndef|if|else|elif|error|endif|define|undef|pragma))")) + R"(^#\s*(?:include|ifdef|ifndef|if|else|elif|error|endif|define|undef|pragma)\b)")) .with_nestable(false) .with_text_format(text_format_t::TF_C_LIKE) .with_text_format(text_format_t::TF_JAVA) .with_role(role_t::VCR_KEYWORD); + hm[{highlight_source_t::INTERNAL, "shell"}] + = highlighter(xpcre_compile("(?:" + "\\bbreak\\b|" + "\\bcase\\b|" + "\\bcd\\b|" + "\\bcontinue\\b|" + "\\bdeclare\\b|" + "\\bdefault\\b|" + "\\bdo\\b|" + "\\bdone\\b|" + "\\becho\\b|" + "\\belif\\b|" + "\\belse\\b|" + "\\besac\\b|" + "\\beval\\b|" + "\\bexit\\b|" + "\\bexport\\b|" + "\\bfalse\\b|" + "\\bfi\\b|" + "\\bfor\\b|" + "\\bfunction\\b|" + "\\bif\\b|" + "\\bin\\b|" + "\\blocal\\b|" + "\\bprintf\\b|" + "\\bpwd\\b|" + "\\bread\\b|" + "\\breadonly\\b|" + "\\breturn\\b|" + "\\bset\\b|" + "\\bshift\\b|" + "\\bsource\\b|" + "\\btest\\b|" + "\\bthen\\b|" + "\\btrap\\b|" + "\\btrue\\b|" + "\\bunset\\b|" + "\\bunsetenv\\b|" + "\\buntil\\b|" + "\\bwhich\\b|" + "\\bwhile\\b" + ")")) + .with_nestable(false) + .with_text_format(text_format_t::TF_SHELL_SCRIPT) + .with_role(role_t::VCR_KEYWORD); hm[{highlight_source_t::INTERNAL, "num"}] = highlighter(xpcre_compile(R"(\b-?(?:\d+|0x[a-zA-Z0-9]+)\b)")) .with_nestable(false) .with_text_format(text_format_t::TF_C_LIKE) .with_text_format(text_format_t::TF_JAVA) + .with_text_format(text_format_t::TF_YAML) .with_role(role_t::VCR_NUMBER); + hm[{highlight_source_t::INTERNAL, "fun"}] + = highlighter(xpcre_compile(R"((\w+)\()")) + .with_nestable(false) + .with_text_format(text_format_t::TF_C_LIKE) + .with_text_format(text_format_t::TF_JAVA) + .with_text_format(text_format_t::TF_PYTHON) + .with_text_format(text_format_t::TF_RUST) + .with_text_format(text_format_t::TF_SQL) + .with_role(role_t::VCR_FUNCTION); + hm[{highlight_source_t::INTERNAL, "sep"}] + = highlighter(xpcre_compile(R"(\.|\s+&(?=\w)|(?<=\w)&\s+|::|\%\b)")) + .with_nestable(false) + .with_text_format(text_format_t::TF_C_LIKE) + .with_text_format(text_format_t::TF_JAVA) + .with_text_format(text_format_t::TF_PYTHON) + .with_text_format(text_format_t::TF_RUST) + .with_text_format(text_format_t::TF_SQL) + .with_role(role_t::VCR_SEP_REF_ACC); + hm[{highlight_source_t::INTERNAL, "type"}] + = highlighter( + xpcre_compile( + R"(\b(class|struct|enum(?:\s+class)?)\s+(\w+)\b|\b(\w+_t)\b)")) + .with_nestable(false) + .with_text_format(text_format_t::TF_C_LIKE) + .with_text_format(text_format_t::TF_JAVA) + .with_text_format(text_format_t::TF_PYTHON) + .with_text_format(text_format_t::TF_RUST) + .with_text_format(text_format_t::TF_SQL) + .with_role(role_t::VCR_TYPE); } |