adds template for function grammar, fixes issue #422
more principled patch for issue #422 with tests