Skip to content

Commit

Permalink
Parse D functions with various attributes/storage classes
Browse files Browse the repository at this point in the history
Parse @attributes, pure, nothrow.
Parse return types immutable(T), shared(T), inout(T).
  • Loading branch information
ntrel committed Jun 8, 2012
1 parent edeaa52 commit e44198a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 18 deletions.
5 changes: 3 additions & 2 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ Geany 1.22 (unreleased)
* Parse PHP functions with multiline argument list (#3037797).
* Handle ``/bin/dash`` shebang (#3470986).
* Update JavaScript parser from CTags.
* Parse D class, struct, interface template bodies and template
blocks; ignore 'static if' expressions.
* Parse D class/struct/interface template bodies and template
blocks; ignore 'static if' expressions; parse function
@attributes, pure/nothrow and immutable/inout/shared return types.
* Fix broken tag/word autocompletion in HTML/PHP documents.
* Enable &entity; completion for all XML-based filetypes.

Expand Down
58 changes: 42 additions & 16 deletions tagmanager/c.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,8 @@ static const keywordDesc KeywordTable [] = {
{ "import", KEYWORD_IMPORT, { 0, 0, 0, 1, 0, 0, 1 } },
{ "inline", KEYWORD_INLINE, { 0, 1, 0, 0, 0, 1, 0 } },
{ "in", KEYWORD_IN, { 0, 0, 0, 0, 0, 0, 1 } },
{ "inout", KEYWORD_INOUT, { 0, 0, 0, 0, 1, 0, 1 } },
{ "inout", KEYWORD_INOUT, { 0, 0, 0, 0, 1, 0, 0 } },
{ "inout", KEYWORD_CONST, { 0, 0, 0, 0, 0, 0, 1 } }, /* treat like const */
{ "input", KEYWORD_INPUT, { 0, 0, 0, 0, 1, 0, 0 } },
{ "int", KEYWORD_INT, { 1, 1, 1, 1, 0, 1, 1 } },
{ "integer", KEYWORD_INTEGER, { 0, 0, 0, 0, 1, 0, 0 } },
Expand Down Expand Up @@ -1675,6 +1676,10 @@ static void skipBraces (void)
static keywordId analyzeKeyword (const char *const name)
{
const keywordId id = (keywordId) lookupKeyword (name, getSourceLanguage ());

/* ignore D @attributes, but show them in function signatures */
if (isLanguage(Lang_d) && id == KEYWORD_NONE && name[0] == '@')
return KEYWORD_CONST;
return id;
}

Expand Down Expand Up @@ -2116,6 +2121,29 @@ static void skipMacro (statementInfo *const st)
skipToMatch ("()");
}

static boolean isDPostArgumentToken(tokenInfo *const token)
{
switch (token->keyword)
{
/* Note: some other keywords e.g. immutable are parsed as
* KEYWORD_CONST - see initializeDParser */
case KEYWORD_CONST:
/* template constraint */
case KEYWORD_IF:
/* contracts */
case KEYWORD_IN:
case KEYWORD_OUT:
case KEYWORD_BODY:
return TRUE;
default:
break;
}
/* @attributes */
if (vStringValue(token->name)[0] == '@')
return TRUE;
return FALSE;
}

/* Skips over characters following the parameter list. This will be either
* non-ANSI style function declarations or C++ stuff. Our choices:
*
Expand Down Expand Up @@ -2177,21 +2205,9 @@ static boolean skipPostArgumentStuff (statementInfo *const st,
if (isident1 (c))
{
readIdentifier (token, c);
if (isLanguage(Lang_d))
{
switch (token->keyword)
{
/* template constraint */
case KEYWORD_IF:
/* contracts */
case KEYWORD_IN:
case KEYWORD_OUT:
case KEYWORD_BODY:
token->keyword = KEYWORD_CONST;
default:
break;
}
}
if (isLanguage(Lang_d) && isDPostArgumentToken(token))
token->keyword = KEYWORD_CONST;

switch (token->keyword)
{
case KEYWORD_ATTRIBUTE: skipParens (); break;
Expand Down Expand Up @@ -3100,8 +3116,18 @@ static void initializeJavaParser (const langType language)

static void initializeDParser (const langType language)
{
/* keyword aliases - some are for parsing like const(Type), some are just
* function attributes */
char *const_aliases[] = {"immutable", "nothrow", "pure", "shared", NULL};
char **s;

Lang_d = language;
buildKeywordHash (language, 6);

for (s = const_aliases; *s != NULL; s++)
{
addKeyword (*s, language, KEYWORD_CONST);
}
}

static void initializeGLSLParser (const langType language)
Expand Down

0 comments on commit e44198a

Please sign in to comment.