Encode/decode of canonical grammars to/from JSON/YAML
A version of `readPGF` where the user can handle reading files