Skip to content

Commit

Permalink
Merge branch 'geany:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex313031 committed Jun 19, 2024
2 parents e9f931e + 90027eb commit bb8c609
Show file tree
Hide file tree
Showing 35 changed files with 876 additions and 637 deletions.
298 changes: 212 additions & 86 deletions ctags/libreadtags/readtags.c

Large diffs are not rendered by default.

20 changes: 18 additions & 2 deletions ctags/libreadtags/readtags.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ typedef enum {
#define sortType tagSortType
#endif

/* Options for tagsFind() */
/* Options for tagsFind() and tagsFindPseudoTag() */
#define TAG_FULLMATCH 0x0
#define TAG_PARTIALMATCH 0x1

Expand All @@ -59,6 +59,7 @@ typedef enum {
* (Zero or a positive integer is expected.) */
TagErrnoInvalidArgument = -4, /* Unexpected argument passed to the API
* function */
TagErrnoFileMaybeTooBig = -5, /* Maybe the tags file is too big */
} tagErrno;

struct sTagFile;
Expand Down Expand Up @@ -258,7 +259,7 @@ extern tagResult tagsFindNext (tagFile *const file, tagEntry *const entry);

/*
* Does the same as tagsFirst(), but is specialized to pseudo tags.
* If tagFileInfo doesn't contain pseudo tags you are interested, read
* If tagFileInfo doesn't contain pseudo tags you are interested in, read
* them sequentially with this function and tagsNextPseudoTag().
*/
extern tagResult tagsFirstPseudoTag (tagFile *const file, tagEntry *const entry);
Expand All @@ -269,6 +270,21 @@ extern tagResult tagsFirstPseudoTag (tagFile *const file, tagEntry *const entry)
*/
extern tagResult tagsNextPseudoTag (tagFile *const file, tagEntry *const entry);

/*
* Does the same as tagsFind(), but is specialized to pseudo tags.
* The available values for `match' are:
*
* TAG_PARTIALMATCH
* Tags whose leading characters match `name' will qualify.
*
* TAG_FULLMATCH
* Only tags whose full lengths match `name' will qualify.
*
* NOTE: unlike tagsFind(), this function uses liner-searching even if
* the tags file is sorted.
*/
extern tagResult tagsFindPseudoTag (tagFile *const file, tagEntry *const entry, const char *const name, const int match);

/*
* Call tagsClose() at completion of reading the tag file, which will
* close the file and free any internal memory allocated. The function will
Expand Down
2 changes: 1 addition & 1 deletion ctags/main/repoinfo.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define CTAGS_REPOINFO "p6.1.20240421.0"
#define CTAGS_REPOINFO "p6.1.20240519.0"
166 changes: 111 additions & 55 deletions ctags/parsers/jscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ typedef struct sTokenInfo {
MIOPos filePosition;
int nestLevel;
bool dynamicProp;
int c;
} tokenInfo;

/*
Expand Down Expand Up @@ -367,6 +368,7 @@ static void copyToken (tokenInfo *const dest, const tokenInfo *const src,
dest->type = src->type;
dest->keyword = src->keyword;
dest->dynamicProp = src->dynamicProp;
dest->c = src->c;
vStringCopy(dest->string, src->string);
if (include_non_read_info)
{
Expand Down Expand Up @@ -464,7 +466,7 @@ static int makeJsRefTagsForNameChain (char *name_chain, const tokenInfo *token,
e.extensionFields.scopeIndex = scope;

index = makeTagEntry (&e);
/* We shold remove This condition. We should fix the callers passing
/* We should remove this condition. We should fix the callers passing
* an empty name instead. makeTagEntry() returns CORK_NIL if the tag
* name is empty. */
if (index != CORK_NIL)
Expand Down Expand Up @@ -996,6 +998,32 @@ static void parseTemplateString (vString *const string)
while (c != EOF);
}

static void reprToken (const tokenInfo *const token, vString *const repr)
{
switch (token->type)
{
case TOKEN_DOTS:
vStringCatS (repr, "...");
break;

case TOKEN_STRING:
case TOKEN_TEMPLATE_STRING:
vStringPut (repr, token->c);
vStringCat (repr, token->string);
vStringPut (repr, token->c);
break;

case TOKEN_IDENTIFIER:
case TOKEN_KEYWORD:
vStringCat (repr, token->string);
break;

default:
vStringPut (repr, token->c);
break;
}
}

static void readTokenFullRaw (tokenInfo *const token, bool include_newlines, vString *const repr)
{
int c;
Expand All @@ -1005,9 +1033,12 @@ static void readTokenFullRaw (tokenInfo *const token, bool include_newlines, vSt
/* if we've got a token held back, emit it */
if (NextToken)
{
TRACE_PRINT("Emitting held token");
copyToken (token, NextToken, false);
deleteToken (NextToken);
NextToken = NULL;
if (repr)
reprToken (token, repr);
return;
}

Expand All @@ -1029,12 +1060,11 @@ static void readTokenFullRaw (tokenInfo *const token, bool include_newlines, vSt
token->lineNumber = getInputLineNumber ();
token->filePosition = getInputFilePosition ();

if (repr && c != EOF)
{
if (i > 1)
vStringPut (repr, ' ');
vStringPut (repr, c);
}
/* special case to insert a separator */
if (repr && c != EOF && i > 1)
vStringPut (repr, ' ');

token->c = c;

switch (c)
{
Expand Down Expand Up @@ -1063,14 +1093,6 @@ static void readTokenFullRaw (tokenInfo *const token, bool include_newlines, vSt
}

token->type = TOKEN_DOTS;
if (repr)
{
/* Adding two dots is enough here.
* The first one is already added with
* vStringPut (repr, c).
*/
vStringCatS (repr, "..");
}
break;
}
case ':': token->type = TOKEN_COLON; break;
Expand Down Expand Up @@ -1125,23 +1147,13 @@ static void readTokenFullRaw (tokenInfo *const token, bool include_newlines, vSt
parseString (token->string, c);
token->lineNumber = getInputLineNumber ();
token->filePosition = getInputFilePosition ();
if (repr)
{
vStringCat (repr, token->string);
vStringPut (repr, c);
}
break;

case '`':
token->type = TOKEN_TEMPLATE_STRING;
parseTemplateString (token->string);
token->lineNumber = getInputLineNumber ();
token->filePosition = getInputFilePosition ();
if (repr)
{
vStringCat (repr, token->string);
vStringPut (repr, c);
}
break;

case '/':
Expand Down Expand Up @@ -1173,8 +1185,6 @@ static void readTokenFullRaw (tokenInfo *const token, bool include_newlines, vSt
}
else
{
if (repr) /* remove the / we added */
vStringChop(repr);
if (d == '*')
{
skipToCharacterInInputFile2('*', '/');
Expand Down Expand Up @@ -1228,8 +1238,6 @@ static void readTokenFullRaw (tokenInfo *const token, bool include_newlines, vSt
token->type = TOKEN_IDENTIFIER;
else
token->type = TOKEN_KEYWORD;
if (repr && vStringLength (token->string) > 1)
vStringCatS (repr, vStringValue (token->string) + 1);
}
break;
}
Expand Down Expand Up @@ -1278,15 +1286,58 @@ static void readTokenFullRaw (tokenInfo *const token, bool include_newlines, vSt
token->type = TOKEN_SEMICOLON;
token->keyword = KEYWORD_NONE;
vStringClear (token->string);
if (repr)
vStringPut (token->string, '\n');
token->c = '\n';
}

#undef IS_STMT_SEPARATOR
#undef IS_BINARY_OPERATOR
}

LastTokenType = token->type;

if (repr)
reprToken (token, repr);
}

/* whether something we consider a keyword (either because it sometimes is or
* because of the parser's perks) is actually valid as a function name
* See https://tc39.es/ecma262/multipage/ecmascript-language-lexical-grammar.html#sec-keywords-and-reserved-words */
static bool canBeFunctionName (const tokenInfo *const token, bool strict_mode)
{
switch (token->keyword)
{
/* non-keywords specific to this parser */
case KEYWORD_capital_function:
case KEYWORD_capital_object:
case KEYWORD_prototype:
case KEYWORD_sap:
/* syntactic, but not keyword:
* as async from get meta of set target
* "await" is OK as well */
case KEYWORD_async:
case KEYWORD_get:
case KEYWORD_set:
return true;

/* strict-mode keywords
* let static implements interface package private protected public
* we need to also include those which are OK as function names
* yield
*/
case KEYWORD_let:
case KEYWORD_static:
return ! strict_mode;

default:
return isType (token, TOKEN_IDENTIFIER);
}
}

static bool canBePropertyName (const tokenInfo *const token)
{
/* property names are pretty relaxed, any non reserved word is OK, even
* strict-mode ones in strict-mode */
return canBeFunctionName (token, false);
}

/* See https://babeljs.io/blog/2018/09/17/decorators */
Expand Down Expand Up @@ -1760,9 +1811,11 @@ static bool parseFunction (tokenInfo *const token, tokenInfo *const lhs_name, co
copyToken (name, token, true);
readToken (name);
if (isType (name, TOKEN_KEYWORD) &&
(isKeyword (name, KEYWORD_get) || isKeyword (name, KEYWORD_set)))
canBeFunctionName (name, false /* true if we're in strict mode */))
{
name->type = TOKEN_IDENTIFIER; // treat as function name
// treat as function name
name->type = TOKEN_IDENTIFIER;
name->keyword = KEYWORD_NONE;
}

if (isType (name, TOKEN_STAR))
Expand Down Expand Up @@ -1981,27 +2034,24 @@ static bool parseMethods (tokenInfo *const token, int class_index,
{
bool is_setter = false;
bool is_getter = false;
bool is_static = false; /* For recognizing static {...} block. */

if (!dont_read)
readToken (token);
dont_read = false;

start:
if (isType (token, TOKEN_CLOSE_CURLY))
{
goto cleanUp;
}

if (isKeyword (token, KEYWORD_async))
readToken (token);
else if (isKeyword (token, KEYWORD_static))
is_static = true;
else if (isType (token, TOKEN_KEYWORD) &&
(isKeyword (token, KEYWORD_get) || isKeyword (token, KEYWORD_set)))
if (isType (token, TOKEN_KEYWORD) && canBePropertyName (token))
{
tokenInfo *saved_token = newToken ();
copyToken (saved_token, token, true);
readToken (token);

/* it wasn't actually a keyword after all, make it an identifier */
if (isType(token, TOKEN_OPEN_PAREN) || isType(token, TOKEN_COLON))
{
Assert (NextToken == NULL);
Expand All @@ -2011,10 +2061,25 @@ static bool parseMethods (tokenInfo *const token, int class_index,
token->type = TOKEN_IDENTIFIER; /* process as identifier */
token->keyword = KEYWORD_NONE;
}
else if (isKeyword (saved_token, KEYWORD_static) &&
isType (token, TOKEN_OPEN_CURLY))
{
/* static initialization block */
deleteToken (saved_token);
parseBlock (token, class_index);
continue;
}
else if (isKeyword (saved_token, KEYWORD_get))
is_getter = true;
else
else if (isKeyword (saved_token, KEYWORD_set))
is_setter = true;
else if (isKeyword (saved_token, KEYWORD_async) ||
isKeyword (saved_token, KEYWORD_static))
{
/* can be a qualifier for another "keyword", so start over */
deleteToken (saved_token);
goto start;
}

deleteToken (saved_token);
}
Expand All @@ -2025,9 +2090,8 @@ static bool parseMethods (tokenInfo *const token, int class_index,
continue;
}

if ((! isType (token, TOKEN_KEYWORD) &&
if (! isType (token, TOKEN_KEYWORD) &&
! isType (token, TOKEN_SEMICOLON))
|| is_static)
{
bool is_generator = false;
bool is_shorthand = false; /* ES6 shorthand syntax */
Expand Down Expand Up @@ -2202,15 +2266,6 @@ static bool parseMethods (tokenInfo *const token, int class_index,

vStringDelete (signature);
}
else if (is_static)
{
if (isType (token, TOKEN_OPEN_CURLY))
/* static initialization block */
parseBlock (token, class_index);
else
dont_read = true;
continue;
}
else
{
bool is_property = isType (token, TOKEN_COMMA);
Expand Down Expand Up @@ -2409,10 +2464,11 @@ static bool parsePrototype (tokenInfo *const name, tokenInfo *const token, state
* Handle CASE 1
*/
readToken (token);
if (isType (token, TOKEN_KEYWORD) &&
(isKeyword (token, KEYWORD_get) || isKeyword (token, KEYWORD_set)))
if (isType (token, TOKEN_KEYWORD) && canBePropertyName (token))
{
token->type = TOKEN_IDENTIFIER; // treat as function name
// treat as function name
token->type = TOKEN_IDENTIFIER;
token->keyword = KEYWORD_NONE;
}

if (! isType(token, TOKEN_KEYWORD))
Expand Down
11 changes: 6 additions & 5 deletions ctags/parsers/matlab.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@

static tagRegexTable matlabTagRegexTable [] = {
/* function [x,y,z] = asdf */
{ "^[ \t]*function[ \t]*\\[.*\\][ \t]*=[ \t]*([.a-zA-Z0-9_]+)",
{ "^[ \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_]+)",
{"^[ \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",
/* function asdf
* function asdf % some comment */
{"^[ \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",
{"^[ \t]*classdef[ \t]+([a-zA-Z0-9_]+)", "\\1",
"c,class", NULL},
};

Expand Down
Loading

0 comments on commit bb8c609

Please sign in to comment.