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.
This is ok as it's checking part of the input path which will be os specific - I've added a comment to clarify though