For #25692 - Improved template parsing to be more robust.

Template parsing now handles more ambiguous cases where one or more static tokens may also appear in a key value.  If a value is ambiguous this will now get reported correctly in the error.
tbh this is the old code which I'm not sure is entirely needed anyway - I'll check though and change it if needed - thanks for spotting this one