Skip to content

Commit

Permalink
PowerShell: keep the KEYWORD type
Browse files Browse the repository at this point in the history
This commit reverts the keyword type that was removed in a previous PR
and adds the attribute keywordType to tokenInfo.

Close universal-ctags#3479
  • Loading branch information
kumarstack55 committed Sep 10, 2022
1 parent fe5a84e commit 8edd3f4
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions parsers/powershell.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ typedef enum eTokenType {
TOKEN_SEMICOLON,
TOKEN_COLON,
TOKEN_COMMA,
TOKEN_KEYWORD_FUNCTION,
TOKEN_KEYWORD_CLASS,
TOKEN_KEYWORD,
TOKEN_OPEN_PAREN,
TOKEN_OPERATOR,
TOKEN_IDENTIFIER,
Expand All @@ -72,8 +71,15 @@ typedef enum eTokenType {
TOKEN_VARIABLE
} tokenType;

typedef enum eTokenKeywordType {
KEYWORD_UNDEFINED,
KEYWORD_FUNCTION,
KEYWORD_CLASS,
} tokenKeywordType;

typedef struct {
tokenType type;
tokenKeywordType keywordType;
vString * string;
vString * scope;
unsigned long lineNumber;
Expand Down Expand Up @@ -163,6 +169,7 @@ static tokenInfo *newToken (void)
tokenInfo *const token = xMalloc (1, tokenInfo);

token->type = TOKEN_UNDEFINED;
token->keywordType = KEYWORD_UNDEFINED;
token->string = vStringNew ();
token->scope = vStringNew ();
token->lineNumber = getInputLineNumber ();
Expand Down Expand Up @@ -377,10 +384,14 @@ static void readToken (tokenInfo *const token)
else
{
parseIdentifier (token->string, c);
if (isTokenFunction (token->string))
token->type = TOKEN_KEYWORD_FUNCTION;
else if (isTokenClass (token->string))
token->type = TOKEN_KEYWORD_CLASS;
if (isTokenFunction (token->string)) {
token->type = TOKEN_KEYWORD;
token->keywordType = KEYWORD_FUNCTION;
}
else if (isTokenClass (token->string)) {
token->type = TOKEN_KEYWORD;
token->keywordType = KEYWORD_CLASS;
}
else
token->type = TOKEN_IDENTIFIER;
}
Expand Down Expand Up @@ -619,12 +630,19 @@ static void enterScope (tokenInfo *const parentToken,
enterScope (token, NULL, KIND_GHOST_INDEX);
break;

case TOKEN_KEYWORD_FUNCTION:
readNext = parseFunction (token);
break;
case TOKEN_KEYWORD:
switch (token->keywordType)
{
case KEYWORD_FUNCTION:
readNext = parseFunction (token);
break;

case KEYWORD_CLASS:
readNext = parseClass (token);
break;

case TOKEN_KEYWORD_CLASS:
readNext = parseClass (token);
default: break;
}
break;

case TOKEN_VARIABLE:
Expand Down

0 comments on commit 8edd3f4

Please sign in to comment.