robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
7a1bad27ca
master
1#pragma once 2 3#include <stdbool.h> 4#include <stdint.h> 5 6#include "nvim/buffer_defs.h" 7 8enum { 9/// Assume max. word len is this many bytes. 10/// Some places assume a word length fits in a byte, thus it can't be above 255. 11MAXWLEN = 254 , 12}; 13 14enum {MAXREGIONS = 8 , };///< Number of regions supported. 15 16/// Type used for indexes in the word tree need to be at least 4 bytes. If int 17/// is 8 bytes we could use something smaller, but what? 18typedef int idx_T ; 19 20#define SPL_FNAME_TMPL "%s.%s.spl" 21#define SPL_FNAME_ADD ".add." 22#define SPL_FNAME_ASCII ".ascii." 23 24/// Flags used for a word. Only the lowest byte can be used, the region byte 25/// comes above it. 26enum { 27WF_REGION = 0x01 ,///< region byte follows 28WF_ONECAP = 0x02 ,///< word with one capital (or all capitals) 29WF_ALLCAP = 0x04 ,///< word must be all capitals 30WF_RARE = 0x08 ,///< rare word 31WF_BANNED = 0x10 ,///< bad word 32WF_AFX = 0x20 ,///< affix ID follows 33WF_FIXCAP = 0x40 ,///< keep-case word, allcap not allowed 34WF_KEEPCAP = 0x80 ,///< keep-case word 35WF_CAPMASK = (WF_ONECAP |WF_ALLCAP |WF_KEEPCAP |WF_FIXCAP ), 36}; 37 38/// for <flags2>, shifted up one byte to be used in wn_flags 39enum { 40WF_HAS_AFF = 0x0100 ,///< word includes affix 41WF_NEEDCOMP = 0x0200 ,///< word only valid in compound 42WF_NOSUGGEST = 0x0400 ,///< word not to be suggested 43WF_COMPROOT = 0x0800 ,///< already compounded word, COMPOUNDROOT 44WF_NOCOMPBEF = 0x1000 ,///< no compounding before this word 45WF_NOCOMPAFT = 0x2000 ,///< no compounding after this word 46}; 47 48/// flags for <pflags> 49enum { 50WFP_RARE = 0x01 ,///< rare prefix 51WFP_NC = 0x02 ,///< prefix is not combining 52WFP_UP = 0x04 ,///< to-upper prefix 53WFP_COMPPERMIT = 0x08 ,///< prefix with COMPOUNDPERMITFLAG 54WFP_COMPFORBID = 0x10 ,///< prefix with COMPOUNDFORBIDFLAG 55}; 56 57/// Flags for postponed prefixes in "sl_pidxs". Must be above affixID (one 58/// byte) and prefcondnr (two bytes). 59enum { 60WF_RAREPFX = WFP_RARE <<24 ,///< rare postponed prefix 61WF_PFX_NC = WFP_NC <<24 ,///< non-combining postponed prefix 62WF_PFX_UP = WFP_UP <<24 ,///< to-upper postponed prefix 63WF_PFX_COMPPERMIT = WFP_COMPPERMIT <<24 ,///< postponed prefix with COMPOUNDPERMITFLAG 64WF_PFX_COMPFORBID = WFP_COMPFORBID <<24 ,///< postponed prefix with COMPOUNDFORBIDFLAG 65}; 66 67/// flags for <compoptions> 68enum { 69COMP_CHECKDUP = 1 ,///< CHECKCOMPOUNDDUP 70COMP_CHECKREP = 2 ,///< CHECKCOMPOUNDREP 71COMP_CHECKCASE = 4 ,///< CHECKCOMPOUNDCASE 72COMP_CHECKTRIPLE = 8 ,///< CHECKCOMPOUNDTRIPLE 73}; 74 75/// Info from "REP", "REPSAL" and "SAL" entries in ".aff" file used in si_rep, 76/// si_repsal, sl_rep, and si_sal. Not for sl_sal! 77/// One replacement: from "ft_from" to "ft_to". 78typedef struct { 79char * ft_from ; 80char * ft_to ; 81}fromto_T ; 82 83/// Info from "SAL" entries in ".aff" file used in sl_sal. 84/// The info is split for quick processing by spell_soundfold(). 85/// Note that "sm_oneof" and "sm_rules" point into sm_lead. 86typedef struct { 87char * sm_lead ;///< leading letters 88int sm_leadlen ;///< length of "sm_lead" 89char * sm_oneof ;///< letters from () or NULL 90char * sm_rules ;///< rules like ^, $, priority 91char * sm_to ;///< replacement. 92int * sm_lead_w ;///< wide character copy of "sm_lead" 93int * sm_oneof_w ;///< wide character copy of "sm_oneof" 94int * sm_to_w ;///< wide character copy of "sm_to" 95}salitem_T ; 96 97typedef int salfirst_T ; 98 99/// Values for SP_*ERROR are negative, positive values are used by 100/// read_cnt_string(). 101enum { 102SP_TRUNCERROR = -1 ,///< spell file truncated error 103SP_FORMERROR = -2 ,///< format error in spell file 104SP_OTHERERROR = -3 ,///< other error while reading spell file 105}; 106 107/// Structure used to store words and other info for one language, loaded from 108/// a .spl file. 109/// The main access is through the tree in "sl_fbyts/sl_fidxs", storing the 110/// case-folded words. "sl_kbyts/sl_kidxs" is for keep-case words. 111/// 112/// The "byts" array stores the possible bytes in each tree node, preceded by 113/// the number of possible bytes, sorted on byte value: 114/// <len> <byte1> <byte2> ... 115/// The "idxs" array stores the index of the child node corresponding to the 116/// byte in "byts". 117/// Exception: when the byte is zero, the word may end here and "idxs" holds 118/// the flags, region mask and affixID for the word. There may be several 119/// zeros in sequence for alternative flag/region/affixID combinations. 120typedef struct slang_S slang_T ; 121 122struct slang_S { 123slang_T * sl_next ;///< next language 124char * sl_name ;///< language name "en", "en.rare", "nl", etc. 125char * sl_fname ;///< name of .spl file 126bool sl_add ;///< true if it's a .add file. 127 128uint8_t * sl_fbyts ;///< case-folded word bytes 129int sl_fbyts_len ;///< length of sl_fbyts 130idx_T * sl_fidxs ;///< case-folded word indexes 131uint8_t * sl_kbyts ;///< keep-case word bytes 132idx_T * sl_kidxs ;///< keep-case word indexes 133uint8_t * sl_pbyts ;///< prefix tree word bytes 134idx_T * sl_pidxs ;///< prefix tree word indexes 135 136char * sl_info ;///< infotext string or NULL 137 138/// table with up to 8 region names plus NUL 139char sl_regions [MAXREGIONS * 2 + 1 ]; 140 141char * sl_midword ;///< MIDWORD string or NULL 142 143hashtab_T sl_wordcount ;///< hashtable with word count, wordcount_T 144 145int sl_compmax ;///< COMPOUNDWORDMAX (default: MAXWLEN) 146int sl_compminlen ;///< COMPOUNDMIN (default: 0) 147int sl_compsylmax ;///< COMPOUNDSYLMAX (default: MAXWLEN) 148int sl_compoptions ;///< COMP_* flags 149garray_T sl_comppat ;///< CHECKCOMPOUNDPATTERN items 150regprog_T * sl_compprog ;///< COMPOUNDRULE turned into a regexp progrm 151///< (NULL when no compounding) 152uint8_t * sl_comprules ;///< all COMPOUNDRULE concatenated (or NULL) 153uint8_t * sl_compstartflags ;///< flags for first compound word 154uint8_t * sl_compallflags ;///< all flags for compound words 155bool sl_nobreak ;///< When true: no spaces between words 156char * sl_syllable ;///< SYLLABLE repeatable chars or NULL 157garray_T sl_syl_items ;///< syllable items 158 159int sl_prefixcnt ;///< number of items in "sl_prefprog" 160regprog_T ** sl_prefprog ;///< table with regprogs for prefixes 161 162garray_T sl_rep ;///< list of fromto_T entries from REP lines 163int16_t sl_rep_first [256 ];///< indexes where byte first appears, -1 if there is none 164garray_T sl_sal ;///< list of salitem_T entries from SAL lines 165salfirst_T sl_sal_first [256 ];///< indexes where byte first appears, -1 if there is none 166bool sl_followup ;///< SAL followup 167bool sl_collapse ;///< SAL collapse_result 168bool sl_rem_accents ;///< SAL remove_accents 169bool sl_sofo ;///< SOFOFROM and SOFOTO instead of SAL items: 170///< "sl_sal_first" maps chars 171///< "sl_sal" is a list of wide char lists. 172garray_T sl_repsal ;///< list of fromto_T entries from REPSAL lines 173int16_t sl_repsal_first [256 ];///< sl_rep_first for REPSAL lines 174bool sl_nosplitsugs ;///< don't suggest splitting a word 175bool sl_nocompoundsugs ;///< don't suggest compounding 176 177// Info from the .sug file. Loaded on demand. 178time_t sl_sugtime ;///< timestamp for .sug file 179uint8_t * sl_sbyts ;///< soundfolded word bytes 180int sl_sbyts_len ;///< length of sl_sbyts 181idx_T * sl_sidxs ;///< soundfolded word indexes 182buf_T * sl_sugbuf ;///< buffer with word number table 183bool sl_sugloaded ;///< true when .sug file was loaded or failed to load 184 185bool sl_has_map ;///< true, if there is a MAP line 186hashtab_T sl_map_hash ;///< MAP for multi-byte chars 187int sl_map_array [256 ];///< MAP for first 256 chars 188hashtab_T sl_sounddone ;///< table with soundfolded words that have 189///< handled, see add_sound_suggest() 190}; 191 192/// Structure used in "b_langp", filled from 'spelllang'. 193typedef struct { 194slang_T * lp_slang ;///< info for this language 195slang_T * lp_sallang ;///< language used for sound folding or NULL 196slang_T * lp_replang ;///< language used for REP items or NULL 197int lp_region ;///< bitmask for region or REGION_ALL 198}langp_T ; 199 200#define LANGP_ENTRY (ga ,i ) (((langp_T *)(ga).ga_data) + (i)) 201 202#define VIMSUGMAGIC "VIMsug" // string at start of Vim .sug file 203#define VIMSUGMAGICL 6 204#define VIMSUGVERSION 1 205 206enum {REGION_ALL = 0xff , };///< word valid in all regions 207 208/// The tables used for recognizing word characters according to spelling. 209/// These are only used for the first 256 characters of 'encoding'. 210typedef struct { 211bool st_isw [256 ];///< flags: is word char 212bool st_isu [256 ];///< flags: is uppercase char 213uint8_t st_fold [256 ];///< chars: folded case 214uint8_t st_upper [256 ];///< chars: upper case 215}spelltab_T ; 216 217/// Values for "what" argument of spell_add_word() 218typedef enum { 219SPELL_ADD_GOOD = 0 , 220SPELL_ADD_BAD = 1 , 221SPELL_ADD_RARE = 2 , 222}SpellAddType ; 223 224typedef struct { 225uint16_t wc_count ;///< nr of times word was seen 226char wc_word [];///< word 227}wordcount_T ; 228 229#define WC_KEY_OFF offsetof(wordcount_T, wc_word) 230#define HI2WC (hi ) ((wordcount_T *)((hi)->hi_key - WC_KEY_OFF)) 231enum {MAXWORDCOUNT = 0xffff , };