%{ /* * Copyright © 2023 Nick Bowler * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include "cdecl-internal.h" #include "parse.h" static const struct keyword *in_word_set(); %} %readonly-tables %language=ANSI-C /* Note: the following options enable gperf-wordwrap.awk to do its thing */ %define word-array-name wordlist_wrapped %null-strings %struct-type struct keyword { uint_least8_t token; }; %% _Bool, PACK_TOKEN(T_BOOL ) _Complex, PACK_TOKEN(T_COMPLEX ) _Imaginary, PACK_TOKEN(T_IMAGINARY) auto, PACK_TOKEN(T_AUTO ) char, PACK_TOKEN(T_CHAR ) const, PACK_TOKEN(T_CONST ) double, PACK_TOKEN(T_DOUBLE ) enum, PACK_TOKEN(T_ENUM ) extern, PACK_TOKEN(T_EXTERN ) float, PACK_TOKEN(T_FLOAT ) inline, PACK_TOKEN(T_INLINE ) int, PACK_TOKEN(T_INT ) long, PACK_TOKEN(T_LONG ) register, PACK_TOKEN(T_REGISTER ) restrict, PACK_TOKEN(T_RESTRICT ) short, PACK_TOKEN(T_SHORT ) signed, PACK_TOKEN(T_SIGNED ) static, PACK_TOKEN(T_STATIC ) struct, PACK_TOKEN(T_STRUCT ) typedef, PACK_TOKEN(T_TYPEDEF ) union, PACK_TOKEN(T_UNION ) unsigned, PACK_TOKEN(T_UNSIGNED ) void, PACK_TOKEN(T_VOID ) volatile, PACK_TOKEN(T_VOLATILE ) # english keywords array, PACK_TOKEN(T_ARRAY ) | 0x80 as, PACK_TOKEN(T_AS ) | 0x80 declare, PACK_TOKEN(T_DECLARE ) | 0x80 function, PACK_TOKEN(T_FUNCTION ) | 0x80 of, PACK_TOKEN(T_OF ) | 0x80 pointer, PACK_TOKEN(T_POINTER ) | 0x80 returning, PACK_TOKEN(T_RETURNING) | 0x80 to, PACK_TOKEN(T_TO ) | 0x80 type, PACK_TOKEN(T_TYPE ) | 0x80 variable-length, PACK_TOKEN(T_VLA ) | 0x80 %% int cdecl__to_keyword(const char *s, int len, int english_mode) { const struct keyword *k; if ((k = in_word_set(s, len))) { unsigned x = (k->token & 0x7fu); if (english_mode || !(k->token & ~0x7fu)) { return UNPACK_TOKEN(x); } } return T_IDENT; } static const char *wordlist_func(const struct keyword *k) { unsigned x = k->token & 0x7f; if (!x) return NULL; return cdecl__token_name(UNPACK_TOKEN(x)); }