diff --git a/Content.Tests/DMProject/Tests/Preprocessor/Pragma/warning_quote.dm b/Content.Tests/DMProject/Tests/Preprocessor/Pragma/warning_quote.dm new file mode 100644 index 0000000000..f8bdfd60be --- /dev/null +++ b/Content.Tests/DMProject/Tests/Preprocessor/Pragma/warning_quote.dm @@ -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 \ No newline at end of file diff --git a/DMCompiler/Compiler/DMPreprocessor/DMPreprocessor.cs b/DMCompiler/Compiler/DMPreprocessor/DMPreprocessor.cs index efb59a9a4d..f5c7c48782 100644 --- a/DMCompiler/Compiler/DMPreprocessor/DMPreprocessor.cs +++ b/DMCompiler/Compiler/DMPreprocessor/DMPreprocessor.cs @@ -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); } } diff --git a/DMCompiler/Compiler/DMPreprocessor/DMPreprocessorLexer.cs b/DMCompiler/Compiler/DMPreprocessor/DMPreprocessorLexer.cs index 6cd410bcf8..d4f4785748 100644 --- a/DMCompiler/Compiler/DMPreprocessor/DMPreprocessorLexer.cs +++ b/DMCompiler/Compiler/DMPreprocessor/DMPreprocessorLexer.cs @@ -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; @@ -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: