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