parse s and see if x matches
Indeed, that's exactly what I plan to do
But as a part of a bigger subsystem (that would allow more flexible "context", rather like a minimalistic scripting language), which I didn't get to implement yet...
In fact, Format and family
are strictly speaking embedded schripting languages. Marcov already explained that. They have their own syntax,parser and lexer and are evaluated at runtime.
I think the C# confusion comes from "reflection", like in Java too (or for that matter FPC's RTTI)
But all of that is runtime oriented, not compile time.
This is a good excercise for Lex and Yacc:
1) let Lex tokenize the input from Format syntax()
2) Let Yacc interpret the tokenized stuff and add code templates on how it should be interpreted.
3) Generate code to implement format() from the Yacc output.
Any compiler generator can do that btw, but this is an example that is - probably?, likely? for such sub-questions - also used in FreePascal's format(). And it is a - relatively - simple one since the syntax is strictly linear.
(I prefer GOLD nowadays, but the difference is small)