Debian Codegraph @

third_party/rust/mapped_hyph/doc/mapped_hyph_format.md

raw
1 # Compiled hyphenation table format for mapped_hyph
2
3 The file is a "flattened" representation of the list of `HyphenDict` structs
4 and descendant objects used by libhyphen
5 (see [hyphen.h](https://github.com/hunspell/hyphen/blob/master/hyphen.h)).
6
7 Note that multi-byte integer types in the file are stored in _little-endian_ byte order.
8
9 ## Overall file header
10
11 The file begins with a 4-byte "signature", followed by a count of the number
12 of hyphenation levels, and an array of offsets to each hyphenation level.
13 A "level" is essentially equivalent to libhyphen's `HyphenDict`.
14
15 ### Header (size: 8 bytes + 4 * numLevels)
16 Type | Name | Description
17 -----|------|------------
18 uint8[4] | magicNumber | 4-byte file identification code: ['H', 'y', 'f', '0']
19 uint32 | numLevels | number of hyphenation levels present
20 uint32[numLevels] | levelOffset | offset from start of file to each Level
21
22 Currently, there are normally 2 hyphenation levels, as the parser/compiler will
23 generate a default first level if no NEXTLEVEL keyword is present in the pattern file.
24
25 ## Hyphenation Level
26
27 Each level of the hyphenation pattern begins with a Level header, followed by
28 the data for its states and the strings they refer to.
29 When the hyphenation machine is executed, we always begin at state offset 0
30 (from the level's stateDataBase); each transition to a new state represents the
31 target directly by its offset from stateDataBase.
32 A state offset of 0xFFFFFF is considered invalid.
33
34 Strings are represented as offsets from the level's stringDataBase; each string
35 is encoded as a one-byte length followed by `length` bytes of utf-8 data.
36 (So the maximum string length is 255 utf-8 code units; this is far more than any actual
37 hyphenation dictionary uses).
38 A string offset of 0xFFFF is considered invalid and represents an absent string.
39
40 The minimum number of characters that must be kept together at the start/end of a word,
41 or of a component of a compound (i.e. the `...Min` values) is a count of _Unicode characters_,
42 not UTF-8 code units. (Note that the presentation-form ligature characters U+FB00 'ff' through U+FB06 'st'
43 are counted as 2 or 3 characters for this purpose.)
44
45 ### Level (size: 16 bytes + state data + string data, padded to a 4-byte boundary)
46 Type | Name | Description
47 -----|------|------------
48 uint32 | stateDataBase | offset from beginning of Level to start of level's State data
49 uint32 | stringDataBase | offset from beginning of Level to start of level's packed String data
50 uint16 | noHyphenStringOffset | from level's stringDataBase
51 uint16 | noHyphenCount | number of (NUL-separated) strings in the nohyphen string
52 uint8 | leftHyphenMin | minimum number of characters kept together at start of word
53 uint8 | rightHyphenMin | minimum number of characters kept together at end of word
54 uint8 | compoundLeftHyphenMin | minimum number of characters kept together at start of second component of a compound
55 uint8 | compoundRightHyphenMin | minimum number of characters kept together at end of first component of a compound
56
57 ## State
58
59 Each state, referred to by its offset from the level's stateDataBase, consists of a header
60 followed by an array of transitions for input bytes that need to be matched in this state.
61 The state also records a fallback state offset, which is the transition to be taken
62 if the next input byte does not match any of the transition records.
63
64 If a match string is present (i.e. `matchStringOffset` is not 0xFFFF), it is a string of hyphenation values
65 (encoded as ASCII digits '0'..'9') to be applied at the current position in the word.
66
67 ### StateHeader (size: 8 bytes)
68 Type | Name | Description
69 -----|------|------------
70 uint32 | fallbackStateOffset | (from level's stateDataBase)
71 uint16 | matchStringOffset | (from level's stringDataBase)
72 uint8 | numTransitions | count of Transitions that follow the StateHeader and optional StateHeaderExtension
73 uint8 | isExtended | if non-zero, the StateHeader is immediately followed by a StateHeaderExtension
74
75 If the `isExtended` flag in the state header is set, this state includes a potential spelling change
76 and there is an extended form of the header present before the array of transitions.
77 (Note that extended states with spelling-change rules are not yet supported by the mapped_hyph engine;
78 none of the hyphenation dictionaries shipped with Firefox includes such rules.)
79
80 ### StateHeaderExtension (size: 4 bytes)
81 Type | Name | Description
82 -----|------|------------
83 uint16 | replacementStringOffset | (from level's stringDataBase) the replacement string
84 int8 | replacementIndex | index of the byte position (relative to current position in the word) at which the spelling replacement should happen
85 int8 | replacementCut | number of bytes to cut from the original word when making the replacement
86
87 ## Transitions
88
89 The state's transitions are encoded as an array of Transition records, each corresponding to an input byte
90 and providing the offset of the new state. The transitions for each state are sorted by ascending value of input byte
91 (although in practice there are usually only a few valid transitions, and so a binary search does not seem to be
92 worthwhile).
93
94 ### Transition (size: 4 bytes)
95 Type | Name | Description
96 -----|------|------------
97 uint24 | newStateOffset | (from level's stateDataBase)
98 uint8 | inputByte | the input byte (utf-8 code unit) for this transition