Skip to content

Commit

Permalink
Switch to uctags regex-based matlab parser
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
techee committed Apr 27, 2024
1 parent 978eb03 commit aa0c796
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 156 deletions.
2 changes: 1 addition & 1 deletion ctags/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
150 changes: 0 additions & 150 deletions ctags/parsers/geany_matlab.c

This file was deleted.

53 changes: 53 additions & 0 deletions ctags/parsers/matlab.c
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 4 additions & 2 deletions src/tagmanager/tm_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tests/ctags/matlab_backtracking.m.tags
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions tests/ctags/matlab_test.m.tags
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
FAIL6�16�0
function: FAIL6
func1�16�0
function: func1
func2�16�0
Expand All @@ -6,5 +8,5 @@ func3
function: func3
func4�16�0
function: func4
func5�16�0
function: func5
functionality�16384�0
variable: functionality

0 comments on commit aa0c796

Please sign in to comment.