Convert defines to enums in xkbcomp.h
[platform/upstream/libxkbcommon.git] / src / xkbcomp / parser.y
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 #include "xkbcomp-priv.h"
29 #include "parseutils.h"
30
31 #pragma GCC diagnostic ignored "-Wredundant-decls"
32
33 extern int yylex(union YYSTYPE *val, struct YYLTYPE *loc, void *scanner);
34
35 static void
36 yyerror(struct YYLTYPE *loc, struct parser_param *param, const char *msg)
37 {
38     scanner_error(loc, param->scanner, msg);
39 }
40
41 #define scanner param->scanner
42 %}
43
44 %define         api.pure
45 %locations
46 %lex-param      { void *scanner }
47 %parse-param    { struct parser_param *param }
48
49 %token
50         END_OF_FILE     0
51         ERROR_TOK       255
52         XKB_KEYMAP      1
53         XKB_KEYCODES    2
54         XKB_TYPES       3
55         XKB_SYMBOLS     4
56         XKB_COMPATMAP   5
57         XKB_GEOMETRY    6
58         XKB_SEMANTICS   7
59         XKB_LAYOUT      8
60         INCLUDE         10
61         OVERRIDE        11
62         AUGMENT         12
63         REPLACE         13
64         ALTERNATE       14
65         VIRTUAL_MODS    20
66         TYPE            21
67         INTERPRET       22
68         ACTION_TOK      23
69         KEY             24
70         ALIAS           25
71         GROUP           26
72         MODIFIER_MAP    27
73         INDICATOR       28
74         SHAPE           29
75         KEYS            30
76         ROW             31
77         SECTION         32
78         OVERLAY         33
79         TEXT            34
80         OUTLINE         35
81         SOLID           36
82         LOGO            37
83         VIRTUAL         38
84         EQUALS          40
85         PLUS            41
86         MINUS           42
87         DIVIDE          43
88         TIMES           44
89         OBRACE          45
90         CBRACE          46
91         OPAREN          47
92         CPAREN          48
93         OBRACKET        49
94         CBRACKET        50
95         DOT             51
96         COMMA           52
97         SEMI            53
98         EXCLAM          54
99         INVERT          55
100         STRING          60
101         INTEGER         61
102         FLOAT           62
103         IDENT           63
104         KEYNAME         64
105         PARTIAL         70
106         DEFAULT         71
107         HIDDEN          72
108         ALPHANUMERIC_KEYS       73
109         MODIFIER_KEYS           74
110         KEYPAD_KEYS             75
111         FUNCTION_KEYS           76
112         ALTERNATE_GROUP         77
113
114 %right  EQUALS
115 %left   PLUS MINUS
116 %left   TIMES DIVIDE
117 %left   EXCLAM INVERT
118 %left   OPAREN
119 %start  XkbFile
120 %union  {
121         int              ival;
122         unsigned         uval;
123         int64_t          num;
124         enum xkb_file_type file_type;
125         char            *str;
126         char            keyName[XkbKeyNameLength];
127         xkb_atom_t      sval;
128         enum merge_mode merge;
129         ParseCommon     *any;
130         ExprDef         *expr;
131         VarDef          *var;
132         VModDef         *vmod;
133         InterpDef       *interp;
134         KeyTypeDef      *keyType;
135         SymbolsDef      *syms;
136         ModMapDef       *modMask;
137         GroupCompatDef  *groupCompat;
138         IndicatorMapDef *ledMap;
139         IndicatorNameDef *ledName;
140         KeycodeDef      *keyCode;
141         KeyAliasDef     *keyAlias;
142         void            *geom;
143         XkbFile         *file;
144 }
145 %type <num>     INTEGER FLOAT
146 %type <str>     IDENT STRING
147 %type <keyName> KEYNAME KeyName
148 %type <ival>    Number Integer Float SignedNumber
149 %type <merge>   MergeMode OptMergeMode
150 %type <file_type> XkbCompositeType FileType
151 %type <uval>    DoodadType Flag Flags OptFlags KeyCode
152 %type <str>     MapName OptMapName KeySym
153 %type <sval>    FieldSpec Ident Element String
154 %type <any>     DeclList Decl
155 %type <expr>    OptExprList ExprList Expr Term Lhs Terminal ArrayInit KeySyms
156 %type <expr>    OptKeySymList KeySymList Action ActionList Coord CoordList
157 %type <var>     VarDecl VarDeclList SymbolsBody SymbolsVarDecl
158 %type <vmod>    VModDecl VModDefList VModDef
159 %type <interp>  InterpretDecl InterpretMatch
160 %type <keyType> KeyTypeDecl
161 %type <syms>    SymbolsDecl
162 %type <modMask> ModMapDecl
163 %type <groupCompat> GroupCompatDecl
164 %type <ledMap>  IndicatorMapDecl
165 %type <ledName> IndicatorNameDecl
166 %type <keyCode> KeyNameDecl
167 %type <keyAlias> KeyAliasDecl
168 %type <geom>    ShapeDecl SectionDecl SectionBody SectionBodyItem RowBody RowBodyItem
169 %type <geom>    Keys Key OverlayDecl OverlayKeyList OverlayKey OutlineList OutlineInList
170 %type <geom>    DoodadDecl
171 %type <file>    XkbFile XkbMapConfigList XkbMapConfig XkbConfig
172 %type <file>    XkbCompositeMap XkbCompMapList
173 %%
174 XkbFile         :       XkbCompMapList
175                         { $$= param->rtrn= $1; }
176                 |       XkbMapConfigList
177                         { $$= param->rtrn= $1;  }
178                 |       XkbConfig
179                         { $$= param->rtrn= $1; }
180                 ;
181
182 XkbCompMapList  :       XkbCompMapList XkbCompositeMap
183                         { $$= (XkbFile *)AppendStmt(&$1->common,&$2->common); }
184                 |       XkbCompositeMap
185                         { $$= $1; }
186                 ;
187
188 XkbCompositeMap :       OptFlags XkbCompositeType OptMapName OBRACE
189                             XkbMapConfigList
190                         CBRACE SEMI
191                         {
192                             $$ = CreateXKBFile(param->ctx, $2, $3,
193                                                &$5->common, $1);
194                         }
195                 ;
196
197 XkbCompositeType:       XKB_KEYMAP      { $$= FILE_TYPE_KEYMAP; }
198                 |       XKB_SEMANTICS   { $$= FILE_TYPE_KEYMAP; }
199                 |       XKB_LAYOUT      { $$= FILE_TYPE_KEYMAP; }
200                 ;
201
202 XkbMapConfigList :      XkbMapConfigList XkbMapConfig
203                         {
204                             if (!$2)
205                                 $$= $1;
206                             else
207                                 $$= (XkbFile *)AppendStmt(&$1->common,&$2->common);
208                         }
209                 |       XkbMapConfig
210                         { $$= $1; }
211                 ;
212
213 XkbMapConfig    :       OptFlags FileType OptMapName OBRACE
214                             DeclList
215                         CBRACE SEMI
216                         {
217                             if ($2 == FILE_TYPE_GEOMETRY)
218                             {
219                                 free($3);
220                                 FreeStmt($5);
221                                 $$= NULL;
222                             }
223                             else
224                             {
225                                 $$ = CreateXKBFile(param->ctx, $2, $3, $5, $1);
226                             }
227                         }
228                 ;
229
230 XkbConfig       :       OptFlags FileType OptMapName DeclList
231                         {
232                             if ($2 == FILE_TYPE_GEOMETRY)
233                             {
234                                 free($3);
235                                 FreeStmt($4);
236                                 $$= NULL;
237                             }
238                             else
239                             {
240                                 $$ = CreateXKBFile(param->ctx, $2, $3, $4, $1);
241                             }
242                         }
243                 ;
244
245
246 FileType        :       XKB_KEYCODES            { $$= FILE_TYPE_KEYCODES; }
247                 |       XKB_TYPES               { $$= FILE_TYPE_TYPES; }
248                 |       XKB_COMPATMAP           { $$= FILE_TYPE_COMPAT; }
249                 |       XKB_SYMBOLS             { $$= FILE_TYPE_SYMBOLS; }
250                 |       XKB_GEOMETRY            { $$= FILE_TYPE_GEOMETRY; }
251                 ;
252
253 OptFlags        :       Flags                   { $$= $1; }
254                 |                               { $$= 0; }
255                 ;
256
257 Flags           :       Flags Flag              { $$= (($1)|($2)); }
258                 |       Flag                    { $$= $1; }
259                 ;
260
261 Flag            :       PARTIAL                 { $$= XkbLC_Partial; }
262                 |       DEFAULT                 { $$= XkbLC_Default; }
263                 |       HIDDEN                  { $$= XkbLC_Hidden; }
264                 |       ALPHANUMERIC_KEYS       { $$= XkbLC_AlphanumericKeys; }
265                 |       MODIFIER_KEYS           { $$= XkbLC_ModifierKeys; }
266                 |       KEYPAD_KEYS             { $$= XkbLC_KeypadKeys; }
267                 |       FUNCTION_KEYS           { $$= XkbLC_FunctionKeys; }
268                 |       ALTERNATE_GROUP         { $$= XkbLC_AlternateGroup; }
269                 ;
270
271 DeclList        :       DeclList Decl
272                         { $$= AppendStmt($1,$2); }
273                 |       { $$= NULL; }
274                 ;
275
276 Decl            :       OptMergeMode VarDecl
277                         {
278                             $2->merge= $1;
279                             $$= &$2->common;
280                         }
281                 |       OptMergeMode VModDecl
282                         {
283                             $2->merge= $1;
284                             $$= &$2->common;
285                         }
286                 |       OptMergeMode InterpretDecl
287                         {
288                             $2->merge= $1;
289                             $$= &$2->common;
290                         }
291                 |       OptMergeMode KeyNameDecl
292                         {
293                             $2->merge= $1;
294                             $$= &$2->common;
295                         }
296                 |       OptMergeMode KeyAliasDecl
297                         {
298                             $2->merge= $1;
299                             $$= &$2->common;
300                         }
301                 |       OptMergeMode KeyTypeDecl
302                         {
303                             $2->merge= $1;
304                             $$= &$2->common;
305                         }
306                 |       OptMergeMode SymbolsDecl
307                         {
308                             $2->merge= $1;
309                             $$= &$2->common;
310                         }
311                 |       OptMergeMode ModMapDecl
312                         {
313                             $2->merge= $1;
314                             $$= &$2->common;
315                         }
316                 |       OptMergeMode GroupCompatDecl
317                         {
318                             $2->merge= $1;
319                             $$= &$2->common;
320                         }
321                 |       OptMergeMode IndicatorMapDecl
322                         {
323                             $2->merge= $1;
324                             $$= &$2->common;
325                         }
326                 |       OptMergeMode IndicatorNameDecl
327                         {
328                             $2->merge= $1;
329                             $$= &$2->common;
330                         }
331                 |       OptMergeMode ShapeDecl
332                         {
333                         }
334                 |       OptMergeMode SectionDecl
335                         {
336                         }
337                 |       OptMergeMode DoodadDecl
338                         {
339                         }
340                 |       MergeMode STRING
341                         {
342                             $$= &IncludeCreate(param->ctx, $2, $1)->common;
343                             free($2);
344                         }
345                 ;
346
347 VarDecl         :       Lhs EQUALS Expr SEMI
348                         { $$= VarCreate($1,$3); }
349                 |       Ident SEMI
350                         { $$= BoolVarCreate($1,1); }
351                 |       EXCLAM Ident SEMI
352                         { $$= BoolVarCreate($2,0); }
353                 ;
354
355 KeyNameDecl     :       KeyName EQUALS KeyCode SEMI
356                         {
357                             $$ = KeycodeCreate($1, $3);
358                         }
359                 ;
360
361 KeyAliasDecl    :       ALIAS KeyName EQUALS KeyName SEMI
362                         {
363                             $$= KeyAliasCreate($2,$4);
364                         }
365                 ;
366
367 VModDecl        :       VIRTUAL_MODS VModDefList SEMI
368                         { $$= $2; }
369                 ;
370
371 VModDefList     :       VModDefList COMMA VModDef
372                         { $$= (VModDef *)AppendStmt(&$1->common,&$3->common); }
373                 |       VModDef
374                         { $$= $1; }
375                 ;
376
377 VModDef         :       Ident
378                         { $$= VModCreate($1,NULL); }
379                 |       Ident EQUALS Expr
380                         { $$= VModCreate($1,$3); }
381                 ;
382
383 InterpretDecl   :       INTERPRET InterpretMatch OBRACE
384                             VarDeclList
385                         CBRACE SEMI
386                         {
387                             $2->def= $4;
388                             $$= $2;
389                         }
390                 ;
391
392 InterpretMatch  :       KeySym PLUS Expr        
393                         { $$= InterpCreate($1, $3); }
394                 |       KeySym                  
395                         { $$= InterpCreate($1, NULL); }
396                 ;
397
398 VarDeclList     :       VarDeclList VarDecl
399                         { $$= (VarDef *)AppendStmt(&$1->common,&$2->common); }
400                 |       VarDecl
401                         { $$= $1; }
402                 ;
403
404 KeyTypeDecl     :       TYPE String OBRACE
405                             VarDeclList
406                         CBRACE SEMI
407                         { $$= KeyTypeCreate($2,$4); }
408                 ;
409
410 SymbolsDecl     :       KEY KeyName OBRACE
411                             SymbolsBody
412                         CBRACE SEMI
413                         { $$= SymbolsCreate($2,(ExprDef *)$4); }
414                 ;
415
416 SymbolsBody     :       SymbolsBody COMMA SymbolsVarDecl
417                         { $$= (VarDef *)AppendStmt(&$1->common,&$3->common); }
418                 |       SymbolsVarDecl
419                         { $$= $1; }
420                 |       { $$= NULL; }
421                 ;
422
423 SymbolsVarDecl  :       Lhs EQUALS Expr
424                         { $$= VarCreate($1,$3); }
425                 |       Lhs EQUALS ArrayInit
426                         { $$= VarCreate($1,$3); }
427                 |       Ident
428                         { $$= BoolVarCreate($1,1); }
429                 |       EXCLAM Ident
430                         { $$= BoolVarCreate($2,0); }
431                 |       ArrayInit
432                         { $$= VarCreate(NULL,$1); }
433                 ;
434
435 ArrayInit       :       OBRACKET OptKeySymList CBRACKET
436                         { $$= $2; }
437                 |       OBRACKET ActionList CBRACKET
438                         { $$= ExprCreateUnary(EXPR_ACTION_LIST, EXPR_TYPE_ACTION, $2); }
439                 ;
440
441 GroupCompatDecl :       GROUP Integer EQUALS Expr SEMI
442                         { $$= GroupCompatCreate($2,$4); }
443                 ;
444
445 ModMapDecl      :       MODIFIER_MAP Ident OBRACE ExprList CBRACE SEMI
446                         { $$= ModMapCreate($2,$4); }
447                 ;
448
449 IndicatorMapDecl:       INDICATOR String OBRACE VarDeclList CBRACE SEMI
450                         { $$= IndicatorMapCreate($2,$4); }
451                 ;
452
453 IndicatorNameDecl:      INDICATOR Integer EQUALS Expr SEMI
454                         { $$= IndicatorNameCreate($2,$4,false); }
455                 |       VIRTUAL INDICATOR Integer EQUALS Expr SEMI
456                         { $$= IndicatorNameCreate($3,$5,true); }
457                 ;
458
459 ShapeDecl       :       SHAPE String OBRACE OutlineList CBRACE SEMI
460                         { $$= NULL; }
461                 |       SHAPE String OBRACE CoordList CBRACE SEMI
462                         { $$= NULL; }
463                 ;
464
465 SectionDecl     :       SECTION String OBRACE SectionBody CBRACE SEMI
466                         { $$= NULL; }
467                 ;
468
469 SectionBody     :       SectionBody SectionBodyItem
470                         { $$= NULL;}
471                 |       SectionBodyItem
472                         { $$= NULL; }
473                 ;
474
475 SectionBodyItem :       ROW OBRACE RowBody CBRACE SEMI
476                         { $$= NULL; }
477                 |       VarDecl
478                         { FreeStmt(&$1->common); $$= NULL; }
479                 |       DoodadDecl
480                         { $$= NULL; }
481                 |       IndicatorMapDecl
482                         { FreeStmt(&$1->common); $$= NULL; }
483                 |       OverlayDecl
484                         { $$= NULL; }
485                 ;
486
487 RowBody         :       RowBody RowBodyItem
488                         { $$= NULL;}
489                 |       RowBodyItem
490                         { $$= NULL; }
491                 ;
492
493 RowBodyItem     :       KEYS OBRACE Keys CBRACE SEMI
494                         { $$= NULL; }
495                 |       VarDecl
496                         { FreeStmt(&$1->common); $$= NULL; }
497                 ;
498
499 Keys            :       Keys COMMA Key
500                         { $$= NULL; }
501                 |       Key
502                         { $$= NULL; }
503                 ;
504
505 Key             :       KeyName
506                         { $$= NULL; }
507                 |       OBRACE ExprList CBRACE
508                         { FreeStmt(&$2->common); $$= NULL; }
509                 ;
510
511 OverlayDecl     :       OVERLAY String OBRACE OverlayKeyList CBRACE SEMI
512                         { $$= NULL; }
513                 ;
514
515 OverlayKeyList  :       OverlayKeyList COMMA OverlayKey
516                         { $$= NULL; }
517                 |       OverlayKey
518                         { $$= NULL; }
519                 ;
520
521 OverlayKey      :       KeyName EQUALS KeyName
522                         { $$= NULL; }
523                 ;
524
525 OutlineList     :       OutlineList COMMA OutlineInList
526                         { $$= NULL;}
527                 |       OutlineInList
528                         { $$= NULL; }
529                 ;
530
531 OutlineInList   :       OBRACE CoordList CBRACE
532                         { $$= NULL; }
533                 |       Ident EQUALS OBRACE CoordList CBRACE
534                         { $$= NULL; }
535                 |       Ident EQUALS Expr
536                         { FreeStmt(&$3->common); $$= NULL; }
537                 ;
538
539 CoordList       :       CoordList COMMA Coord
540                         { $$= NULL; }
541                 |       Coord
542                         { $$= NULL; }
543                 ;
544
545 Coord           :       OBRACKET SignedNumber COMMA SignedNumber CBRACKET
546                         { $$= NULL; }
547                 ;
548
549 DoodadDecl      :       DoodadType String OBRACE VarDeclList CBRACE SEMI
550                         { FreeStmt(&$4->common); $$= NULL; }
551                 ;
552
553 DoodadType      :       TEXT                    { $$= 0; }
554                 |       OUTLINE                 { $$= 0; }
555                 |       SOLID                   { $$= 0; }
556                 |       LOGO                    { $$= 0; }
557                 ;
558
559 FieldSpec       :       Ident                   { $$= $1; }
560                 |       Element                 { $$= $1; }
561                 ;
562
563 Element         :       ACTION_TOK              
564                         { $$= xkb_atom_intern(param->ctx, "action"); }
565                 |       INTERPRET
566                         { $$= xkb_atom_intern(param->ctx, "interpret"); }
567                 |       TYPE
568                         { $$= xkb_atom_intern(param->ctx, "type"); }
569                 |       KEY
570                         { $$= xkb_atom_intern(param->ctx, "key"); }
571                 |       GROUP
572                         { $$= xkb_atom_intern(param->ctx, "group"); }
573                 |       MODIFIER_MAP
574                         {$$= xkb_atom_intern(param->ctx, "modifier_map");}
575                 |       INDICATOR
576                         { $$= xkb_atom_intern(param->ctx, "indicator"); }
577                 |       SHAPE   
578                         { $$= xkb_atom_intern(param->ctx, "shape"); }
579                 |       ROW     
580                         { $$= XKB_ATOM_NONE; }
581                 |       SECTION 
582                         { $$= XKB_ATOM_NONE; }
583                 |       TEXT
584                         { $$= XKB_ATOM_NONE; }
585                 ;
586
587 OptMergeMode    :       MergeMode               { $$= $1; }
588                 |                               { $$= MERGE_DEFAULT; }
589                 ;
590
591 MergeMode       :       INCLUDE                 { $$= MERGE_DEFAULT; }
592                 |       AUGMENT                 { $$= MERGE_AUGMENT; }
593                 |       OVERRIDE                { $$= MERGE_OVERRIDE; }
594                 |       REPLACE                 { $$= MERGE_REPLACE; }
595                 |       ALTERNATE
596                 {
597                     /*
598                      * This used to be MERGE_ALT_FORM. This functionality was
599                      * unused and has been removed.
600                      */
601                     $$ = MERGE_DEFAULT;
602                 }
603                 ;
604
605 OptExprList     :       ExprList                        { $$= $1; }
606                 |                               { $$= NULL; }
607                 ;
608
609 ExprList        :       ExprList COMMA Expr
610                         { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
611                 |       Expr
612                         { $$= $1; }
613                 ;
614
615 Expr            :       Expr DIVIDE Expr
616                         { $$= ExprCreateBinary(EXPR_DIVIDE,$1,$3); }
617                 |       Expr PLUS Expr
618                         { $$= ExprCreateBinary(EXPR_ADD,$1,$3); }
619                 |       Expr MINUS Expr
620                         { $$= ExprCreateBinary(EXPR_SUBTRACT,$1,$3); }
621                 |       Expr TIMES Expr
622                         { $$= ExprCreateBinary(EXPR_MULTIPLY,$1,$3); }
623                 |       Lhs EQUALS Expr
624                         { $$= ExprCreateBinary(EXPR_ASSIGN,$1,$3); }
625                 |       Term
626                         { $$= $1; }
627                 ;
628
629 Term            :       MINUS Term
630                         { $$= ExprCreateUnary(EXPR_NEGATE,$2->value_type,$2); }
631                 |       PLUS Term
632                         { $$= ExprCreateUnary(EXPR_UNARY_PLUS,$2->value_type,$2); }
633                 |       EXCLAM Term
634                         { $$= ExprCreateUnary(EXPR_NOT,EXPR_TYPE_BOOLEAN,$2); }
635                 |       INVERT Term
636                         { $$= ExprCreateUnary(EXPR_INVERT,$2->value_type,$2); }
637                 |       Lhs
638                         { $$= $1;  }
639                 |       FieldSpec OPAREN OptExprList CPAREN %prec OPAREN
640                         { $$= ActionCreate($1,$3); }
641                 |       Terminal
642                         { $$= $1;  }
643                 |       OPAREN Expr CPAREN
644                         { $$= $2;  }
645                 ;
646
647 ActionList      :       ActionList COMMA Action
648                         { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
649                 |       Action
650                         { $$= $1; }
651                 ;
652
653 Action          :       FieldSpec OPAREN OptExprList CPAREN
654                         { $$= ActionCreate($1,$3); }
655                 ;
656
657 Lhs             :       FieldSpec
658                         {
659                             ExprDef *expr;
660                             expr= ExprCreate(EXPR_IDENT, EXPR_TYPE_UNKNOWN);
661                             expr->value.str= $1;
662                             $$= expr;
663                         }
664                 |       FieldSpec DOT FieldSpec
665                         {
666                             ExprDef *expr;
667                             expr= ExprCreate(EXPR_FIELD_REF,EXPR_TYPE_UNKNOWN);
668                             expr->value.field.element= $1;
669                             expr->value.field.field= $3;
670                             $$= expr;
671                         }
672                 |       FieldSpec OBRACKET Expr CBRACKET
673                         {
674                             ExprDef *expr;
675                             expr= ExprCreate(EXPR_ARRAY_REF,EXPR_TYPE_UNKNOWN);
676                             expr->value.array.element= XKB_ATOM_NONE;
677                             expr->value.array.field= $1;
678                             expr->value.array.entry= $3;
679                             $$= expr;
680                         }
681                 |       FieldSpec DOT FieldSpec OBRACKET Expr CBRACKET
682                         {
683                             ExprDef *expr;
684                             expr= ExprCreate(EXPR_ARRAY_REF,EXPR_TYPE_UNKNOWN);
685                             expr->value.array.element= $1;
686                             expr->value.array.field= $3;
687                             expr->value.array.entry= $5;
688                             $$= expr;
689                         }
690                 ;
691
692 Terminal        :       String
693                         {
694                             ExprDef *expr;
695                             expr= ExprCreate(EXPR_VALUE,EXPR_TYPE_STRING);
696                             expr->value.str= $1;
697                             $$= expr;
698                         }
699                 |       Integer
700                         {
701                             ExprDef *expr;
702                             expr= ExprCreate(EXPR_VALUE,EXPR_TYPE_INT);
703                             expr->value.ival= $1;
704                             $$= expr;
705                         }
706                 |       Float
707                         {
708                             $$= NULL;
709                         }
710                 |       KeyName
711                         {
712                             ExprDef *expr;
713                             expr= ExprCreate(EXPR_VALUE,EXPR_TYPE_KEYNAME);
714                             strncpy(expr->value.keyName,$1,4);
715                             $$= expr;
716                         }
717                 ;
718
719 OptKeySymList   :       KeySymList                      { $$= $1; }
720                 |                                       { $$= NULL; }
721                 ;
722
723 KeySymList      :       KeySymList COMMA KeySym
724                         { $$= AppendKeysymList($1,$3); }
725                 |       KeySymList COMMA KeySyms
726                         { $$= AppendMultiKeysymList($1,$3); }
727                 |       KeySym
728                         { $$= CreateKeysymList($1); }
729                 |       KeySyms
730                         { $$= CreateMultiKeysymList($1); }
731                 ;
732
733 KeySyms         :       OBRACE KeySymList CBRACE
734                         { $$= $2; }
735                 ;
736
737 KeySym          :       IDENT   { $$= $1; }
738                 |       SECTION { $$= strdup("section"); }
739                 |       Integer         
740                         {
741                             if ($1 < 10) {      /* XK_0 .. XK_9 */
742                                 $$= malloc(2);
743                                 $$[0]= $1 + '0';
744                                 $$[1]= '\0';
745                             }
746                             else {
747                                 $$= malloc(17);
748                                 snprintf($$, 17, "0x%x", $1);
749                             }
750                         }
751                 ;
752
753 SignedNumber    :       MINUS Number    { $$= -$2; }
754                 |       Number              { $$= $1; }
755                 ;
756
757 Number          :       FLOAT           { $$= $1; }
758                 |       INTEGER         { $$= $1*XkbGeomPtsPerMM; }
759                 ;
760
761 Float           :       FLOAT           { $$= 0; }
762                 ;
763
764 Integer         :       INTEGER         { $$= $1; }
765                 ;
766
767 KeyCode         :       INTEGER         { $$= $1; }
768                 ;
769
770 KeyName         :       KEYNAME         { strncpy($$, $1, XkbKeyNameLength); }
771                 ;
772
773 Ident           :       IDENT
774                         {
775                             $$ = xkb_atom_steal(param->ctx, $1);
776                         }
777                 |       DEFAULT
778                         {
779                             $$ = xkb_atom_intern(param->ctx, "default");
780                         }
781                 ;
782
783 String          :       STRING
784                         {
785                             $$ = xkb_atom_steal(param->ctx, $1);
786                         }
787                 ;
788
789 OptMapName      :       MapName { $$= $1; }
790                 |               { $$= NULL; }
791                 ;
792
793 MapName         :       STRING  { $$= $1; }
794                 ;
795
796 %%
797
798 #undef scanner