Cleanup and followup to PR #17830: parsing changes

Prevents breaking down `$name` tokens into separate `$` and `name`.
Reports unknown macro variables.

Fixes #18775
Fixes #18839