ID:72383
 
Resolved
Document-style strings {"..."} were parsed incorrectly when used as arguments to a #define macro.
BYOND Version:442.1020
Operating System:Windows XP Pro
Web Browser:Firefox 3.0.11
Applies to:Dream Maker
Status: Resolved (513.1503)

This issue has been resolved.
Descriptive Problem Summary:

when using {""} in the environment provided below it returns quite a few errors, but changing {""} to "" with the " inside of it changed to \" compiles correctly.
I use {""} for nearly every type of html-in dm thing I do because it makes finding special parts easier. I thought these were no different from each other, other than the fact {" "} can spread across multiple lines.


Numbered Steps to Reproduce Problem:

Use the code below.

Code Snippet (if applicable) to Reproduce Problem:
mob/Login()
. = ..()
usr << output( {"
<script type="text/javascript">
function replacetitle(v) {
document.getElementById('title').innerHTML = v;
}
function replace(v) {
document.getElementById('content').innerHTML = v;
}
</script>
<body bgcolor="#AA0000">

<!-- Begin Client Output -->
<center><b><font size=+1><div id="title">Help Guide</div></font></b></center>
<div id="content">This text can change.</div>
<!-- End Output -->

</body>
"}
,"browser1")
#define LP(str) list2params(list(str))
mob/verb/newtext()
usr << output(LP("Help Guide 101"),"browser1:replacetitle")
usr << output(LP({"<li><a href="?GettingStarted">Getting Started</a>"}),"browser1:replace")


Expected Results:

For the line to be read, and the process called.

Actual Results:

loading Feudal Times.dme
Feudal Times.dme:17:incorrect number of macro arguments
Monsters.dm:1:error: mob: missing comma ',' or right-paren ')'
HelpGuide.dm:24:error: list started here
Monsters.dm:1:error: mob: expected end of statement

Feudal Times.dmb - 3 errors, 0 warnings (double-click on an error to jump to it)


(Monsters.dm is right after HelpGuide.DM that is why the right-paren thing is showing.)

Does the problem occur:
Every time? Or how often? Everytime

When does the problem NOT occur?

See below.

Workarounds:
Instead of
usr << output(LP({"<li><a href="?GettingStarted">Getting Started</a>"}),"browser1:replace")

Use
usr << output(LP("<li><a href=\"?GettingStarted\">Getting Started</a>"),"browser1:replace")


[Edit] Updated BYOND Version, my bad I didnt see 442 on the list and just put it as 441, now I see the other option.
Huh, good find. This bug actually doesn't have to do with the output() or javascript. The compiler is screwing up expanding the macro with this combination of parameters (block quote, multiple arguments).

In this case you can just skip the macro since you are only passing one argument to the javascript, eg:

usr << output({"..."},"browser1:replace")

As a general workaround to this bug, you can either expand the macro in place, eg:

usr << output(list2params(list({"..."},[other args])),"browser1:replace")

or, better, use an intermediate var:

var/v = LP({"..."},[other args])
usr << output(LP(v),"browser1:replace")

We'll try to figure this out at some point, but this is probably the most "blackbox" section of our code.
Bringing this back up, because I've run into this problem in my code.
Code as simple as this, does not compile:
#define MY_MACRO(ARG) ARG

client/verb/Test()
MY_MACRO({"text"})
I'll take a fresh look into this and see what I can come up with. I've fixed some issues with macro expansion and this part of the code is now much less black-boxy, so this might be possible to tackle now.
Interesting.

This doesn't compile:
#define IDENTITY(x) x
var/v = IDENTITY({"foo"})


This does, and works exactly as it should:

#define IDENTITY(x) x
var/v = (IDENTITY({"foo"}))
Lummox JR resolved issue with message:
Document-style strings {"..."} were parsed incorrectly when used as arguments to a #define macro.