- Take a line of input (function arguments or stdin, etc.).
- Remove comments in it, where a comment starts and ends with
"
. - Do not remove comments in string literals, which start and end with
'
. String literals do not contain escapes, because smalltalk has nice, easily lexable syntax ;). - Output this string.
- The number of
"
s not inside strings and the number of'
s not in comments in the input are both guaranteed to be even. - Because removing comments makes programs more golfy, this is code-golf: shortest code per language wins.
Examples
input => output
123 => 123
1"2"3 => 13
1""23 => 123
'12' => '12'
'1"2'3"" => '1"2'3
'1"2"3' => '1"2"3'
a"1'2'3"a => aa
"a"b"c" => b
'a'b'c' => 'a'b'c'
a'"'b'"'c => a'"'b'"'c
a"'"b"'"c => abc
Regex is boring as usual. Try something new, or answer in smalltalk!