Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: Jiří Techet techet@gmail.com Date: Sat, 27 Apr 2024 20:09:38 UTC Commit: aa0c796b5c1e6a1b6a4050086309a5864819eca3 https://github.com/geany/geany/commit/aa0c796b5c1e6a1b6a4050086309a5864819ec...
Log Message: ----------- Switch to uctags regex-based matlab parser
Even though the output isn't perfect, I'd prefer not to maintain our own version of the parser (with different kinds which makes ctags files incompatible with our version).
Modified Paths: -------------- ctags/Makefile.am ctags/parsers/geany_matlab.c ctags/parsers/matlab.c meson.build src/tagmanager/tm_parser.c tests/ctags/matlab_backtracking.m.tags tests/ctags/matlab_test.m.tags
Modified: ctags/Makefile.am 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -85,7 +85,7 @@ parsers = \ parsers/make.h \ parsers/markdown.c \ parsers/markdown.h \ - parsers/geany_matlab.c \ + parsers/matlab.c \ parsers/nsis.c \ parsers/objc.c \ parsers/ocaml.c \
Modified: ctags/parsers/geany_matlab.c 150 lines changed, 0 insertions(+), 150 deletions(-) =================================================================== @@ -1,150 +0,0 @@ -/* -* -* Copyright (c) 2000-2001, Darren Hiebert -* -* This source code is released for free distribution under the terms of the -* GNU General Public License. -* -* This module contains functions for generating tags for Matlab scripts. -* The tags 'function' and 'struct' are parsed. -* Author Roland Baudin roland65@free.fr -*/ - -/* -* INCLUDE FILES -*/ -#include "general.h" /* must always come first */ - -#include <string.h> - -#include "parse.h" -#include "routines.h" -#include "read.h" -#include "vstring.h" - -/* -* DATA DEFINITIONS -*/ -typedef enum { - K_FUNCTION, - K_STRUCT -} MatlabKind; - -static kindDefinition MatlabKinds [] = { - { true, 'f', "function", "Functions" }, - { true, 's', "struct", "Structures" }, -}; - -/* -* FUNCTION DEFINITIONS -*/ - -static void findMatlabTags (void) -{ - vString *name = vStringNew (); - const unsigned char *line; - const unsigned char *p; - - while ((line = readLineFromInputFile ()) != NULL) - { - int i, ic; - - if (line [0] == '\0' || line [0] == '%') - continue; - - /* search if the line has a comment */ - for (ic = 0 ; line [ic] != '\0' && line [ic]!='%' ; ++ic) - ; - - /* function tag */ - - /* read first word */ - for (i = 0 ; line [i] != '\0' && ! isspace (line [i]) ; ++i) - ; - - if (strncmp ((const char *) line, "function", (size_t) 8) == 0 - && isspace (line [8])) - { - const unsigned char *cp = line + i; - const unsigned char *ptr = cp; - bool eq=false; - - while (isspace ((int) *cp)) - ++cp; - - /* search for '=' character in the line (ignoring comments) */ - while (*ptr != '\0') - { - if (*ptr == '%') - break; - - if (*ptr == '=') - { - eq=true; - break; - } - ptr++; - } - - /* '=' was found => get the first word of the line after '=' */ - if (eq) - { - ptr++; - while (isspace ((int) *ptr)) - ++ptr; - - while (isalnum ((int) *ptr) || *ptr == '_') - { - vStringPut (name, (int) *ptr); - ++ptr; - } - } - - /* '=' was not found => get the first word of the line after "function" */ - else - { - while (isalnum ((int) *cp) || *cp == '_') - { - vStringPut (name, (int) *cp); - ++cp; - } - } - - makeSimpleTag (name, K_FUNCTION); - vStringClear (name); - } - - /* struct tag */ - - /* search if the line contains the keyword 'struct' */ - p=(const unsigned char*) strstr ((const char*) line, "struct"); - - /* and avoid the part after the '%' if any */ - if ( p != NULL && ic>0 && p < line+ic) - { - const unsigned char *cp = line; - - /* get the left most part of the line before '=' */ - while (*cp != '\0' && !isspace(*cp) && *cp != '=' ) - { - vStringPut (name, (int) *cp); - ++cp; - } - - makeSimpleTag (name, K_STRUCT); - vStringClear (name); - } - } - vStringDelete (name); -} - -extern parserDefinition* MatLabParser (void) -{ - static const char *const extensions [] = { "m", NULL }; - parserDefinition* def = parserNew ("Matlab"); - def->kindTable = MatlabKinds; - def->kindCount = ARRAY_SIZE (MatlabKinds); - def->extensions = extensions; - def->parser = findMatlabTags; - return def; -}
Modified: ctags/parsers/matlab.c 53 lines changed, 53 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2008, David Fishburn +* +* 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 MATLAB language files. +*/ + +/* +* INCLUDE FILES +*/ +#include "general.h" /* must always come first */ + +#include <string.h> +#include "parse.h" +#include "routines.h" +#include "selectors.h" + +static tagRegexTable matlabTagRegexTable [] = { + /* function [x,y,z] = asdf */ + { "^[ \t]*function[ \t]*\[.*\][ \t]*=[ \t]*([.a-zA-Z0-9_]+)", + "\1", "f,function", NULL}, + /* function x = asdf */ + {"^[ \t]*function[ \t]*[a-zA-Z0-9_]+[ \t]*=[ \t]*([.a-zA-Z0-9_]+)", + "\1", "f,function", NULL}, + /* function asdf */ + {"^[ \t]*function[ \t]*([.a-zA-Z0-9_]+)[^=]*$", "\1", + "f,function", NULL}, + /* variables */ + {"^[ \t]*([a-zA-Z0-9_]+)[ \t]*=[ \t]", "\1", + "v,variable", NULL}, + /* class definitions */ + {"^[ \t]*classdef[ \t]*([a-zA-Z0-9_]+)", "\1", + "c,class", NULL}, +}; + +/* +* FUNCTION DEFINITIONS +*/ +extern parserDefinition* MatLabParser (void) +{ + static const char *const extensions [] = { "m", NULL }; + static selectLanguage selectors [] = { selectByObjectiveCAndMatLabKeywords, + NULL }; + parserDefinition* const def = parserNew ("MatLab"); + def->extensions = extensions; + def->tagRegexTable = matlabTagRegexTable; + def->tagRegexCount = ARRAY_SIZE (matlabTagRegexTable); + def->method = METHOD_NOT_CRAFTED|METHOD_REGEX; + def->selectLanguage = selectors; + return def; +}
Modified: meson.build 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -650,7 +650,7 @@ ctags = static_library('ctags', 'ctags/parsers/geany_docbook.c', 'ctags/parsers/geany_lcpp.c', 'ctags/parsers/geany_lcpp.h', - 'ctags/parsers/geany_matlab.c', + 'ctags/parsers/matlab.c', 'ctags/parsers/go.c', 'ctags/parsers/haskell.c', 'ctags/parsers/haxe.c',
Modified: src/tagmanager/tm_parser.c 6 lines changed, 4 insertions(+), 2 deletions(-) =================================================================== @@ -668,11 +668,13 @@ static TMParserMapGroup group_FORTRAN[] = {
static TMParserMapEntry map_MATLAB[] = { {'f', tm_tag_function_t}, // function - {'s', tm_tag_struct_t}, // struct + {'v', tm_tag_variable_t}, // variable + {'c', tm_tag_class_t}, // class }; static TMParserMapGroup group_MATLAB[] = { + {N_("Classes"), TM_ICON_CLASS, tm_tag_class_t}, {N_("Functions"), TM_ICON_METHOD, tm_tag_function_t}, - {N_("Structures"), TM_ICON_STRUCT, tm_tag_struct_t}, + {N_("Variables"), TM_ICON_VAR, tm_tag_variable_t}, };
#define map_CUDA map_C
Modified: tests/ctags/matlab_backtracking.m.tags 10 lines changed, 10 insertions(+), 0 deletions(-) =================================================================== @@ -1,2 +1,12 @@ backtrack�16�0 function: backtrack +cDDfnc�16384�0 +variable: cDDfnc +d�16384�0 +variable: d +fcall�16384�0 +variable: fcall +fn�16384�0 +variable: fn +xn�16384�0 +variable: xn
Modified: tests/ctags/matlab_test.m.tags 6 lines changed, 4 insertions(+), 2 deletions(-) =================================================================== @@ -1,3 +1,5 @@ +FAIL6�16�0 +function: FAIL6 func1�16�0 function: func1 func2�16�0 @@ -6,5 +8,5 @@ func3 function: func3 func4�16�0 function: func4 -func5�16�0 -function: func5 +functionality�16384�0 +variable: functionality
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).