Skip to content

Commit

Permalink
SCSS: add module parser-specific field
Browse files Browse the repository at this point in the history
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed Jan 2, 2025
1 parent f7a7c87 commit 4a62955
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
8 changes: 4 additions & 4 deletions Units/parser-scss.r/use.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
X/y input.scss /^@use "X\/y";$/;" M roles:used
y input.scss /^@use "X\/y";$/;" n roles:def
y input.scss /^@use "X\/y";$/;" n roles:def module:X/y
Z input.scss /^@use "Z";$/;" M roles:used
Z input.scss /^@use "Z";$/;" n roles:def
Z input.scss /^@use "Z";$/;" n roles:def module:Z
A input.scss /^@use "A" as NS;$/;" M roles:used
NS input.scss /^@use "A" as NS;$/;" n roles:def
NS input.scss /^@use "A" as NS;$/;" n roles:def module:A
B/ input.scss /^@use "B\/";$/;" M roles:used
C/d/e input.scss /^@use 'C\/d\/e';$/;" M roles:used
e input.scss /^@use 'C\/d\/e';$/;" n roles:def
e input.scss /^@use 'C\/d\/e';$/;" n roles:def module:C/d/e
P/q input.scss /^@use 'P\/q' as *;$/;" M roles:used
1 change: 1 addition & 0 deletions docs/man/ctags-lang-scss.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Change since "0.0"

* New kind ``module`` and new role ``used`` of the ``module`` kind
* New kind ``namespace``
* New field ``module``

SEE ALSO
--------
Expand Down
1 change: 1 addition & 0 deletions man/ctags-lang-scss.7.rst.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Change since "0.0"

* New kind ``module`` and new role ``used`` of the ``module`` kind
* New kind ``namespace``
* New field ``module``

SEE ALSO
--------
Expand Down
18 changes: 15 additions & 3 deletions optlib/scss.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ static void initializeSCSSParser (const langType language)
" % module-name offset' count namespace-string\n"
" _copyinterval\n"
" dup length 0 gt {\n"
" /namespace @1 _tag _commit pop\n"
" /namespace @1 _tag _commit \\1 SCSS.module:\n"
" } {\n"
" clear\n"
" } ifelse\n"
" } {\n"
" % Extract the module name as a namespace.\n"
" \\1 /namespace @1 _tag _commit pop\n"
" \\1 /namespace @1 _tag _commit \\1 SCSS.module:\n"
" } ifelse\n"
" } {\n"
" % \"as *\" doesn't make a namespace.\n"
" \\3 (*) ne {\n"
" \\3 /namespace @3 _tag _commit pop\n"
" \\3 /namespace @3 _tag _commit \\1 SCSS.module:\n"
" } if\n"
" } ifelse\n"
"}}", NULL);
Expand Down Expand Up @@ -233,6 +233,16 @@ extern parserDefinition* SCSSParser (void)
ATTACH_ROLES(SCSSModuleRoleTable),
},
};
static fieldDefinition SCSSFieldTable [] = {
{
.enabled = true,
.name = "module",
.description = "the name of module behind the namespace",
.dataType = FIELDTYPE_SCRIPTABLE|FIELDTYPE_STRING,
.getValueObject = getFieldValueGeneric,
.setValueObject = setFieldValueGeneric,
},
};

parserDefinition* const def = parserNew ("SCSS");

Expand All @@ -246,6 +256,8 @@ extern parserDefinition* SCSSParser (void)
def->useCork = CORK_QUEUE;
def->kindTable = SCSSKindTable;
def->kindCount = ARRAY_SIZE(SCSSKindTable);
def->fieldTable = SCSSFieldTable;
def->fieldCount = ARRAY_SIZE(SCSSFieldTable);
def->initialize = initializeSCSSParser;

return def;
Expand Down
9 changes: 6 additions & 3 deletions optlib/scss.ctags
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
--kinddef-SCSS=M,module,modules
--_roledef-SCSS.{module}=used,used

--_fielddef-SCSS=module,the name of module behind the namespace{datatype=str}
--fields-SCSS=+{module}

--_tabledef-SCSS=toplevel
--_tabledef-SCSS=comment
--_tabledef-SCSS=interp
Expand Down Expand Up @@ -69,18 +72,18 @@
% module-name offset' count namespace-string
_copyinterval
dup length 0 gt {
/namespace @1 _tag _commit pop
/namespace @1 _tag _commit \1 SCSS.module:
} {
clear
} ifelse
} {
% Extract the module name as a namespace.
\1 /namespace @1 _tag _commit pop
\1 /namespace @1 _tag _commit \1 SCSS.module:
} ifelse
} {
% "as *" doesn't make a namespace.
\3 (*) ne {
\3 /namespace @3 _tag _commit pop
\3 /namespace @3 _tag _commit \1 SCSS.module:
} if
} ifelse
}}
Expand Down

0 comments on commit 4a62955

Please sign in to comment.