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

fix #warn choking on apostrophe #1478

Merged
merged 4 commits into from
Oct 11, 2023
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
10 changes: 10 additions & 0 deletions Content.Tests/DMProject/Tests/Preprocessor/Pragma/warning_quote.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#define CONDITION_TRUE

#ifdef CONDITION_TRUE
#warn Oh no you're gonna have a bad time
#endif

/proc/RunTest()
return

#warn end of file
15 changes: 2 additions & 13 deletions DMCompiler/Compiler/DMPreprocessor/DMPreprocessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -582,21 +582,10 @@ private void HandleErrorOrWarningDirective(Token token) {
if (!VerifyDirectiveUsage(token))
return;

StringBuilder messageBuilder = new StringBuilder();

Token messageToken = GetNextToken(true);
while (messageToken.Type != TokenType.EndOfFile) {
if (messageToken.Type == TokenType.Newline) break;

messageBuilder.Append(messageToken.Text);
messageToken = GetNextToken();
}

string message = messageBuilder.ToString();
if (token.Type == TokenType.DM_Preproc_Error) {
DMCompiler.Emit(WarningCode.ErrorDirective, token.Location, message);
DMCompiler.Emit(WarningCode.ErrorDirective, token.Location, token.Text);
} else {
DMCompiler.Emit(WarningCode.WarningDirective, token.Location, message);
DMCompiler.Emit(WarningCode.WarningDirective, token.Location, token.Text);
}
}

Expand Down
24 changes: 22 additions & 2 deletions DMCompiler/Compiler/DMPreprocessor/DMPreprocessorLexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,28 @@ protected override Token ParseNextToken() {
private bool TryMacroKeyword(string text, out Token token) {
switch (text) {
case "warn":
case "warning": token = CreateToken(TokenType.DM_Preproc_Warning, "#warn"); break;
case "warning": {
StringBuilder message = new StringBuilder();

while (GetCurrent() is not '\0' and not '\n') {
message.Append(GetCurrent());
Advance();
}

token = CreateToken(TokenType.DM_Preproc_Warning, "#warn" + message.ToString());
break;
}
case "error": {
StringBuilder message = new StringBuilder();

while (GetCurrent() is not '\0' and not '\n') {
message.Append(GetCurrent());
Advance();
}

token = CreateToken(TokenType.DM_Preproc_Error, "#error" + message.ToString());
break;
}
case "include": token = CreateToken(TokenType.DM_Preproc_Include, "#include"); break;
case "define": token = CreateToken(TokenType.DM_Preproc_Define, "#define"); break;
case "undef": token = CreateToken(TokenType.DM_Preproc_Undefine, "#undef"); break;
Expand All @@ -438,7 +459,6 @@ private bool TryMacroKeyword(string text, out Token token) {
case "elif": token = CreateToken(TokenType.DM_Preproc_Elif, "#elif"); break;
case "else": token = CreateToken(TokenType.DM_Preproc_Else, "#else"); break;
case "endif": token = CreateToken(TokenType.DM_Preproc_EndIf, "#endif"); break;
case "error": token = CreateToken(TokenType.DM_Preproc_Error, "#error"); break;
//OD-specific directives
case "pragma": token = CreateToken(TokenType.DM_Preproc_Pragma, "#pragma"); break;
default:
Expand Down
Loading