Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Parse D functions with various attributes/storage classes

Parse @attributes, pure, nothrow.
Parse return types immutable(T), shared(T), inout(T).
  • Loading branch information...
commit e44198abb2080904576f3d7a52814d3d6c737339 1 parent edeaa52
@ntrel ntrel authored
Showing with 45 additions and 18 deletions.
  1. +3 −2 NEWS
  2. +42 −16 tagmanager/c.c
View
5 NEWS
@@ -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.
View
58 tagmanager/c.c
@@ -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 } },
@@ -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;
}
@@ -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:
*
@@ -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;
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.