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