Skip to content

Commit

Permalink
Merge pull request #4168 from masatake/scss--use
Browse files Browse the repository at this point in the history
SCSS: extract modules and namespaces from @use "..."
  • Loading branch information
masatake authored Jan 2, 2025
2 parents 81c2ca6 + a2bf630 commit 1ef6496
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Tmain/list-roles.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Units/parser-scss.r/use.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--sort=no
--extras=+r
--fields=+r
7 changes: 7 additions & 0 deletions Units/parser-scss.r/use.d/expected.tags
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions Units/parser-scss.r/use.d/input.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@use "X/y";
@use "Z";
@use "A" as NS;
@use "B/";
1 change: 1 addition & 0 deletions docs/man-pages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Man pages
ctags-lang-python(7) <man/ctags-lang-python.7.rst>
ctags-lang-r(7) <man/ctags-lang-r.7.rst>
ctags-lang-rmarkdown(7) <man/ctags-lang-rmarkdown.7.rst>
ctags-lang-scss(7) <man/ctags-lang-scss.7.rst>
ctags-lang-sql(7) <man/ctags-lang-sql.7.rst>
ctags-lang-systemtap(7) <man/ctags-lang-systemtap.7.rst>
ctags-lang-tcl(7) <man/ctags-lang-tcl.7.rst>
Expand Down
34 changes: 34 additions & 0 deletions docs/man/ctags-lang-scss.7.rst
Original file line number Diff line number Diff line change
@@ -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) <ctags(1)>`
1 change: 1 addition & 0 deletions man/GNUmakefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
34 changes: 34 additions & 0 deletions man/ctags-lang-scss.7.rst.in
Original file line number Diff line number Diff line change
@@ -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)
41 changes: 39 additions & 2 deletions optlib/scss.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -171,6 +197,9 @@ extern parserDefinition* SCSSParser (void)
NULL
};

static roleDefinition SCSSModuleRoleTable [] = {
{ true, "used", "used" },
};
static kindDefinition SCSSKindTable [] = {
{
true, 'm', "mixin", "mixins",
Expand All @@ -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;
Expand Down
28 changes: 27 additions & 1 deletion optlib/scss.ctags
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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//
Expand Down

0 comments on commit 1ef6496

Please sign in to comment.