Skip to content

Commit

Permalink
JavaScript: added foreigndecl role
Browse files Browse the repository at this point in the history
  • Loading branch information
edam authored and masatake committed Dec 11, 2023
1 parent 6878f6d commit a63485f
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 15 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 @@ -64,6 +64,7 @@ HTML J/script extFile on referenced as extern
HTML c/class attribute on assigned as attributes
Java p/package imported on imported package
JavaScript c/class chainElt off (EXPERIMENTAL)used as an element in a name chain like a.b.c
JavaScript f/function foreigndecl on declared in foreign languages
JavaScript v/variable chainElt off (EXPERIMENTAL)used as an element in a name chain like a.b.c
Julia Y/unknown imported on loaded by "import"
Julia Y/unknown used on loaded by "using"
Expand Down Expand Up @@ -192,6 +193,7 @@ HTML J/script extFile on referenced as extern
HTML c/class attribute on assigned as attributes
Java p/package imported on imported package
JavaScript c/class chainElt off (EXPERIMENTAL)used as an element in a name chain like a.b.c
JavaScript f/function foreigndecl on declared in foreign languages
JavaScript v/variable chainElt off (EXPERIMENTAL)used as an element in a name chain like a.b.c
Julia Y/unknown imported on loaded by "import"
Julia Y/unknown used on loaded by "using"
Expand Down
5 changes: 5 additions & 0 deletions docs/man/ctags-lang-javascript.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ CLASSES

ES6 introduced the ``class`` keyword, but there is still the original method of defining a function and attaching a ``prototype``. ctags follows the convention that function names that start with a capital letter are class constructors.

Change since "0.0"
~~~~~~~~~~~~~~~~~~

* New role ``foreigndecl`` for ``function`` kind

SEE ALSO
--------
:ref:`ctags(1) <ctags(1)>`, :ref:`ctags-client-tools(7) <ctags-client-tools(7)>`
2 changes: 2 additions & 0 deletions makefiles/testing.mak
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ validate-input:
--categories=$(CATEGORIES) \
$${VALIDATORS}"; \
$(SHELL) $${c} $(srcdir)/Units $(srcdir)/misc/validators

#
# Test main part, not parsers
#
Expand Down Expand Up @@ -292,6 +293,7 @@ CPPCHECK_FLAGS = --enable=all
cppcheck:
cppcheck $(CPPCHECK_DEFS) $(CPPCHECK_UNDEFS) $(CPPCHECK_FLAGS) \
$$(git ls-files | grep '^\(parsers\|main\)/.*\.[ch]' )

#
# Testing examples in per-language man pages
#
Expand Down
5 changes: 5 additions & 0 deletions man/ctags-lang-javascript.7.rst.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ CLASSES

ES6 introduced the ``class`` keyword, but there is still the original method of defining a function and attaching a ``prototype``. ctags follows the convention that function names that start with a capital letter are class constructors.

Change since "0.0"
~~~~~~~~~~~~~~~~~~

* New role ``foreigndecl`` for ``function`` kind

SEE ALSO
--------
ctags(1), ctags-client-tools(7)
27 changes: 12 additions & 15 deletions parsers/jscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
#include "mbcs.h"
#include "trace.h"

#include "jscript.h"

/*
* MACROS
*/
Expand Down Expand Up @@ -150,20 +152,6 @@ static objPool *TokenPool = NULL;
static iconv_t JSUnicodeConverter = (iconv_t) -2;
#endif

typedef enum {
JSTAG_FUNCTION,
JSTAG_CLASS,
JSTAG_METHOD,
JSTAG_PROPERTY,
JSTAG_CONSTANT,
JSTAG_VARIABLE,
JSTAG_GENERATOR,
JSTAG_GETTER,
JSTAG_SETTER,
JSTAG_FIELD,
JSTAG_COUNT
} jsKind;

/*
* "chain element" role is introduced when adapting the JavaScript parser
* to corkAPI.
Expand Down Expand Up @@ -255,6 +243,11 @@ typedef enum {
JS_CLASS_CHAINELT,
} jsClassRole;

static roleDefinition JsFunctionRoles [] = {
/* Currently V parser wants this items. */
{ true, "foreigndecl", "declared in foreign languages" },
};

static roleDefinition JsVariableRoles [] = {
{ false, "chainElt", "(EXPERIMENTAL)used as an element in a name chain like a.b.c" },
};
Expand All @@ -264,7 +257,8 @@ static roleDefinition JsClassRoles [] = {
};

static kindDefinition JsKinds [] = {
{ true, 'f', "function", "functions" },
{ true, 'f', "function", "functions",
.referenceOnly = false, ATTACH_ROLES(JsFunctionRoles) },
{ true, 'c', "class", "classes",
.referenceOnly = false, ATTACH_ROLES(JsClassRoles) },
{ true, 'm', "method", "methods" },
Expand Down Expand Up @@ -3324,5 +3318,8 @@ extern parserDefinition* JavaScriptParser (void)
def->useCork = CORK_QUEUE|CORK_SYMTAB;
def->requestAutomaticFQTag = true;

def->versionCurrent = 1;
def->versionAge = 1;

return def;
}
32 changes: 32 additions & 0 deletions parsers/jscript.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2003, Darren Hiebert
*
* This source code is released for free distribution under the terms of the
* GNU General Public License version 2 or (at your option) any later version.
*
* This module contains functions for generating tags for JavaScript language
* files.
*/

#ifndef CTAGS_JSCRIPT_H
#define CTAGS_JSCRIPT_H

typedef enum {
JSTAG_FUNCTION,
JSTAG_CLASS,
JSTAG_METHOD,
JSTAG_PROPERTY,
JSTAG_CONSTANT,
JSTAG_VARIABLE,
JSTAG_GENERATOR,
JSTAG_GETTER,
JSTAG_SETTER,
JSTAG_FIELD,
JSTAG_COUNT
} jsKind;

typedef enum {
JSTAG_FUNCTIONRoleFOREIGNDECL
} JSTAGFunctionRole;

#endif
1 change: 1 addition & 0 deletions source.mak
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ PARSER_HEADS = \
parsers/bibtex.h \
parsers/frontmatter.h \
parsers/iniconf.h \
parsers/jscript.h \
parsers/m4.h \
parsers/make.h \
parsers/markdown.h \
Expand Down
1 change: 1 addition & 0 deletions win32/ctags_vs2013.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@
<ClInclude Include="..\parsers\cxx\cxx_token_chain.h" />
<ClInclude Include="..\parsers\frontmatter.h" />
<ClInclude Include="..\parsers\iniconf.h" />
<ClInclude Include="..\parsers\jscript.h" />
<ClInclude Include="..\parsers\m4.h" />
<ClInclude Include="..\parsers\make.h" />
<ClInclude Include="..\parsers\markdown.h" />
Expand Down
3 changes: 3 additions & 0 deletions win32/ctags_vs2013.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,9 @@
<ClInclude Include="..\parsers\iniconf.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\parsers\jscript.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\parsers\m4.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down

0 comments on commit a63485f

Please sign in to comment.