One of the problems is a string like this:
The string 'this is 'a string that's got two apostrophes in it' has two apostrophes in it.
The problem is. How to tell if that's supposed to be
The string
'this is '
a string that
's got two apostrophes in it'
has two apostrophes in it.
or
The string
'this is \'a string that\'s got two apostrophes in it'
has two apostrophes in it.
or
The string \'this is \'a string that\'s got two apostrophes in it\' has two apostrophes in it.
As Drakla suggested; if you can, escape strings before embedding them into others. Otherwise you have to undo all your work to get them back out again so that you can escape them (and then put them back in again).