From 66c62e0bc6646c71abf0d5b144652ec5e1d06597 Mon Sep 17 00:00:00 2001 From: Hadriel Kaplan Date: Sat, 11 Aug 2018 14:40:43 -0400 Subject: [PATCH] Fix cmake.ctags optlib to use _advanceTo properly --- .../cmake-comments.d/expected.tags | 2 +- .../cmake-comments.d/input.cmake | 4 +- optlib/cmake.c | 37 +++++++++++++------ optlib/cmake.ctags | 29 ++++++++++----- 4 files changed, 48 insertions(+), 24 deletions(-) diff --git a/Units/parser-cmake.r/cmake-comments.d/expected.tags b/Units/parser-cmake.r/cmake-comments.d/expected.tags index 4dd2b76388..98726ff297 100644 --- a/Units/parser-cmake.r/cmake-comments.d/expected.tags +++ b/Units/parser-cmake.r/cmake-comments.d/expected.tags @@ -1,3 +1,3 @@ another_good_target input.cmake /^add_library(another_good_target# <-- target$/;" t -good_target input.cmake /^ good_target# this is legal comment placement I think$/;" t +good_target input.cmake /^ good_target# this is legal comment placement set(NO_TAG foo)$/;" t tag_this input.cmake /^]]set(tag_this)$/;" v diff --git a/Units/parser-cmake.r/cmake-comments.d/input.cmake b/Units/parser-cmake.r/cmake-comments.d/input.cmake index 3cbd2c99b7..e10a1642c1 100644 --- a/Units/parser-cmake.r/cmake-comments.d/input.cmake +++ b/Units/parser-cmake.r/cmake-comments.d/input.cmake @@ -8,10 +8,10 @@ option(DO_NOT_TAG "foo" OFF) add_custom_target(# comment set(NO_TAG "foo") # anothe rline comment - good_target# this is legal comment placement I think + good_target# this is legal comment placement set(NO_TAG foo) ALL) add_library(another_good_target# <-- target - SHARED # <-- lib type + SHARED # set(NO_TAG bar) gmock-all.cc ) diff --git a/optlib/cmake.c b/optlib/cmake.c index 513510c0f4..b6b553dfee 100644 --- a/optlib/cmake.c +++ b/optlib/cmake.c @@ -54,53 +54,68 @@ static void initializeCMakeParser (const langType language CTAGS_ATTR_UNUSED) "^[ \t\n]+", "", "", "", NULL); addLanguageTagMultiTableRegex (language, "variable", - "^([A-Za-z0-9_.-]+)([# \t\n\\)])", - "\\1", "v", "{tleave}{advanceTo=2start}", NULL); + "^([A-Za-z0-9_.-]+)[ \t\n\\)]+", + "\\1", "v", "{tleave}", NULL); addLanguageTagMultiTableRegex (language, "variable", "^[ \t\n]+", "", "", "", NULL); addLanguageTagMultiTableRegex (language, "variable", "^#", "", "", "{tenter=commentBegin}", NULL); + addLanguageTagMultiTableRegex (language, "variable", + "^([A-Za-z0-9_.-]+)(#)", + "\\1", "v", "{tleave}{_advanceTo=2start}", NULL); addLanguageTagMultiTableRegex (language, "function", - "^([A-Za-z_][A-Za-z0-9_]*)([# \t\n\\)])", - "\\1", "f", "{tleave}{advanceTo=2start}", NULL); + "^([A-Za-z_][A-Za-z0-9_]*)[ \t\n\\)]+", + "\\1", "f", "{tleave}", NULL); addLanguageTagMultiTableRegex (language, "function", "^[ \t\n]+", "", "", "", NULL); addLanguageTagMultiTableRegex (language, "function", "^#", "", "", "{tenter=commentBegin}", NULL); + addLanguageTagMultiTableRegex (language, "function", + "^([A-Za-z_][A-Za-z0-9_]*)(#)", + "\\1", "f", "{tleave}{_advanceTo=2start}", NULL); addLanguageTagMultiTableRegex (language, "macro", - "^([A-Za-z_][A-Za-z0-9_]*)([# \t\n\\)])", - "\\1", "m", "{tleave}{advanceTo=2start}", NULL); + "^([A-Za-z_][A-Za-z0-9_]*)[ \t\n\\)]+", + "\\1", "m", "{tleave}", NULL); addLanguageTagMultiTableRegex (language, "macro", "^[ \t\n]+", "", "", "", NULL); addLanguageTagMultiTableRegex (language, "macro", "^#", "", "", "{tenter=commentBegin}", NULL); + addLanguageTagMultiTableRegex (language, "macro", + "^([A-Za-z_][A-Za-z0-9_]*)(#)", + "\\1", "m", "{tleave}{_advanceTo=2start}", NULL); addLanguageTagMultiTableRegex (language, "target", - "^([A-Za-z0-9_.-]+)([# \t\n\\)])", - "\\1", "t", "{tleave}{advanceTo=2start}", NULL); + "^([A-Za-z0-9_.-]+)[ \t\n\\)]+", + "\\1", "t", "{tleave}", NULL); addLanguageTagMultiTableRegex (language, "target", "^[ \t\n]+", "", "", "", NULL); addLanguageTagMultiTableRegex (language, "target", "^#", "", "", "{tenter=commentBegin}", NULL); + addLanguageTagMultiTableRegex (language, "target", + "^([A-Za-z0-9_.-]+)(#)", + "\\1", "t", "{tleave}{_advanceTo=2start}", NULL); addLanguageTagMultiTableRegex (language, "option", - "^([A-Za-z0-9_.-]+)([# \t\n\\)])", - "\\1", "D", "{tleave}{advanceTo=2start}", NULL); + "^([A-Za-z0-9_.-]+)[ \t\n\\)]+", + "\\1", "D", "{tleave}", NULL); addLanguageTagMultiTableRegex (language, "option", "^[ \t\n]+", "", "", "", NULL); addLanguageTagMultiTableRegex (language, "option", "^#", "", "", "{tenter=commentBegin}", NULL); + addLanguageTagMultiTableRegex (language, "option", + "^([A-Za-z0-9_.-]+)(#)", + "\\1", "D", "{tleave}{_advanceTo=2start}", NULL); addLanguageTagMultiTableRegex (language, "project", "^([A-Za-z0-9_.-]+)([# \t\n\\)])", - "\\1", "p", "{tleave}{advanceTo=2start}", NULL); + "\\1", "p", "{tleave}{_advanceTo=2start}", NULL); addLanguageTagMultiTableRegex (language, "project", "^[ \t\n]+", "", "", "", NULL); diff --git a/optlib/cmake.ctags b/optlib/cmake.ctags index 86db657569..7d7414cc95 100644 --- a/optlib/cmake.ctags +++ b/optlib/cmake.ctags @@ -115,44 +115,53 @@ # # Each of the following basically work the same way, and only differ in the # exact pattern allowed to be their name, and the Kind they add. Note that they -# capture a required trailing '[# \t\n\)]', to verify the full name token matched -# the name's pattern, but then we advanceTo=2start for the next round, so that -# we don't go past a potential '#' comment token but instead match it again in -# the main table as a comment (or whitespace if it was whitespace). +# capture a required trailing '[ \t\n\)]' or '#', to verify the full name token +# matched the name's pattern, but then we advanceTo=2start for the next round, +# so that we don't go past a potential '#' comment token but instead match it +# again in the main table as a comment. The odds of a comment '#' immediately +# following the name is very low, so we split it into its own check and do it +# last in each table - this improves real-world performance ~10%, because in +# the common case we can capture the whitespace at the same time as the name, +# and not have to skip it again in the 'main' table. # # # variable # ---_mtable-regex-CMake=variable/([A-Za-z0-9_.-]+)([# \t\n\)])/\1/v/{tleave}{advanceTo=2start} +--_mtable-regex-CMake=variable/([A-Za-z0-9_.-]+)[ \t\n\)]+/\1/v/{tleave} --_mtable-extend-CMake=variable+skipToName +--_mtable-regex-CMake=variable/([A-Za-z0-9_.-]+)(#)/\1/v/{tleave}{_advanceTo=2start} # # function # ---_mtable-regex-CMake=function/([A-Za-z_][A-Za-z0-9_]*)([# \t\n\)])/\1/f/{tleave}{advanceTo=2start} +--_mtable-regex-CMake=function/([A-Za-z_][A-Za-z0-9_]*)[ \t\n\)]+/\1/f/{tleave} --_mtable-extend-CMake=function+skipToName +--_mtable-regex-CMake=function/([A-Za-z_][A-Za-z0-9_]*)(#)/\1/f/{tleave}{_advanceTo=2start} # # macro # ---_mtable-regex-CMake=macro/([A-Za-z_][A-Za-z0-9_]*)([# \t\n\)])/\1/m/{tleave}{advanceTo=2start} +--_mtable-regex-CMake=macro/([A-Za-z_][A-Za-z0-9_]*)[ \t\n\)]+/\1/m/{tleave} --_mtable-extend-CMake=macro+skipToName +--_mtable-regex-CMake=macro/([A-Za-z_][A-Za-z0-9_]*)(#)/\1/m/{tleave}{_advanceTo=2start} # # target # ---_mtable-regex-CMake=target/([A-Za-z0-9_.-]+)([# \t\n\)])/\1/t/{tleave}{advanceTo=2start} +--_mtable-regex-CMake=target/([A-Za-z0-9_.-]+)[ \t\n\)]+/\1/t/{tleave} --_mtable-extend-CMake=target+skipToName +--_mtable-regex-CMake=target/([A-Za-z0-9_.-]+)(#)/\1/t/{tleave}{_advanceTo=2start} # # option # ---_mtable-regex-CMake=option/([A-Za-z0-9_.-]+)([# \t\n\)])/\1/D/{tleave}{advanceTo=2start} +--_mtable-regex-CMake=option/([A-Za-z0-9_.-]+)[ \t\n\)]+/\1/D/{tleave} --_mtable-extend-CMake=option+skipToName +--_mtable-regex-CMake=option/([A-Za-z0-9_.-]+)(#)/\1/D/{tleave}{_advanceTo=2start} # # project # ---_mtable-regex-CMake=project/([A-Za-z0-9_.-]+)([# \t\n\)])/\1/p/{tleave}{advanceTo=2start} +--_mtable-regex-CMake=project/([A-Za-z0-9_.-]+)([# \t\n\)])/\1/p/{tleave}{_advanceTo=2start} --_mtable-extend-CMake=project+skipToName