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