Problem: Given a string that may or may not have “” or ‘’ at either end, in unknown quantities, for example
'const char`
"const char"
"'const char*'"
How does one remove them all? I initially started thinking about lists, how to match the first and last elements etc etc and then…somewhere…split_string crept into the back of my mind.
Awesome! I have no idea what magic and sorcery is happening behind the scenes and quite frankly, right, I don’t give a damn! (Very bad paraphrase from Gone With The Wind).
In the end, it was a “code smell” that needed attention. I had blindly taken the PHP code as my guide from version 1. The real solution has been to re-do the AST parsing DCG rules so that the presence of a type after a “/” is formally identified and dealt with.
The format is “VARNAME/TYPE” and because my tokeniser doesn’t care about whitespace, you can tokenise that as VARNAME/ TYPE i.e. two tokens. All I had to do was extend the rules and it all works so nicely now, I even was able to delete cruft that was splitting the token around “/” and then looking for types etc.
To quote that old TV advert, “One instinctively knows when something is right”.