Construct is a DSL implemented in Python used to describe data structures (binary and text). After you describe the data structure, the designer can analyze and build it for you. What is good ("DRY", "Declarative", "Denotational-Semantics" ...)
Usage example:
itxt_info = Struct("itxt_info",
CString("keyword"),
UBInt8("compression_flag"),
compression_method,
CString("language_tag"),
CString("translated_keyword"),
OnDemand(
Field("text",
lambda ctx: ctx._.length - (len(ctx.keyword) +
len(ctx.language_tag) + len(ctx.translated_keyword) + 5),
),
),
)
I need such a tool for Haskell and I wonder if something like that exists.
I know:
- Data.Binary: user implements parsing and building separately
- Parsec: Only for parsing? For text only?
I think you need to use Template Haskell for this?