Skip to content

Commit 9f54e5d

Browse files
ntrelmasatake
authored andcommitted
D: parse user-defined attributes
Quoted from the pull request (#3701): UDAs can precede a declaration or come after a function parameter list. https://dlang.org/spec/attribute.html#uda @mastake edited the commit log.
1 parent 5fb6767 commit 9f54e5d

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

Units/parser-d.r/simple.d.d/expected.tags

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ TemplateAlias input.d /^ alias TemplateAlias = a!T;$/;" a file:
1111
UT input.d /^union UT(T){}$/;" u file:
1212
Union input.d /^ union Union$/;" u struct:Struct file:
1313
_bar input.d /^ private AliasInt _bar;$/;" m class:Class file:
14+
attr_anon input.d /^@(obj) T attr_anon;$/;" v
15+
attr_decl input.d /^@attr(i) int attr_decl = 1;$/;" v
1416
bar input.d /^ bar,$/;" e enum:Enum file:
1517
bar input.d /^ public AliasInt bar()$/;" f class:Class
1618
conditional input.d /^ T conditional;$/;" v file:

Units/parser-d.r/simple.d.d/input.d

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ int i;
7878
int error;
7979
+/
8080

81+
@attr(i) int attr_decl = 1;
82+
@attr(i) attr_decl_infer = 1; // FIXME
83+
@(obj) T attr_anon;
84+
void attr_post() @attr(obj); // FIXME
85+
8186
static if (is(typeof(__traits(getMember, a, name)) == function))
8287
T conditional;
8388

parsers/c-based.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,6 +2123,10 @@ static bool skipPostArgumentStuff (
21232123
break;
21242124
}
21252125
}
2126+
else if (isInputLanguage (Lang_d) && c == '@')
2127+
{
2128+
parseAtMarkStyleAnnotation (st);
2129+
}
21262130
}
21272131
if (! end)
21282132
{
@@ -2226,7 +2230,11 @@ static void parseAtMarkStyleAnnotation (statementInfo *const st)
22262230
tokenInfo *const token = activeToken (st);
22272231

22282232
int c = skipToNonWhite ();
2229-
readIdentifier (token, c);
2233+
if (cppIsident1 (c))
2234+
readIdentifier (token, c);
2235+
else
2236+
cppUngetc (c); // D allows: @ ( ArgumentList )
2237+
22302238
if (token->keyword == KEYWORD_INTERFACE)
22312239
{
22322240
/* Oops. This was actually "@interface" defining a new annotation. */
@@ -2347,7 +2355,7 @@ static int parseParens (statementInfo *const st, parenInfo *const info)
23472355
break;
23482356

23492357
default:
2350-
if (c == '@' && isInputLanguage (Lang_java))
2358+
if (c == '@' && (isInputLanguage (Lang_d) || isInputLanguage (Lang_java)))
23512359
{
23522360
parseAtMarkStyleAnnotation (st);
23532361
}
@@ -2638,7 +2646,7 @@ static void parseGeneralToken (statementInfo *const st, const int c)
26382646
if (c2 != '=')
26392647
cppUngetc (c2);
26402648
}
2641-
else if (c == '@' && isInputLanguage (Lang_java))
2649+
else if (c == '@' && (isInputLanguage (Lang_d) || isInputLanguage (Lang_java)))
26422650
{
26432651
parseAtMarkStyleAnnotation (st);
26442652
}

0 commit comments

Comments
 (0)