Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/dparse/ast.d
Original file line number Diff line number Diff line change
Expand Up @@ -2932,6 +2932,14 @@ final class PrimaryExpression : ExpressionNode
/** */ Arguments arguments;
/** */ InterpolatedString interpolatedString;
mixin OpEquals;

IdType builtinType() inout @property @safe nothrow @nogc pure
{
if (type)
if (auto t2 = type.type2)
return t2.builtinType ? t2.builtinType : IdType.init;
return IdType.init;
}
}

///
Expand Down Expand Up @@ -4141,6 +4149,30 @@ unittest // issue #398: Support extern(C++, <string expressions...>)
checkText(ns[2], `"baz"`);
}

unittest // issue #526
{
import dparse.formatter, dparse.lexer, dparse.parser, dparse.rollback_allocator;
string src = q{enum E : int*[0] { a = int*[0].init }};
final class Test : ASTVisitor
{
}
RollbackAllocator ra;
auto cf = LexerConfig("", StringBehavior.source);
auto ca = StringCache(16);
Module m = ParserConfig(getTokensForParser(src, cf, &ca), "", &ra).parseModule();
auto t = new Test;
t.visit(m);
assert(m.declarations.length == 1);
auto ed = m.declarations[0].enumDeclaration;
assert(ed);
auto type = ed.type;
auto app = appender!string();
auto formatter = new Formatter!(typeof(app))(app);
formatter.format(type);
assert(app[] == "int*[0]");
assert(ed.type.typeSuffixes.length == 2);
}

unittest // Differentiate between no and empty DDOC comments, e.g. for DDOC unittests
{
import dparse.lexer, dparse.parser, dparse.rollback_allocator;
Expand Down
17 changes: 9 additions & 8 deletions src/dparse/parser.d
Original file line number Diff line number Diff line change
Expand Up @@ -5848,9 +5848,9 @@ class Parser
* $(GRAMMAR $(RULEDEF primaryExpression):
* $(RULE identifierOrTemplateInstance)
* | $(LITERAL '.') $(RULE identifierOrTemplateInstance)
* | $(RULE typeConstructor) $(LITERAL '$(LPAREN)') $(RULE basicType) $(LITERAL '$(RPAREN)') $(LITERAL '.') $(LITERAL Identifier)
* | $(RULE basicType) $(LITERAL '.') $(LITERAL Identifier)
* | $(RULE basicType) $(RULE arguments)
* | $(RULE typeConstructor) $(LITERAL '$(LPAREN)') $(RULE type) $(LITERAL '$(RPAREN)') $(LITERAL '.') $(LITERAL Identifier)
* | $(RULE builtinType) $(RULE typeSuffix)* $(LITERAL '.') $(LITERAL Identifier)
* | $(RULE builtinType) $(RULE typeSuffix)* $(RULE arguments)
* | $(RULE typeofExpression)
* | $(RULE typeidExpression)
* | $(RULE vector)
Expand Down Expand Up @@ -5923,18 +5923,19 @@ class Parser
break;
}
foreach (B; BasicTypes) { case B: }
node.basicType = advance();
{
node.type = parseType();
if (currentIs(tok!"."))
{
advance();
const t = expect(tok!"identifier");
if (t !is null)
node.primary = *t;
if (const ident = expect(tok!"identifier"))
node.primary = *ident;
}
else if (currentIs(tok!"("))
mixin(parseNodeQ!(`node.arguments`, `Arguments`));
else goto default;
break;
}
break;
case tok!"function":
case tok!"delegate":
case tok!"{":
Expand Down
1 change: 1 addition & 0 deletions test/pass_files/issue0526.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enum E : int*[0] { a = int*[0].init }
Loading