Skip to content

Commit 5ee9328

Browse files
committed
1 parent ce770e4 commit 5ee9328

2 files changed

Lines changed: 59 additions & 2 deletions

File tree

src/dparse/ast.d

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4195,6 +4195,33 @@ unittest // issue #526
41954195
assert(ed.type.typeSuffixes.length == 2);
41964196
}
41974197

4198+
unittest // issue #895
4199+
{
4200+
import dparse.lexer, dparse.parser, dparse.rollback_allocator;
4201+
4202+
string src = q{
4203+
private immutable bool hasPreviewIn = ((in int[256] a) { return __traits(isRef, a); })(int[256].init);
4204+
private enum Foo = int[256].init;
4205+
};
4206+
4207+
RollbackAllocator ra;
4208+
auto cf = LexerConfig("", StringBehavior.source);
4209+
auto ca = StringCache(16);
4210+
uint errorCount;
4211+
Module m = parseModule(getTokensForParser(src, cf, &ca), "", &ra, null, &errorCount);
4212+
4213+
assert(m);
4214+
assert(errorCount == 0);
4215+
assert(m.declarations.length == 2);
4216+
auto decl = m.declarations[0].variableDeclaration;
4217+
assert(decl);
4218+
auto init = decl.declarators[0].initializer;
4219+
assert(init);
4220+
assert(init.nonVoidInitializer);
4221+
assert(init.nonVoidInitializer.assignExpression);
4222+
assert(m.declarations[1].variableDeclaration);
4223+
}
4224+
41984225
unittest // Differentiate between no and empty DDOC comments, e.g. for DDOC unittests
41994226
{
42004227
import dparse.lexer, dparse.parser, dparse.rollback_allocator;

src/dparse/parser.d

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5902,6 +5902,36 @@ class Parser
59025902
* | $(LITERAL IstringLiteral)
59035903
* ;)
59045904
*/
5905+
Type parsePrimaryExpressionType()
5906+
{
5907+
auto startIndex = index;
5908+
auto node = allocator.make!Type;
5909+
if (!moreTokens)
5910+
{
5911+
error("type expected");
5912+
return null;
5913+
}
5914+
switch (current.type)
5915+
{
5916+
case tok!"const":
5917+
case tok!"immutable":
5918+
case tok!"inout":
5919+
case tok!"shared":
5920+
if (!peekIs(tok!"("))
5921+
mixin(parseNodeQ!(`node.typeConstructors`, `TypeConstructors`));
5922+
break;
5923+
default:
5924+
}
5925+
mixin(parseNodeQ!(`node.type2`, `Type2`));
5926+
StackBuffer typeSuffixes;
5927+
while (moreTokens() && currentIsOneOf(tok!"[", tok!"*", tok!"delegate", tok!"function"))
5928+
if (!typeSuffixes.put(parseTypeSuffix()))
5929+
return null;
5930+
ownArray(node.typeSuffixes, typeSuffixes);
5931+
node.tokens = tokens[startIndex .. index];
5932+
return node;
5933+
}
5934+
59055935
PrimaryExpression parsePrimaryExpression()
59065936
{
59075937
mixin(traceEnterAndExit!(__FUNCTION__));
@@ -5930,7 +5960,7 @@ class Parser
59305960
{
59315961
node.typeConstructor = advance();
59325962
mixin(tokenCheck!"(");
5933-
mixin(parseNodeQ!(`node.type`, `Type`));
5963+
mixin(parseNodeQ!(`node.type`, `PrimaryExpressionType`));
59345964
mixin(tokenCheck!")");
59355965
mixin(tokenCheck!".");
59365966
const ident = expect(tok!"identifier");
@@ -5940,7 +5970,7 @@ class Parser
59405970
}
59415971
foreach (B; BasicTypes) { case B: }
59425972
{
5943-
node.type = parseType();
5973+
node.type = parsePrimaryExpressionType();
59445974
if (currentIs(tok!"."))
59455975
{
59465976
advance();

0 commit comments

Comments
 (0)