1 /************************************************************
2 Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
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.
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.
25 ********************************************************/
96 #include "parseutils.h"
98 #include <X11/keysym.h>
121 GroupCompatDef *groupCompat;
122 IndicatorMapDef *ledMap;
123 IndicatorNameDef *ledName;
125 KeyAliasDef *keyAlias;
131 OverlayKeyDef *olKey;
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
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 <shape> ShapeDecl
156 %type <section> SectionDecl
157 %type <row> SectionBody SectionBodyItem
158 %type <key> RowBody RowBodyItem Keys Key
159 %type <overlay> OverlayDecl
160 %type <olKey> OverlayKeyList OverlayKey
161 %type <outline> OutlineList OutlineInList
162 %type <doodad> DoodadDecl
163 %type <file> XkbFile XkbMapConfigList XkbMapConfig XkbConfig
164 %type <file> XkbCompositeMap XkbCompMapList
166 XkbFile : XkbCompMapList
167 { $$= rtrnValue= $1; }
169 { $$= rtrnValue= $1; }
171 { $$= rtrnValue= $1; }
174 XkbCompMapList : XkbCompMapList XkbCompositeMap
175 { $$= (XkbFile *)AppendStmt(&$1->common,&$2->common); }
180 XkbCompositeMap : OptFlags XkbCompositeType OptMapName OBRACE
183 { $$= CreateXKBFile($2,$3,&$5->common,$1); }
186 XkbCompositeType: XKB_KEYMAP { $$= XkmKeymapFile; }
187 | XKB_SEMANTICS { $$= XkmSemanticsFile; }
188 | XKB_LAYOUT { $$= XkmLayoutFile; }
191 XkbMapConfigList : XkbMapConfigList XkbMapConfig
192 { $$= (XkbFile *)AppendStmt(&$1->common,&$2->common); }
197 XkbMapConfig : OptFlags FileType OptMapName OBRACE
200 { $$= CreateXKBFile($2,$3,$5,$1); }
203 XkbConfig : OptFlags FileType OptMapName DeclList
204 { $$= CreateXKBFile($2,$3,$4,$1); }
208 FileType : XKB_KEYCODES { $$= XkmKeyNamesIndex; }
209 | XKB_TYPES { $$= XkmTypesIndex; }
210 | XKB_COMPATMAP { $$= XkmCompatMapIndex; }
211 | XKB_SYMBOLS { $$= XkmSymbolsIndex; }
212 | XKB_GEOMETRY { $$= XkmGeometryIndex; }
215 OptFlags : Flags { $$= $1; }
219 Flags : Flags Flag { $$= (($1)|($2)); }
223 Flag : PARTIAL { $$= XkbLC_Partial; }
224 | DEFAULT { $$= XkbLC_Default; }
225 | HIDDEN { $$= XkbLC_Hidden; }
226 | ALPHANUMERIC_KEYS { $$= XkbLC_AlphanumericKeys; }
227 | MODIFIER_KEYS { $$= XkbLC_ModifierKeys; }
228 | KEYPAD_KEYS { $$= XkbLC_KeypadKeys; }
229 | FUNCTION_KEYS { $$= XkbLC_FunctionKeys; }
230 | ALTERNATE_GROUP { $$= XkbLC_AlternateGroup; }
233 DeclList : DeclList Decl
234 { $$= AppendStmt($1,$2); }
238 Decl : OptMergeMode VarDecl
240 $2->merge= StmtSetMerge(&$2->common,$1);
243 | OptMergeMode VModDecl
245 $2->merge= StmtSetMerge(&$2->common,$1);
248 | OptMergeMode InterpretDecl
250 $2->merge= StmtSetMerge(&$2->common,$1);
253 | OptMergeMode KeyNameDecl
255 $2->merge= StmtSetMerge(&$2->common,$1);
258 | OptMergeMode KeyAliasDecl
260 $2->merge= StmtSetMerge(&$2->common,$1);
263 | OptMergeMode KeyTypeDecl
265 $2->merge= StmtSetMerge(&$2->common,$1);
268 | OptMergeMode SymbolsDecl
270 $2->merge= StmtSetMerge(&$2->common,$1);
273 | OptMergeMode ModMapDecl
275 $2->merge= StmtSetMerge(&$2->common,$1);
278 | OptMergeMode GroupCompatDecl
280 $2->merge= StmtSetMerge(&$2->common,$1);
283 | OptMergeMode IndicatorMapDecl
285 $2->merge= StmtSetMerge(&$2->common,$1);
288 | OptMergeMode IndicatorNameDecl
290 $2->merge= StmtSetMerge(&$2->common,$1);
293 | OptMergeMode ShapeDecl
295 $2->merge= StmtSetMerge(&$2->common,$1);
298 | OptMergeMode SectionDecl
300 $2->merge= StmtSetMerge(&$2->common,$1);
303 | OptMergeMode DoodadDecl
305 $2->merge= StmtSetMerge(&$2->common,$1);
310 if ($1==MergeAltForm) {
311 yyerror("cannot use 'alternate' to include other maps");
312 $$= &IncludeCreate(scanBuf,MergeDefault)->common;
315 $$= &IncludeCreate(scanBuf,$1)->common;
320 VarDecl : Lhs EQUALS Expr SEMI
321 { $$= VarCreate($1,$3); }
323 { $$= BoolVarCreate($1,1); }
325 { $$= BoolVarCreate($2,0); }
328 KeyNameDecl : KeyName EQUALS KeyCode SEMI
332 def= KeycodeCreate($1,$3);
339 KeyAliasDecl : ALIAS KeyName EQUALS KeyName SEMI
342 def= KeyAliasCreate($2,$4);
349 VModDecl : VIRTUAL_MODS VModDefList SEMI
353 VModDefList : VModDefList COMMA VModDef
354 { $$= (VModDef *)AppendStmt(&$1->common,&$3->common); }
360 { $$= VModCreate($1,NULL); }
362 { $$= VModCreate($1,$3); }
365 InterpretDecl : INTERPRET InterpretMatch OBRACE
374 InterpretMatch : KeySym PLUS Expr
375 { $$= InterpCreate($1, $3); }
377 { $$= InterpCreate($1, NULL); }
380 VarDeclList : VarDeclList VarDecl
381 { $$= (VarDef *)AppendStmt(&$1->common,&$2->common); }
386 KeyTypeDecl : TYPE String OBRACE
389 { $$= KeyTypeCreate($2,$4); }
392 SymbolsDecl : KEY KeyName OBRACE
395 { $$= SymbolsCreate($2,(ExprDef *)$4); free($2); }
398 SymbolsBody : SymbolsBody COMMA SymbolsVarDecl
399 { $$= (VarDef *)AppendStmt(&$1->common,&$3->common); }
405 SymbolsVarDecl : Lhs EQUALS Expr
406 { $$= VarCreate($1,$3); }
407 | Lhs EQUALS ArrayInit
408 { $$= VarCreate($1,$3); }
410 { $$= BoolVarCreate($1,1); }
412 { $$= BoolVarCreate($2,0); }
414 { $$= VarCreate(NULL,$1); }
417 ArrayInit : OBRACKET OptKeySymList CBRACKET
419 | OBRACKET ActionList CBRACKET
420 { $$= ExprCreateUnary(ExprActionList,TypeAction,$2); }
423 GroupCompatDecl : GROUP Integer EQUALS Expr SEMI
424 { $$= GroupCompatCreate($2,$4); }
427 ModMapDecl : MODIFIER_MAP Ident OBRACE ExprList CBRACE SEMI
428 { $$= ModMapCreate($2,$4); }
431 IndicatorMapDecl: INDICATOR String OBRACE VarDeclList CBRACE SEMI
432 { $$= IndicatorMapCreate($2,$4); }
435 IndicatorNameDecl: INDICATOR Integer EQUALS Expr SEMI
436 { $$= IndicatorNameCreate($2,$4,False); }
437 | VIRTUAL INDICATOR Integer EQUALS Expr SEMI
438 { $$= IndicatorNameCreate($3,$5,True); }
441 ShapeDecl : SHAPE String OBRACE OutlineList CBRACE SEMI
442 { $$= ShapeDeclCreate($2,(OutlineDef *)&$4->common); }
443 | SHAPE String OBRACE CoordList CBRACE SEMI
445 OutlineDef *outlines;
446 outlines= OutlineCreate(None,$4);
447 $$= ShapeDeclCreate($2,outlines);
451 SectionDecl : SECTION String OBRACE SectionBody CBRACE SEMI
452 { $$= SectionDeclCreate($2,$4); }
455 SectionBody : SectionBody SectionBodyItem
456 { $$=(RowDef *)AppendStmt(&$1->common,&$2->common);}
461 SectionBodyItem : ROW OBRACE RowBody CBRACE SEMI
462 { $$= RowDeclCreate($3); }
464 { $$= (RowDef *)$1; }
466 { $$= (RowDef *)$1; }
468 { $$= (RowDef *)$1; }
470 { $$= (RowDef *)$1; }
473 RowBody : RowBody RowBodyItem
474 { $$=(KeyDef *)AppendStmt(&$1->common,&$2->common);}
479 RowBodyItem : KEYS OBRACE Keys CBRACE SEMI
482 { $$= (KeyDef *)$1; }
485 Keys : Keys COMMA Key
486 { $$=(KeyDef *)AppendStmt(&$1->common,&$3->common);}
492 { $$= KeyDeclCreate($1,NULL); }
493 | OBRACE ExprList CBRACE
494 { $$= KeyDeclCreate(NULL,$2); }
497 OverlayDecl : OVERLAY String OBRACE OverlayKeyList CBRACE SEMI
498 { $$= OverlayDeclCreate($2,$4); }
501 OverlayKeyList : OverlayKeyList COMMA OverlayKey
503 $$= (OverlayKeyDef *)
504 AppendStmt(&$1->common,&$3->common);
510 OverlayKey : KeyName EQUALS KeyName
511 { $$= OverlayKeyCreate($1,$3); }
514 OutlineList : OutlineList COMMA OutlineInList
515 { $$=(OutlineDef *)AppendStmt(&$1->common,&$3->common);}
520 OutlineInList : OBRACE CoordList CBRACE
521 { $$= OutlineCreate(None,$2); }
522 | Ident EQUALS OBRACE CoordList CBRACE
523 { $$= OutlineCreate($1,$4); }
525 { $$= OutlineCreate($1,$3); }
528 CoordList : CoordList COMMA Coord
529 { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
534 Coord : OBRACKET SignedNumber COMMA SignedNumber CBRACKET
537 expr= ExprCreate(ExprCoord,TypeUnknown);
538 expr->value.coord.x= $2;
539 expr->value.coord.y= $4;
544 DoodadDecl : DoodadType String OBRACE VarDeclList CBRACE SEMI
545 { $$= DoodadCreate($1,$2,$4); }
548 DoodadType : TEXT { $$= XkbTextDoodad; }
549 | OUTLINE { $$= XkbOutlineDoodad; }
550 | SOLID { $$= XkbSolidDoodad; }
551 | LOGO { $$= XkbLogoDoodad; }
554 FieldSpec : Ident { $$= $1; }
555 | Element { $$= $1; }
559 { $$= xkb_intern_atom("action"); }
561 { $$= xkb_intern_atom("interpret"); }
563 { $$= xkb_intern_atom("type"); }
565 { $$= xkb_intern_atom("key"); }
567 { $$= xkb_intern_atom("group"); }
569 {$$= xkb_intern_atom("modifier_map");}
571 { $$= xkb_intern_atom("indicator"); }
573 { $$= xkb_intern_atom("shape"); }
575 { $$= xkb_intern_atom("row"); }
577 { $$= xkb_intern_atom("section"); }
579 { $$= xkb_intern_atom("text"); }
582 OptMergeMode : MergeMode { $$= $1; }
583 | { $$= MergeDefault; }
586 MergeMode : INCLUDE { $$= MergeDefault; }
587 | AUGMENT { $$= MergeAugment; }
588 | OVERRIDE { $$= MergeOverride; }
589 | REPLACE { $$= MergeReplace; }
590 | ALTERNATE { $$= MergeAltForm; }
593 OptExprList : ExprList { $$= $1; }
597 ExprList : ExprList COMMA Expr
598 { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
603 Expr : Expr DIVIDE Expr
604 { $$= ExprCreateBinary(OpDivide,$1,$3); }
606 { $$= ExprCreateBinary(OpAdd,$1,$3); }
608 { $$= ExprCreateBinary(OpSubtract,$1,$3); }
610 { $$= ExprCreateBinary(OpMultiply,$1,$3); }
612 { $$= ExprCreateBinary(OpAssign,$1,$3); }
618 { $$= ExprCreateUnary(OpNegate,$2->type,$2); }
620 { $$= ExprCreateUnary(OpUnaryPlus,$2->type,$2); }
622 { $$= ExprCreateUnary(OpNot,TypeBoolean,$2); }
624 { $$= ExprCreateUnary(OpInvert,$2->type,$2); }
627 | FieldSpec OPAREN OptExprList CPAREN %prec OPAREN
628 { $$= ActionCreate($1,$3); }
635 ActionList : ActionList COMMA Action
636 { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
641 Action : FieldSpec OPAREN OptExprList CPAREN
642 { $$= ActionCreate($1,$3); }
648 expr= ExprCreate(ExprIdent,TypeUnknown);
652 | FieldSpec DOT FieldSpec
655 expr= ExprCreate(ExprFieldRef,TypeUnknown);
656 expr->value.field.element= $1;
657 expr->value.field.field= $3;
660 | FieldSpec OBRACKET Expr CBRACKET
663 expr= ExprCreate(ExprArrayRef,TypeUnknown);
664 expr->value.array.element= None;
665 expr->value.array.field= $1;
666 expr->value.array.entry= $3;
669 | FieldSpec DOT FieldSpec OBRACKET Expr CBRACKET
672 expr= ExprCreate(ExprArrayRef,TypeUnknown);
673 expr->value.array.element= $1;
674 expr->value.array.field= $3;
675 expr->value.array.entry= $5;
683 expr= ExprCreate(ExprValue,TypeString);
690 expr= ExprCreate(ExprValue,TypeInt);
691 expr->value.ival= $1;
697 expr= ExprCreate(ExprValue,TypeFloat);
698 expr->value.ival= $1;
704 expr= ExprCreate(ExprValue,TypeKeyName);
705 memset(expr->value.keyName,0,5);
706 strncpy(expr->value.keyName,$1,4);
712 OptKeySymList : KeySymList { $$= $1; }
716 KeySymList : KeySymList COMMA KeySym
717 { $$= AppendKeysymList($1,$3); }
719 { $$= CreateKeysymList($1); }
722 KeySym : IDENT { $$= strdup(scanBuf); }
723 | SECTION { $$= strdup("section"); }
726 if ($1 < 10) { /* XK_0 .. XK_9 */
733 snprintf($$, 17, "%x", $1);
738 SignedNumber : MINUS Number { $$= -$2; }
742 Number : FLOAT { $$= scanInt; }
743 | INTEGER { $$= scanInt*XkbGeomPtsPerMM; }
746 Float : FLOAT { $$= scanInt; }
749 Integer : INTEGER { $$= scanInt; }
752 KeyCode : INTEGER { $$= scanULong; }
755 KeyName : KEYNAME { $$= strdup(scanBuf); }
758 Ident : IDENT { $$= xkb_intern_atom(scanBuf); }
759 | DEFAULT { $$= xkb_intern_atom("default"); }
762 String : STRING { $$= xkb_intern_atom(scanBuf); }
765 OptMapName : MapName { $$= $1; }
769 MapName : STRING { $$= strdup(scanBuf); }