Posted by kelvSYC on 7-21-2014
Hot on the heels of the SimCity 2000 grammar, here’s a quick Generic IFF grammar. This grammar is made so that anyone can extend it to create their own grammar for file formats based on IFF. (It is possible to use it on RIFF and AIFF-based grammars as well, but I plan on having more specialized grammars for those.)
The IFF grammar defines a few simple data structures.
- The Base IFF Chunk is the abstract base structure for all chunks, including builtin chunk types FORM, LIST, PROP, and CAT. To create your own, simply subclass this one, override the “Type ID” by inserting a fixed value, and fill in the contents of the internal Chunk Data structure.
- The FORM Chunk, CAT Chunk, LIST Chunk, and PROP Chunk are all abstract base structures for their specific builtin chunk types. Subclass them and modify their chunk data where necessary. However, do not delete the Form Type or Contents Type fields in the Chunk Data, as these are part of the standard.
- The FORM/LIST/CAT structure matches only FORM, LIST, and CAT Chunks. You may replace them if necessary with something more specific.
- Since FORM Chunk contents may be any user defined chunk type or FORM/LIST/CAT, consider subclassing FORM Chunk Contents for your needs.
- The Properties substructure of the PROP Chunk Data is meant to hold all and only user-defined chunks.
The intent of the generic IFF Grammar is that it should be able to parse in its entirety any generic IFF documents, with a specific focus on FORM, CAT, LIST, and PROP Chunks (all four of which are reserved). It does not cover the reserved FOR1-FOR9, LIS1-LIS9, and CAT1-CAT9 chunks, nor any commonly found chunk data types.
- This grammar does not check that FORM type IDs are not all lowercase letters and is not punctuation-free.
- The structure references are better represented as a script so as to better do parsing for embedded structures and the like, but script support is still a bit iffy at the present type.
- Be aware that some past versions do not handle structure inheritance properly, and may not respect overrides on fixed values or the deletion of members in a subclass. If this is an issue, feel free to extend the Base IFF Chunk instead.
- There is no support for the “four spaces” chunk type.
Changelist after the break.
Changes for 7-21-14:
- Initial release. Hopefully this is a good enough start for most people…