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