{ # Place this block at the top of the grammar, before any rules. sub dequote_double { local $_ = (@_ ? $_[0] : $_); $_ = substr($_, 1, -1); s/\\(.)/$1/sg; } # Like in Perl. # Unlike bash. sub dequote_single { local $_ = (@_ ? $_[0] : $_); $_ = substr($_, 1, -1); s/\\(['\\])/$1/sg; } } string : /"(?:[^\\"]|\\.)*"/ {[ $item[0], dequote_double($item[1]) ]} | /'(?:[^\\']|\\.)*'/ {[ $item[0], dequote_single($item[1]) ]}