1 /************************************************************
2 Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
4 Permission to use, copy, modify, and distribute this
5 software and its documentation for any purpose and without
6 fee is hereby granted, provided that the above copyright
7 notice appear in all copies and that both that copyright
8 notice and this permission notice appear in supporting
9 documentation, and that the name of Silicon Graphics not be
10 used in advertising or publicity pertaining to distribution
11 of the software without specific prior written permission.
12 Silicon Graphics makes no representation about the suitability
13 of this software for any purpose. It is provided "as is"
14 without any express or implied warranty.
16 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19 GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
23 THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 ********************************************************/
28 #include "xkbcomp-priv.h"
29 #include "parser-priv.h"
31 #pragma GCC diagnostic ignored "-Wmissing-noreturn"
32 #pragma GCC diagnostic ignored "-Wredundant-decls"
33 #pragma GCC diagnostic push
35 struct scanner_extra {
36 struct xkb_context *ctx;
37 const char *file_name;
43 scanner_error_extra(struct YYLTYPE *loc, struct scanner_extra *extra,
46 #define YY_USER_ACTION { \
47 yylloc->first_line = yylineno; \
48 yylloc->last_line = yylineno; \
51 #define APPEND_S(ch) do { \
52 if (yyextra->s - yyextra->scanBuf >= sizeof(yyextra->scanBuf) - 1) \
58 %option prefix="_xkbcommon_"
60 %option extra-type="struct scanner_extra *"
61 %option bison-bridge bison-locations
63 %option nounistd noyywrap noinput nounput
64 %option never-interactive
65 %option case-insensitive
74 \" yyextra->s = yyextra->scanBuf; BEGIN(S_STR);
79 yylval->str = strdup(yyextra->scanBuf);
84 /* octal escape sequence */
87 (void) sscanf( yytext + 1, "%o", &result );
90 scanner_error_extra(yylloc, yyextra,
91 "Illegal octal escape");
99 scanner_error_extra(yylloc, yyextra,
100 "Illegal octal escape");
104 <S_STR>\\n APPEND_S('\n');
105 <S_STR>\\t APPEND_S('\t');
106 <S_STR>\\r APPEND_S('\r');
107 <S_STR>\\b APPEND_S('\b');
108 <S_STR>\\f APPEND_S('\f');
109 <S_STR>\\v APPEND_S('\v');
110 <S_STR>\\e APPEND_S('\033');
112 <S_STR>. APPEND_S(yytext[0]);
114 \<[a-zA-Z0-9_+-]+\> {
115 /* We don't want the brackets. */
116 yytext[yyleng - 1] = '\0';
118 yylval->sval = xkb_atom_intern(yyextra->ctx, yytext);
122 xkb_keymap return XKB_KEYMAP;
123 xkb_keycodes return XKB_KEYCODES;
124 xkb_types return XKB_TYPES;
125 xkb_symbols return XKB_SYMBOLS;
126 xkb_compat return XKB_COMPATMAP;
127 xkb_compat_map return XKB_COMPATMAP;
128 xkb_compatibility return XKB_COMPATMAP;
129 xkb_compatibility_map return XKB_COMPATMAP;
130 xkb_geometry return XKB_GEOMETRY;
131 xkb_semantics return XKB_SEMANTICS;
132 xkb_layout return XKB_LAYOUT;
133 include return INCLUDE;
134 override return OVERRIDE;
135 augment return AUGMENT;
136 replace return REPLACE;
137 alternate return ALTERNATE;
138 partial return PARTIAL;
139 default return DEFAULT;
140 hidden return HIDDEN;
141 virtual_modifiers return VIRTUAL_MODS;
143 interpret return INTERPRET;
144 action return ACTION_TOK;
148 modmap return MODIFIER_MAP;
149 mod_map return MODIFIER_MAP;
150 modifier_map return MODIFIER_MAP;
151 indicator return INDICATOR;
155 section return SECTION;
156 overlay return OVERLAY;
158 outline return OUTLINE;
161 virtual return VIRTUAL;
162 alphanumeric_keys return ALPHANUMERIC_KEYS;
163 modifier_keys return MODIFIER_KEYS;
164 keypad_keys return KEYPAD_KEYS;
165 function_keys return FUNCTION_KEYS;
166 alternate_group return ALTERNATE_GROUP;
168 [a-zA-Z_][a-zA-Z_0-9]* yylval->str = strdup(yytext); return IDENT;
173 yylval->num = strtoul(yytext, &end, 0);
179 yylval->num = strtod(yytext, &end);
203 <<EOF>> return END_OF_FILE;
209 #pragma GCC diagnostic pop
212 scanner_error_extra(struct YYLTYPE *loc, struct scanner_extra *extra,
215 log_err(extra->ctx, "%s: line %d of %s\n", msg,
217 extra->file_name ? extra->file_name : "(unknown)");
221 scanner_error(struct YYLTYPE *loc, void *scanner, const char *msg)
223 struct scanner_extra *extra = yyget_extra(scanner);
224 scanner_error_extra(loc, extra, msg);
228 init_scanner(yyscan_t *scanner, struct scanner_extra *extra,
229 struct xkb_context *ctx, const char *file_name)
231 memset(extra, 0, sizeof(*extra));
233 if (yylex_init_extra(extra, scanner) != 0)
237 extra->file_name = file_name;
243 clear_scanner(yyscan_t scanner)
245 yylex_destroy(scanner);
249 XkbParseString(struct xkb_context *ctx, const char *string,
250 const char *file_name)
253 struct scanner_extra extra;
254 YY_BUFFER_STATE state;
257 if (!init_scanner(&scanner, &extra, ctx, file_name))
260 state = yy_scan_string(string, scanner);
262 xkb_file = parse(ctx, scanner, NULL);
264 yy_delete_buffer(state, scanner);
265 clear_scanner(scanner);
271 * yy_scan_buffer() requires the last two bytes of \buf to be 0. These two bytes
272 * are not scanned. Other zero bytes in the buffer are scanned normally, though.
273 * Due to these terminating zeroes, \length must be greater than 2.
274 * Furthermore, the buffer must be writable and you cannot make any assumptions
275 * about it after the scanner finished.
276 * All this must be guaranteed by the caller of this function!
279 XkbParseBuffer(struct xkb_context *ctx, char *buf, size_t length,
280 const char *file_name)
283 struct scanner_extra extra;
284 YY_BUFFER_STATE state;
287 if (!init_scanner(&scanner, &extra, ctx, file_name))
291 state = yy_scan_buffer(buf, length, scanner);
293 xkb_file = parse(ctx, scanner, NULL);
294 yy_delete_buffer(state, scanner);
297 clear_scanner(scanner);
303 XkbParseFile(struct xkb_context *ctx, FILE *file,
304 const char *file_name, const char *map)
307 struct scanner_extra extra;
308 YY_BUFFER_STATE state;
311 if (!init_scanner(&scanner, &extra, ctx, file_name))
314 state = yy_create_buffer(file, YY_BUF_SIZE, scanner);
315 yy_switch_to_buffer(state, scanner);
317 xkb_file = parse(ctx, scanner, map);
319 yy_delete_buffer(state, scanner);
320 clear_scanner(scanner);