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.
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
\. 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,
- 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.
execand 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.
"hello" ' world'->
( '''"""'''"""'''""" )(without parentheses, but with spaces) ->
Shortest code wins.