Skip to content

Commit df9e7db

Browse files
committed
supported istring as TemplateSingleArgument
1 parent 35b16cf commit df9e7db

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

src/dparse/ast.d

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
module dparse.ast;
1717

1818
import dparse.lexer;
19-
import std.traits;
2019
import std.algorithm;
2120
import std.array;
2221
import std.string;
22+
import std.traits;
2323

2424
private immutable uint[TypeInfo] typeMap;
2525

@@ -1425,8 +1425,8 @@ final class Declaration : BaseNode
14251425
}
14261426
}
14271427

1428-
private import std.variant:Algebraic;
1429-
private import std.typetuple:TypeTuple;
1428+
import std.typetuple : TypeTuple;
1429+
import std.variant : Algebraic;
14301430

14311431
alias DeclarationTypes = TypeTuple!(AliasDeclaration, AliasAssign, AliasThisDeclaration,
14321432
AnonymousEnumDeclaration, AttributeDeclaration,
@@ -3483,9 +3483,10 @@ final class TemplateSingleArgument : BaseNode
34833483
{
34843484
override void accept(ASTVisitor visitor) const
34853485
{
3486-
mixin (visitIfNotNull!(token));
3486+
mixin (visitIfNotNull!(token, istring));
34873487
}
34883488
/** */ Token token;
3489+
/** */ InterpolatedString istring;
34893490
mixin OpEquals;
34903491
}
34913492

@@ -4092,7 +4093,7 @@ unittest //#365 : used to segfault
40924093
unittest // issue #398: Support extern(C++, <string expressions...>)
40934094
{
40944095
import dparse.lexer : LexerConfig;
4095-
import dparse.parser : ParserConfig, parseModule;
4096+
import dparse.parser : parseModule, ParserConfig;
40964097
import dparse.rollback_allocator : RollbackAllocator;
40974098

40984099
RollbackAllocator ra;

src/dparse/formatter.d

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3290,7 +3290,10 @@ class Formatter(Sink)
32903290
**/
32913291

32923292
put("!");
3293-
format(templateSingleArgument.token);
3293+
if (templateSingleArgument.istring)
3294+
format(templateSingleArgument.istring);
3295+
else
3296+
format(templateSingleArgument.token);
32943297
}
32953298

32963299
void format(const TemplateThisParameter templateThisParameter)
@@ -4405,5 +4408,10 @@ z /// Documentation for z
44054408
testFormatNode!(VariableDeclaration)(`T x = i" hello $(name) ";`);
44064409
testFormatNode!(VariableDeclaration)(`T x = i" hello $( name ) ";`, `T x = i" hello $(name) ";`);
44074410
testFormatNode!(VariableDeclaration)(`auto a = iq{ "}" hi };`, `auto a = iq{ "}" hi };`);
4408-
testFormatNode!(VariableDeclaration)("T x = iq{\n};", "T x = iq{\n};");
4411+
testFormatNode!(VariableDeclaration)("T x = iq{\n};");
4412+
testFormatNode!(AliasDeclaration)(`alias expr = AliasSeq!i"$(a) $(b)";`);
4413+
testFormatNode!(VariableDeclaration)(q{auto thing = i"$(b) $("$" ~ ')' ~ `"`)";});
4414+
testFormatNode!(VariableDeclaration)("auto x = i` $(b) is $(b)!`;");
4415+
testFormatNode!(VariableDeclaration)("auto x = iq{ $(b) is $(b)!};");
4416+
testFormatNode!(VariableDeclaration)("auto x = iq{{$('$')}};");
44094417
}

src/dparse/parser.d

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7254,6 +7254,7 @@ class Parser
72547254
* | $(LITERAL StringLiteral)
72557255
* | $(LITERAL IntegerLiteral)
72567256
* | $(LITERAL FloatLiteral)
7257+
* | $(LITERAL InterpolatedString)
72577258
* | $(LITERAL '_true')
72587259
* | $(LITERAL '_false')
72597260
* | $(LITERAL '_null')
@@ -7289,6 +7290,9 @@ class Parser
72897290
foreach (C; BasicTypes) { case C: }
72907291
node.token = advance();
72917292
break;
7293+
case tok!"istringLiteralStart":
7294+
node.istring = parseInterpolatedString();
7295+
break;
72927296
default:
72937297
error(`Invalid template argument. (Try enclosing in parenthesis?)`);
72947298
return null;

0 commit comments

Comments
 (0)