From a63485f93547577cea7325f57ba696eaa890bf0d Mon Sep 17 00:00:00 2001 From: Tim Marston Date: Sun, 10 Dec 2023 08:25:38 +0000 Subject: [PATCH] JavaScript: added foreigndecl role --- Tmain/list-roles.d/stdout-expected.txt | 2 ++ docs/man/ctags-lang-javascript.7.rst | 5 ++++ makefiles/testing.mak | 2 ++ man/ctags-lang-javascript.7.rst.in | 5 ++++ parsers/jscript.c | 27 ++++++++++------------ parsers/jscript.h | 32 ++++++++++++++++++++++++++ source.mak | 1 + win32/ctags_vs2013.vcxproj | 1 + win32/ctags_vs2013.vcxproj.filters | 3 +++ 9 files changed, 63 insertions(+), 15 deletions(-) create mode 100644 parsers/jscript.h diff --git a/Tmain/list-roles.d/stdout-expected.txt b/Tmain/list-roles.d/stdout-expected.txt index c84af2f1d3..a94103c619 100644 --- a/Tmain/list-roles.d/stdout-expected.txt +++ b/Tmain/list-roles.d/stdout-expected.txt @@ -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" @@ -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" diff --git a/docs/man/ctags-lang-javascript.7.rst b/docs/man/ctags-lang-javascript.7.rst index 8da9482550..032d62a5ff 100644 --- a/docs/man/ctags-lang-javascript.7.rst +++ b/docs/man/ctags-lang-javascript.7.rst @@ -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) `, :ref:`ctags-client-tools(7) ` diff --git a/makefiles/testing.mak b/makefiles/testing.mak index 614b3c9b91..e3714a8f46 100644 --- a/makefiles/testing.mak +++ b/makefiles/testing.mak @@ -173,6 +173,7 @@ validate-input: --categories=$(CATEGORIES) \ $${VALIDATORS}"; \ $(SHELL) $${c} $(srcdir)/Units $(srcdir)/misc/validators + # # Test main part, not parsers # @@ -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 # diff --git a/man/ctags-lang-javascript.7.rst.in b/man/ctags-lang-javascript.7.rst.in index 69493ef90e..22e9bb48e1 100644 --- a/man/ctags-lang-javascript.7.rst.in +++ b/man/ctags-lang-javascript.7.rst.in @@ -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) diff --git a/parsers/jscript.c b/parsers/jscript.c index 44f694065a..d59247d7d2 100644 --- a/parsers/jscript.c +++ b/parsers/jscript.c @@ -48,6 +48,8 @@ #include "mbcs.h" #include "trace.h" +#include "jscript.h" + /* * MACROS */ @@ -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. @@ -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" }, }; @@ -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" }, @@ -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; } diff --git a/parsers/jscript.h b/parsers/jscript.h new file mode 100644 index 0000000000..0dfb435900 --- /dev/null +++ b/parsers/jscript.h @@ -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 diff --git a/source.mak b/source.mak index 2266f84e19..068659f212 100644 --- a/source.mak +++ b/source.mak @@ -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 \ diff --git a/win32/ctags_vs2013.vcxproj b/win32/ctags_vs2013.vcxproj index 8e2fb01d6b..1d38f799d5 100644 --- a/win32/ctags_vs2013.vcxproj +++ b/win32/ctags_vs2013.vcxproj @@ -462,6 +462,7 @@ + diff --git a/win32/ctags_vs2013.vcxproj.filters b/win32/ctags_vs2013.vcxproj.filters index 3a327be697..70bd2e8352 100644 --- a/win32/ctags_vs2013.vcxproj.filters +++ b/win32/ctags_vs2013.vcxproj.filters @@ -905,6 +905,9 @@ Header Files + + Header Files + Header Files