Parse a Python string literal The challenge is to parse a string like Python does and print the contents of the string.


Input (command-line argument or stdin): a string literal (e.g. "hello") (or multiple literals, see string literal concatenation below)
Output (stdout): the contents of the string (e.g. hello)


Rules for parsing the string:


A string literal is enclosed in matching pairs of single quotes ('a'), double quotes ("a"),  triple single quotes ('''a''') or triple double quotes ("""a""").  The first reoccurrence of the type of quotes that opened the string ends the string.
Backslash escapes: \' within a string becomes ', \" becomes " and \\ becomes \.  You do not need to implement any other backslash escapes.  A backslash that is not part of an escape sequence stays a backslash.
String literal concatenation: The contents of adjacent string literals are concatenated. For example, "hello" 'world' becomes helloworld.
The input may contain spaces that are not part of any literal.
You do not need to support any other kind of whitespace, neither within nor outside literals.


Additional rules:


eval, exec and similar stuff is not allowed for parsing the literal or parts of it.
You may assume that the input is valid.
You may assume a maximum input length of 1023 characters.


Examples:


"hello"  ' world' -> hello world
"""\"""'\\\A""" -> """'\\A
( '''"""'''"""'''""" ) (without parentheses, but with spaces) -> """'''


Shortest code wins.
Perl, 54 characters

#!/usr/bin/perl -p
s/ |("""|'''|"|')((\\?.)*?)\1/$2/g;s/\\(["'\\])/$1/g


Just as I was posting this, I noticed that it's almost identical to Jan Dvorak's Ruby solution. I'm a little put out by how similar it is, in fact, but I'm going to say "Great minds think alike" and let it go at that.

This program highlights a weird corner case in counting characters in Perl scripts: By my reading, the presence of single-quotes in the script means that I need to count the -p option as two characters towards my total. Typically, when computing Perl script sizes, the initial dash character on the options is considered to be free, on the justification that it can be bundled with the -e that introduces the program proper ... but then you also have to account for any extra escapes you need to enter the script on the command-line. The single-quotes require lots of escaping, so to avoid that penalty I have to count it as a script run from a file, and therefore I get the #!/usr/bin/perl for free, but not any option characters. It's a little confusing.