ChristmasTree-0.2.1.1: Alternative approach of 'read' that composes grammars instead of parsers.

Safe HaskellNone

Text.GRead.Derive

Description

Automatically derive Gram instances for data types.

Note! This is not a complete implementation and will not work for all datatypes.

Unsupported are

  • Multiple type arguments
  • Tuple, Function, List types
  • All primitive types (also when used in user defined types!)

Use with care.

Synopsis

Documentation

deriveGrammar :: Name -> Q [Dec]Source

Derive a Gram instance. This is a Template Haskell function. Usage example:

data T1 = C1 | C2 | C3

$(deriveGrammar ''T1)

deriveSimpleGrammar :: Name -> Q [Dec]Source

Simpler version of deriveGrammar that doesn't do binding group calculations. Use this for large types without cyclic references to other types.

For example, if you want to derive the Gram for T3 and T4 below, you will need the normal deriveGrammar.

data T3 = T3 T4 | C3
data T4 = T4 T3 | C4