From a2bf630368ac1cfbd4e71018714850ae5f25e792 Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Thu, 2 Jan 2025 05:32:50 +0900 Subject: [PATCH] SCSS: extract modules and namespaces from @use "..." Signed-off-by: Masatake YAMATO --- Tmain/list-roles.d/stdout-expected.txt | 2 ++ Units/parser-scss.r/use.d/args.ctags | 3 ++ Units/parser-scss.r/use.d/expected.tags | 7 +++++ Units/parser-scss.r/use.d/input.scss | 4 +++ docs/man-pages.rst | 1 + docs/man/ctags-lang-scss.7.rst | 34 ++++++++++++++++++++ man/GNUmakefile.am | 1 + man/ctags-lang-scss.7.rst.in | 34 ++++++++++++++++++++ optlib/scss.c | 41 +++++++++++++++++++++++-- optlib/scss.ctags | 28 ++++++++++++++++- 10 files changed, 152 insertions(+), 3 deletions(-) create mode 100644 Units/parser-scss.r/use.d/args.ctags create mode 100644 Units/parser-scss.r/use.d/expected.tags create mode 100644 Units/parser-scss.r/use.d/input.scss create mode 100644 docs/man/ctags-lang-scss.7.rst create mode 100644 man/ctags-lang-scss.7.rst.in diff --git a/Tmain/list-roles.d/stdout-expected.txt b/Tmain/list-roles.d/stdout-expected.txt index 6dfc210c6c..0dab3c853e 100644 --- a/Tmain/list-roles.d/stdout-expected.txt +++ b/Tmain/list-roles.d/stdout-expected.txt @@ -111,6 +111,7 @@ RpmSpec p/patch decl on declared for applyin Ruby L/library loaded on loaded by "load" method Ruby L/library required on loaded by "require" method Ruby L/library requiredRel on loaded by "require_relative" method +SCSS M/module used on used Sh h/heredoc endmarker on end marker Sh s/script loaded on loaded SystemTap p/probe attached on attached by code for probing @@ -255,6 +256,7 @@ RpmSpec p/patch decl on declared for applyin Ruby L/library loaded on loaded by "load" method Ruby L/library required on loaded by "require" method Ruby L/library requiredRel on loaded by "require_relative" method +SCSS M/module used on used Sh h/heredoc endmarker on end marker Sh s/script loaded on loaded SystemTap p/probe attached on attached by code for probing diff --git a/Units/parser-scss.r/use.d/args.ctags b/Units/parser-scss.r/use.d/args.ctags new file mode 100644 index 0000000000..41f6dbed62 --- /dev/null +++ b/Units/parser-scss.r/use.d/args.ctags @@ -0,0 +1,3 @@ +--sort=no +--extras=+r +--fields=+r diff --git a/Units/parser-scss.r/use.d/expected.tags b/Units/parser-scss.r/use.d/expected.tags new file mode 100644 index 0000000000..e99ecbcff6 --- /dev/null +++ b/Units/parser-scss.r/use.d/expected.tags @@ -0,0 +1,7 @@ +X/y input.scss /^@use "X\/y";$/;" M roles:used +y input.scss /^@use "X\/y";$/;" n roles:def +Z input.scss /^@use "Z";$/;" M roles:used +Z input.scss /^@use "Z";$/;" n roles:def +A input.scss /^@use "A" as NS;$/;" M roles:used +NS input.scss /^@use "A" as NS;$/;" n roles:def +B/ input.scss /^@use "B\/";$/;" M roles:used diff --git a/Units/parser-scss.r/use.d/input.scss b/Units/parser-scss.r/use.d/input.scss new file mode 100644 index 0000000000..0a5a30e782 --- /dev/null +++ b/Units/parser-scss.r/use.d/input.scss @@ -0,0 +1,4 @@ +@use "X/y"; +@use "Z"; +@use "A" as NS; +@use "B/"; diff --git a/docs/man-pages.rst b/docs/man-pages.rst index f447883654..21d4905db3 100644 --- a/docs/man-pages.rst +++ b/docs/man-pages.rst @@ -41,6 +41,7 @@ Man pages ctags-lang-python(7) ctags-lang-r(7) ctags-lang-rmarkdown(7) + ctags-lang-scss(7) ctags-lang-sql(7) ctags-lang-systemtap(7) ctags-lang-tcl(7) diff --git a/docs/man/ctags-lang-scss.7.rst b/docs/man/ctags-lang-scss.7.rst new file mode 100644 index 0000000000..a415409764 --- /dev/null +++ b/docs/man/ctags-lang-scss.7.rst @@ -0,0 +1,34 @@ +.. _ctags-lang-scss(7): + +============================================================== +ctags-lang-scss +============================================================== + +Random notes about tagging SCSS source code with Universal Ctags + +:Version: 6.1.0 +:Manual group: Universal Ctags +:Manual section: 7 + +SYNOPSIS +-------- +| **ctags** ... --languages=+SCSS ... +| **ctags** ... --language-force=SCSS ... +| **ctags** ... --map-Scss=+.scss ... + +DESCRIPTION +----------- +This man page gathers random notes about tagging SCSS input. + +VERSIONS +-------- + +Change since "0.0" +~~~~~~~~~~~~~~~~~~ + +* New kind ``module`` and new role ``used`` of the ``module`` kind +* New kind ``namespace`` + +SEE ALSO +-------- +:ref:`ctags(1) ` diff --git a/man/GNUmakefile.am b/man/GNUmakefile.am index 115c083e2d..d04b64dfbc 100644 --- a/man/GNUmakefile.am +++ b/man/GNUmakefile.am @@ -52,6 +52,7 @@ GEN_IN_MAN_FILES = \ ctags-lang-python.7 \ ctags-lang-r.7 \ ctags-lang-rmarkdown.7 \ + ctags-lang-scss.7 \ ctags-lang-sql.7 \ ctags-lang-systemtap.7 \ ctags-lang-tcl.7 \ diff --git a/man/ctags-lang-scss.7.rst.in b/man/ctags-lang-scss.7.rst.in new file mode 100644 index 0000000000..7c446ef9b9 --- /dev/null +++ b/man/ctags-lang-scss.7.rst.in @@ -0,0 +1,34 @@ +.. _ctags-lang-scss(7): + +============================================================== +ctags-lang-scss +============================================================== +--------------------------------------------------------------------- +Random notes about tagging SCSS source code with Universal Ctags +--------------------------------------------------------------------- +:Version: @VERSION@ +:Manual group: Universal Ctags +:Manual section: 7 + +SYNOPSIS +-------- +| **@CTAGS_NAME_EXECUTABLE@** ... --languages=+SCSS ... +| **@CTAGS_NAME_EXECUTABLE@** ... --language-force=SCSS ... +| **@CTAGS_NAME_EXECUTABLE@** ... --map-Scss=+.scss ... + +DESCRIPTION +----------- +This man page gathers random notes about tagging SCSS input. + +VERSIONS +-------- + +Change since "0.0" +~~~~~~~~~~~~~~~~~~ + +* New kind ``module`` and new role ``used`` of the ``module`` kind +* New kind ``namespace`` + +SEE ALSO +-------- +ctags(1) diff --git a/optlib/scss.c b/optlib/scss.c index 47c32cf574..7e8b7ef709 100644 --- a/optlib/scss.c +++ b/optlib/scss.c @@ -49,6 +49,32 @@ static void initializeSCSSParser (const langType language) addLanguageTagMultiTableRegex (language, "toplevel", "^@for[ \t]+\\$([A-Za-z0-9_-]+)[ \t]from[ \t]+.*[ \t]+(to|through)[ \t]+[^{]+", "\\1", "v", "", NULL); + addLanguageTagMultiTableRegex (language, "toplevel", + "^@use[ \t]+\"([^\"]+)\"([ \t]+as[ \t]+([A-Za-z0-9_-]+))?", + "\\1", "M", "{_role=used}" + "{{\n" + " \\2 false eq {\n" + " \\1 (/) _strrstr {\n" + " % Extract the last component in the module name:\n" + " % module-name offset\n" + " 1 add dup \\1 length exch sub\n" + " % module-name offset' count\n" + " 0 string\n" + " % module-name offset' count namespace-string\n" + " _copyinterval\n" + " dup length 0 gt {\n" + " /namespace @1 _tag _commit pop\n" + " } {\n" + " clear\n" + " } ifelse\n" + " } {\n" + " % Extract the module name as a namespace.\n" + " \\1 /namespace @1 _tag _commit pop\n" + " } ifelse\n" + " } {\n" + " \\3 /namespace @3 _tag _commit pop\n" + " } ifelse\n" + "}}", NULL); addLanguageTagMultiTableRegex (language, "toplevel", "^@[^\n]+\n?", "", "", "", NULL); @@ -171,6 +197,9 @@ extern parserDefinition* SCSSParser (void) NULL }; + static roleDefinition SCSSModuleRoleTable [] = { + { true, "used", "used" }, + }; static kindDefinition SCSSKindTable [] = { { true, 'm', "mixin", "mixins", @@ -193,17 +222,25 @@ extern parserDefinition* SCSSParser (void) { true, 'z', "parameter", "function parameters", }, + { + true, 'n', "namespace", "namespaces", + }, + { + true, 'M', "module", "modules", + ATTACH_ROLES(SCSSModuleRoleTable), + }, }; parserDefinition* const def = parserNew ("SCSS"); - def->versionCurrent= 0; - def->versionAge = 0; + def->versionCurrent= 1; + def->versionAge = 1; def->enabled = true; def->extensions = extensions; def->patterns = patterns; def->aliases = aliases; def->method = METHOD_NOT_CRAFTED|METHOD_REGEX; + def->useCork = CORK_QUEUE; def->kindTable = SCSSKindTable; def->kindCount = ARRAY_SIZE(SCSSKindTable); def->initialize = initializeSCSSParser; diff --git a/optlib/scss.ctags b/optlib/scss.ctags index 3ba416eb79..1b68cdb04f 100644 --- a/optlib/scss.ctags +++ b/optlib/scss.ctags @@ -21,7 +21,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # ---langdef=SCSS +--langdef=SCSS{version=1.1} --map-SCSS=+.scss --kinddef-SCSS=m,mixin,mixins @@ -32,6 +32,9 @@ --kinddef-SCSS=i,id,identities # --kinddef-SCSS=p,pseudo,pseudos --kinddef-SCSS=z,parameter,function parameters +--kinddef-SCSS=n,namespace,namespaces +--kinddef-SCSS=M,module,modules +--_roledef-SCSS.{module}=used,used --_tabledef-SCSS=toplevel --_tabledef-SCSS=comment @@ -51,6 +54,29 @@ --_mtable-regex-SCSS=toplevel/@function[ \t]+([A-Za-z0-9_-]+)/\1/f/{tenter=args} --_mtable-regex-SCSS=toplevel/@each[ \t]+\$([A-Za-z0-9_-]+)[ \t]in[ \t]+/\1/v/ --_mtable-regex-SCSS=toplevel/@for[ \t]+\$([A-Za-z0-9_-]+)[ \t]from[ \t]+.*[ \t]+(to|through)[ \t]+[^{]+/\1/v/ +--_mtable-regex-SCSS=toplevel/@use[ \t]+"([^"]+)"([ \t]+as[ \t]+([A-Za-z0-9_-]+))?/\1/M/{_role=used}{{ + \2 false eq { + \1 (/) _strrstr { + % Extract the last component in the module name: + % module-name offset + 1 add dup \1 length exch sub + % module-name offset' count + 0 string + % module-name offset' count namespace-string + _copyinterval + dup length 0 gt { + /namespace @1 _tag _commit pop + } { + clear + } ifelse + } { + % Extract the module name as a namespace. + \1 /namespace @1 _tag _commit pop + } ifelse + } { + \3 /namespace @3 _tag _commit pop + } ifelse +}} --_mtable-regex-SCSS=toplevel/@[^\n]+\n?// --_mtable-regex-SCSS=toplevel/:[^{;]+;\n?// --_mtable-regex-SCSS=toplevel/:[^\n;{]+\n//