Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interpolated Strings #7988

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions src/dmd/cli.d
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,8 @@ dmd -cov -unittest myprog.d
"list all variables going into thread local storage"),
Feature("vmarkdown", "vmarkdown",
"list instances of Markdown replacements in Ddoc"),
Feature("interpolate", "interpolateStrings",
"enable interpolated string support via the 'i' prefix on string literals"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be preview - not a transition - as this allows earlier merging.

];

/// Returns all available reverts
Expand Down
2 changes: 1 addition & 1 deletion src/dmd/globals.d
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ struct Param

bool markdown; // enable Markdown replacements in Ddoc
bool vmarkdown; // list instances of Markdown replacements in Ddoc

bool interpolateStrings;// Enable interpolated string support via the 'i' prefix on string literals
bool showGaggedErrors; // print gagged errors anyway
bool printErrorContext; // print errors with the error context (the error line in the source file)
bool manual; // open browser on compiler manual
Expand Down
1 change: 1 addition & 0 deletions src/dmd/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ struct Param
CppStdRevision cplusplus; // version of C++ name mangling to support
bool markdown; // enable Markdown replacements in Ddoc
bool vmarkdown; // list instances of Markdown replacements in Ddoc
bool interpolateStrings;// Enable interpolated string support via the 'i' prefix on string literals
bool showGaggedErrors; // print gagged errors anyway
bool printErrorContext; // print errors with the error context (the error line in the source file)
bool manual; // open browser on compiler manual
Expand Down
48 changes: 46 additions & 2 deletions src/dmd/lexer.d
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ class Lexer
bool commentToken; // comments are TOK.comment's
int lastDocLine; // last line of previous doc comment

private DiagnosticReporter diagnosticReporter;
protected DiagnosticReporter diagnosticReporter;

private Token* tokenFreelist;

Expand Down Expand Up @@ -646,6 +646,44 @@ class Lexer
case '"':
escapeStringConstant(t);
return;
case 'i':
if (global.params.interpolateStrings)
{
if (p[1] == 'r')
{
if (p[2] == '"')
{
p += 2;
goto case '`';
}
}
else if (p[1] == '`')
{
p++;
goto case '`';
}
else if (p[1] == '"')
{
p++;
goto case '"';
}
else if (p[1] == 'q')
{
if (p[2] == '"')
{
p += 2;
delimitedStringConstant(t);
return;
}
else if (p[2] == '{')
{
p += 2;
tokenStringConstant(t);
return;
}
}
}
goto case_ident;
case 'a':
case 'b':
case 'c':
Expand All @@ -654,7 +692,6 @@ class Lexer
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
Expand Down Expand Up @@ -2491,6 +2528,13 @@ class Lexer
diagnosticReporter.error(loc, format, args);
va_end(args);
}
// temporary hack to handle r-value references to Loc structures
pragma(inline)
final void error(T...)(const Loc loc, const(char)* format, T args)
{
error(loc, format, args);
}


final void errorSupplemental(const ref Loc loc, const(char)* format, ...)
{
Expand Down
Loading