Can I use grammar to enforce a coding style?

Can I leverage an existing language grammar file for a language to enforce a certain coding style as it is typed?

For example:

If someone types any of the keywords:

if endif and not...

They will be correctly cased:

If EndIf And Not

I can already identify these keywords through existing syntax highlighting grammar.