Tutorial: Create a Hexinator grammar from scratch for ASE files
This tutorial shows you step by step how to create a new grammar in Hexinator. The grammar will finally allow to decode an ASE file automatically:
ASE is a good example because it contains some typical patterns found in other file formats as well:
- A file header contains a file signature and information how to interpret the rest of the file
- ASE consists of multiple blocks, the number of blocks is contained in the header
- All blocks share a common structure however differ depending on color type
In order to follow the tutorial please download the following ASE file:
You can walk forward and backward in the tutorial with the buttons located at the bottom.
Some background information about Adobe Swatch Exchange files
Adobe Swatch Exchange consist of multiple blocks. The number of blocks is contained in the file header. Each block contains a color which may be of type RGB, CMYK or something else.
How does the grammar created in the tutorial work?
The number of blocks to be parsed are taken from the NumberOfBlocks element. You can use expressions for lengths and repeat counts that contain names of number elements. The names of the number elements shouldn’t contain spaces!
Interesting in this grammar is the usage of inherited structures. A parent structure “Color” contains the elements common to all color structures, be it for RGB, CMYK or others. This means you don’t have to create those elements again and again for each specific color type. The elements of the specific (RGB, …) structures inherited from the Color structure inherit the properties of their parents. Thus you have to set the “Must match” flag only once in the Model element of Color.
In many grammars you need to select one of multiple structures, depending on the file contents. This works by having
- A “switch/case” structure (in this tutorial the “Color” in the “Block” structure)
- This structure must have the element order set to “Variable”
- Structure references to all structures that may appear
- The referenced structures must have at least for one element the “Must match” flag set that lets the element (and enclosing structure) only match if one of the fixed values matches the file contents