Skip to content

Commit

Permalink
Sync ctags parsers with big changes with Geany (geany#2991)
Browse files Browse the repository at this point in the history
* Remove the geany_ prefix from selected parsers and use the corresponding uctags version

* Update tag mappings in tm_parser.c

* Update PHP and zephir context separator to "\\" which is used in uctags now

* Update ruby unit tests, the tests only differ in added "()" to all functions in generated tags.

* Update nsis unit tests, the section name seems to be parsed correctly now.

* Update go unit tests, the new go tags contain extra scope information.

* Update php and zephir unit tests, PHP and zephir now use "\\" as the context separator instead of "::".
For zephir, return values of methods are now parsed.

* Update Objective-C unit tests, the new parser parses also method arguments.

* Update lua unit tests, Scope information seems to be correctly parsed now.

* Add uctags iniconf parser

* Update tag mappings for the iniconf parser

* Add a way to modify scope information if needed and use it to unify php separators

This patch introduces a new function tm_parser_update_scope() which
can be used to modify scope information when the provided value from
ctags doesn't suit our needs.

This patch uses it to replace php scope separator \ with :: so there's
a single scope separator for this language.

* Remove comment regarding ruby scope separator

"." is used as the context separator in ruby now, the comment is
probably just some historic artifact.

* Add comment explaining why we modify PHP scope separators

* Add a mechanism to enable/disable roles for certain kinds

This patch allows us to enable/disable ctags roles for certain languages
and kinds. Roles are currently disabled only for the Go kind 'p'
for the reasons mentioned in the comment message in the patch.

* Add a mechanism to enable/disable some ctags kinds

This patch is similar to the patch allowing us to enable/disable roles,
it just does this for ctags kinds. This can be useful when there is
a bug in a ctags parser causing incorrect parsing when certain kind is
enabled - which is what happens when parsing cython source files
with the 'z' flag enabled.

* Add LUA to the list of parsers returning full scope

* Enable/disable kinds in ctags based on whether we use them or not

Instead of enabling all kinds and then manually disabling them if
there are problems with them, we can enable/disable them based on whether
we actually use them - i.e., when they are mapped to something else
than tm_tag_undef_t.
  • Loading branch information
techee committed Dec 7, 2021
1 parent 808b7a3 commit ad1debc
Show file tree
Hide file tree
Showing 49 changed files with 7,447 additions and 3,325 deletions.
33 changes: 18 additions & 15 deletions ctags/Makefile.am
Expand Up @@ -15,43 +15,46 @@ parsers = \
parsers/abc.c \
parsers/asciidoc.c \
parsers/geany_asm.c \
parsers/geany_basic.c \
parsers/basic.c \
parsers/bibtex.c \
parsers/geany_c.c \
parsers/cobol.c \
parsers/geany_iniconf.c \
parsers/iniconf.c \
parsers/iniconf.h \
parsers/css.c \
parsers/geany_diff.c \
parsers/diff.c \
parsers/geany_docbook.c \
parsers/erlang.c \
parsers/flex.c \
parsers/geany_fortran.c \
parsers/geany_go.c \
parsers/go.c \
parsers/haskell.c \
parsers/haxe.c \
parsers/geany_html.c \
parsers/geany_jscript.c \
parsers/html.c \
parsers/jscript.c \
parsers/json.c \
parsers/julia.c \
parsers/geany_lcpp.c \
parsers/geany_lcpp.h \
parsers/geany_lua.c \
parsers/geany_make.c \
parsers/lua.c \
parsers/make.c \
parsers/make.h \
parsers/geany_markdown.c \
parsers/geany_matlab.c \
parsers/geany_nsis.c \
parsers/geany_objc.c \
parsers/nsis.c \
parsers/objc.c \
parsers/geany_pascal.c \
parsers/geany_perl.c \
parsers/geany_php.c \
parsers/perl.c \
parsers/perl.h \
parsers/php.c \
parsers/powershell.c \
parsers/geany_python.c \
parsers/geany_r.c \
parsers/rst.c \
parsers/geany_ruby.c \
parsers/geany_rust.c \
parsers/ruby.c \
parsers/rust.c \
parsers/geany_sh.c \
parsers/geany_sql.c \
parsers/sql.c \
parsers/geany_tcl.c \
parsers/geany_tex.c \
parsers/txt2tags.c \
Expand Down
206 changes: 206 additions & 0 deletions ctags/parsers/basic.c
@@ -0,0 +1,206 @@
/*
* Copyright (c) 2000-2006, Darren Hiebert, Elias Pschernig
*
* 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 BlitzBasic
* (BlitzMax), PureBasic and FreeBasic language files. For now, this is kept
* quite simple - but feel free to ask for more things added any time -
* patches are of course most welcome.
*/

/*
* INCLUDE FILES
*/
#include "general.h" /* must always come first */

#include <string.h>

#include "parse.h"
#include "read.h"
#include "routines.h"
#include "vstring.h"

/*
* DATA DEFINITIONS
*/
typedef enum {
K_CONST,
K_FUNCTION,
K_LABEL,
K_TYPE,
K_VARIABLE,
K_ENUM
} BasicKind;

typedef struct {
char const *token;
BasicKind kind;
int skip;
} KeyWord;

static kindDefinition BasicKinds[] = {
{true, 'c', "constant", "constants"},
{true, 'f', "function", "functions"},
{true, 'l', "label", "labels"},
{true, 't', "type", "types"},
{true, 'v', "variable", "variables"},
{true, 'g', "enum", "enumerations"}
};

static KeyWord blitzbasic_keywords[] = {
{"const", K_CONST, 0},
{"global", K_VARIABLE, 0},
{"dim", K_VARIABLE, 0},
{"function", K_FUNCTION, 0},
{"type", K_TYPE, 0},
{NULL, 0, 0}
};

static KeyWord purebasic_keywords[] = {
{"newlist", K_VARIABLE, 0},
{"global", K_VARIABLE, 0},
{"dim", K_VARIABLE, 0},
{"procedure", K_FUNCTION, 0},
{"interface", K_TYPE, 0},
{"structure", K_TYPE, 0},
{NULL, 0, 0}
};

static KeyWord freebasic_keywords[] = {
{"const", K_CONST, 0},
{"dim as", K_VARIABLE, 1},
{"dim", K_VARIABLE, 0},
{"common", K_VARIABLE, 0},
{"function", K_FUNCTION, 0},
{"sub", K_FUNCTION, 0},
{"private sub", K_FUNCTION, 0},
{"public sub", K_FUNCTION, 0},
{"private function", K_FUNCTION, 0},
{"public function", K_FUNCTION, 0},
{"type", K_TYPE, 0},
{"enum", K_ENUM, 0},
{NULL, 0, 0}
};

/*
* FUNCTION DEFINITIONS
*/

/* Match the name of a tag (function, variable, type, ...) starting at pos. */
static char const *extract_name (char const *pos, vString * name)
{
while (isspace (*pos))
pos++;
vStringClear (name);
for (; *pos && !isspace (*pos) && *pos != '(' && *pos != ','; pos++)
vStringPut (name, *pos);
return pos;
}

/* Match a keyword starting at p (case insensitive). */
static int match_keyword (const char *p, KeyWord const *kw)
{
vString *name;
size_t i;
int j;
for (i = 0; i < strlen (kw->token); i++)
{
if (tolower (p[i]) != kw->token[i])
return 0;
}
name = vStringNew ();
p += i;
for (j = 0; j < 1 + kw->skip; j++)
{
p = extract_name (p, name);
}
makeSimpleTag (name, kw->kind);
vStringDelete (name);
return 1;
}

/* Match a "label:" style label. */
static void match_colon_label (char const *p)
{
char const *end = p + strlen (p) - 1;
while (isspace (*end))
end--;
if (*end == ':')
{
vString *name = vStringNew ();
vStringNCatS (name, p, end - p);
makeSimpleTag (name, K_LABEL);
vStringDelete (name);
}
}

/* Match a ".label" style label. */
static void match_dot_label (char const *p)
{
if (*p == '.')
{
vString *name = vStringNew ();
extract_name (p + 1, name);
makeSimpleTag (name, K_LABEL);
vStringDelete (name);
}
}

static void findBasicTags (void)
{
const char *line;
const char *extension = fileExtension (getInputFileName ());
KeyWord *keywords;

if (strcmp (extension, "bb") == 0)
keywords = blitzbasic_keywords;
else if (strcmp (extension, "pb") == 0)
keywords = purebasic_keywords;
else
keywords = freebasic_keywords;

while ((line = (const char *) readLineFromInputFile ()) != NULL)
{
const char *p = line;
KeyWord const *kw;

while (isspace (*p))
p++;

/* Empty line? */
if (!*p)
continue;

/* REM comment? */
if (strncasecmp (p, "REM", 3) == 0 &&
(isspace (*(p + 3)) || *(p + 3) == '\0'))
continue;

/* Single-quote comment? */
if (*p == '\'')
continue;

/* In Basic, keywords always are at the start of the line. */
for (kw = keywords; kw->token; kw++)
if (match_keyword (p, kw)) break;

/* Is it a label? */
if (strcmp (extension, "bb") == 0)
match_dot_label (p);
else
match_colon_label (p);
}
}

parserDefinition *BasicParser (void)
{
static char const *extensions[] = { "bas", "bi", "bm", "bb", "pb", NULL };
parserDefinition *def = parserNew ("Basic");
def->kindTable = BasicKinds;
def->kindCount = ARRAY_SIZE (BasicKinds);
def->extensions = extensions;
def->parser = findBasicTags;
return def;
}

0 comments on commit ad1debc

Please sign in to comment.