Introduce xkb_keycode_t for keycodes
[platform/upstream/libxkbcommon.git] / src / xkbcomp / xkbscan.l
1 /************************************************************
2  Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
3
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.
15
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.
24
25  ********************************************************/
26
27 %{
28
29 #include <stdio.h>
30 #include <ctype.h>
31 #include <X11/Xos.h>
32
33 #include "tokens.h"
34 #include "utils.h"
35 #include "parseutils.h"
36
37 const char *yystring;
38 char *scanFile = NULL;
39 int lineNum = 0;
40
41 int scanInt;
42 unsigned long scanULong;
43
44 static char *s;
45 char scanBuf[1024];
46
47 #define BUFSIZE 4096
48
49 %}
50
51 %option case-insensitive
52 %option yylineno
53 %option noyywrap
54
55 %x S_STR S_KEY
56
57 %%
58
59 "//"[^\n]*
60 "#"[^\n]*
61
62 \"                      s = scanBuf; BEGIN(S_STR);
63 \<                      s = scanBuf; BEGIN(S_KEY);
64
65 <S_STR>\"               BEGIN(INITIAL); *s = '\0'; return STRING;
66 <S_KEY>\>               BEGIN(INITIAL); *s = '\0'; return KEYNAME;
67
68 <S_STR,S_KEY>\\[0-7]{1,3} {
69                         /* octal escape sequence */
70                         int result;
71
72                         (void) sscanf( yytext + 1, "%o", &result );
73
74                         if (result > 0xff) {
75                             fprintf(stderr, "Illegal octal escape %s\n", yytext);
76                             return ERROR_TOK;
77                         }
78
79                         *s++ = result;
80                     }
81
82 <S_STR,S_KEY>\\[0-9]+ {
83                         fprintf(stderr, "Illegal octal escape %s\n", yytext);
84                         return ERROR_TOK;
85                     }
86
87 <S_STR,S_KEY>\\n        *s++ = '\n';
88 <S_STR,S_KEY>\\t        *s++ = '\t';
89 <S_STR,S_KEY>\\r        *s++ = '\r';
90 <S_STR,S_KEY>\\b        *s++ = '\b';
91 <S_STR,S_KEY>\\f        *s++ = '\f';
92 <S_STR,S_KEY>\\v        *s++ = '\v';
93 <S_STR,S_KEY>\\e        *s++ = '\033';
94
95 <S_STR,S_KEY>.          *s++ = yytext[0];
96
97 xkb_keymap              return XKB_KEYMAP;
98 xkb_keycodes            return XKB_KEYCODES;
99 xkb_types               return XKB_TYPES;
100 xkb_symbols             return XKB_SYMBOLS;
101 xkb_compat              return XKB_COMPATMAP;
102 xkb_compat_map          return XKB_COMPATMAP;
103 xkb_compatibility       return XKB_COMPATMAP;
104 xkb_compatibility_map   return XKB_COMPATMAP;
105 xkb_geometry            return XKB_GEOMETRY;
106 xkb_semantics           return XKB_SEMANTICS;
107 xkb_layout              return XKB_LAYOUT;
108 include                 return INCLUDE;
109 override                return OVERRIDE;
110 augment                 return AUGMENT;
111 replace                 return REPLACE;
112 alternate               return ALTERNATE;
113 partial                 return PARTIAL;
114 default                 return DEFAULT;
115 hidden                  return HIDDEN;
116 virtual_modifiers       return VIRTUAL_MODS;
117 type                    return TYPE;
118 interpret               return INTERPRET;
119 action                  return ACTION_TOK;
120 key                     return KEY;
121 alias                   return ALIAS;
122 group                   return GROUP;
123 modmap                  return MODIFIER_MAP;
124 mod_map                 return MODIFIER_MAP;
125 modifier_map            return MODIFIER_MAP;
126 indicator               return INDICATOR;
127 shape                   return SHAPE;
128 row                     return ROW;
129 keys                    return KEYS;
130 section                 return SECTION;
131 overlay                 return OVERLAY;
132 text                    return TEXT;
133 outline                 return OUTLINE;
134 solid                   return SOLID;
135 logo                    return LOGO;
136 virtual                 return VIRTUAL;
137 alphanumeric_keys       return ALPHANUMERIC_KEYS;
138 modifier_keys           return MODIFIER_KEYS;
139 keypad_keys             return KEYPAD_KEYS;
140 function_keys           return FUNCTION_KEYS;
141 alternate_group         return ALTERNATE_GROUP;
142
143 [a-zA-Z_][a-zA-Z_0-9]*  memcpy(scanBuf, yytext, yyleng + 1); return IDENT;
144
145 0x[a-fA-F0-9]+          |
146 [0-9]+                  {
147                             char *end;
148                             scanInt = strtol(yytext, &end, 0);
149                             scanULong = strtoul(yytext, &end, 0);
150
151                             return INTEGER;
152                         }
153 [0-9]+\.[0-9]+ {
154                             char *end;
155                             scanInt = strtod(yytext, &end) * XkbGeomPtsPerMM;
156
157                             return FLOAT;
158                         }
159
160 "="                     return EQUALS;
161 "+"                     return PLUS;
162 "-"                     return MINUS;
163 "/"                     return DIVIDE;
164 "*"                     return TIMES;
165 "{"                     return OBRACE;
166 "}"                     return CBRACE;
167 "("                     return OPAREN;
168 ")"                     return CPAREN;
169 "["                     return OBRACKET;
170 "]"                     return CBRACKET;
171 "."                     return DOT;
172 ","                     return COMMA;
173 ";"                     return SEMI;
174 "!"                     return EXCLAM;
175 "~"                     return INVERT;
176
177 [ \t\r\n\v]+            
178
179 <<EOF>>                 return END_OF_FILE;
180
181 .                       return ERROR_TOK;
182
183 %%
184
185 void
186 yyerror(const char *s)
187 {
188     if (warningLevel>0) {
189         (void)fprintf(stderr,"%s: line %d of %s\n",s,yylineno,
190                                         (scanFile?scanFile:"(unknown)"));
191         if ((warningLevel>3))
192             (void)fprintf(stderr,"last scanned symbol is: %s\n",scanBuf);
193     }
194     return;
195 }
196
197 void setScanState(char *file, int lineno)
198 {
199   yylineno = 1;
200   if (scanFile)
201     free(scanFile);
202   scanFile = strdup(file);
203 }
204
205 int
206 XKBParseString(const char *string, XkbFile ** pRtrn)
207 {
208     YY_BUFFER_STATE state;
209
210     *pRtrn = NULL;
211     if (string == NULL)
212         return 1;
213
214     state = yy_scan_string(string);
215     rtrnValue = NULL;
216     if (yyparse() != 0)
217         return 0;
218
219     yy_delete_buffer(state);
220     yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
221     *pRtrn = rtrnValue;
222     CheckDefaultMap(rtrnValue);
223     rtrnValue = NULL;
224
225     return 1;
226 }
227
228 int
229 XKBParseFile(FILE * file, XkbFile ** pRtrn)
230 {
231     if (file)
232     {
233         yyin = file;
234         yystring = NULL;
235         rtrnValue = NULL;
236         if (yyparse() == 0)
237         {
238             *pRtrn = rtrnValue;
239             CheckDefaultMap(rtrnValue);
240             rtrnValue = NULL;
241             return 1;
242         }
243         *pRtrn = NULL;
244         return 0;
245     }
246     *pRtrn = NULL;
247     return 1;
248 }