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"
99 #include <X11/keysym.h>
122 GroupCompatDef *groupCompat;
123 IndicatorMapDef *ledMap;
124 IndicatorNameDef *ledName;
126 KeyAliasDef *keyAlias;
132 OverlayKeyDef *olKey;
137 %type <ival> Number Integer Float SignedNumber
138 %type <uval> XkbCompositeType FileType MergeMode OptMergeMode
139 %type <uval> DoodadType Flag Flags OptFlags
140 %type <str> KeyName MapName OptMapName KeySym
141 %type <sval> FieldSpec Ident Element String
142 %type <any> DeclList Decl
143 %type <expr> OptExprList ExprList Expr Term Lhs Terminal ArrayInit
144 %type <expr> OptKeySymList KeySymList Action ActionList Coord CoordList
145 %type <var> VarDecl VarDeclList SymbolsBody SymbolsVarDecl
146 %type <vmod> VModDecl VModDefList VModDef
147 %type <interp> InterpretDecl InterpretMatch
148 %type <keyType> KeyTypeDecl
149 %type <syms> SymbolsDecl
150 %type <modMask> ModMapDecl
151 %type <groupCompat> GroupCompatDecl
152 %type <ledMap> IndicatorMapDecl
153 %type <ledName> IndicatorNameDecl
154 %type <keyName> KeyNameDecl
155 %type <keyAlias> KeyAliasDecl
156 %type <shape> ShapeDecl
157 %type <section> SectionDecl
158 %type <row> SectionBody SectionBodyItem
159 %type <key> RowBody RowBodyItem Keys Key
160 %type <overlay> OverlayDecl
161 %type <olKey> OverlayKeyList OverlayKey
162 %type <outline> OutlineList OutlineInList
163 %type <doodad> DoodadDecl
164 %type <file> XkbFile XkbMapConfigList XkbMapConfig XkbConfig
165 %type <file> XkbCompositeMap XkbCompMapList
167 XkbFile : XkbCompMapList
168 { $$= rtrnValue= $1; }
170 { $$= rtrnValue= $1; }
172 { $$= rtrnValue= $1; }
175 XkbCompMapList : XkbCompMapList XkbCompositeMap
176 { $$= (XkbFile *)AppendStmt(&$1->common,&$2->common); }
181 XkbCompositeMap : OptFlags XkbCompositeType OptMapName OBRACE
184 { $$= CreateXKBFile($2,$3,&$5->common,$1); }
187 XkbCompositeType: XKB_KEYMAP { $$= XkmKeymapFile; }
188 | XKB_SEMANTICS { $$= XkmSemanticsFile; }
189 | XKB_LAYOUT { $$= XkmLayoutFile; }
192 XkbMapConfigList : XkbMapConfigList XkbMapConfig
193 { $$= (XkbFile *)AppendStmt(&$1->common,&$2->common); }
198 XkbMapConfig : OptFlags FileType OptMapName OBRACE
201 { $$= CreateXKBFile($2,$3,$5,$1); }
204 XkbConfig : OptFlags FileType OptMapName DeclList
205 { $$= CreateXKBFile($2,$3,$4,$1); }
209 FileType : XKB_KEYCODES { $$= XkmKeyNamesIndex; }
210 | XKB_TYPES { $$= XkmTypesIndex; }
211 | XKB_COMPATMAP { $$= XkmCompatMapIndex; }
212 | XKB_SYMBOLS { $$= XkmSymbolsIndex; }
213 | XKB_GEOMETRY { $$= XkmGeometryIndex; }
216 OptFlags : Flags { $$= $1; }
220 Flags : Flags Flag { $$= (($1)|($2)); }
224 Flag : PARTIAL { $$= XkbLC_Partial; }
225 | DEFAULT { $$= XkbLC_Default; }
226 | HIDDEN { $$= XkbLC_Hidden; }
227 | ALPHANUMERIC_KEYS { $$= XkbLC_AlphanumericKeys; }
228 | MODIFIER_KEYS { $$= XkbLC_ModifierKeys; }
229 | KEYPAD_KEYS { $$= XkbLC_KeypadKeys; }
230 | FUNCTION_KEYS { $$= XkbLC_FunctionKeys; }
231 | ALTERNATE_GROUP { $$= XkbLC_AlternateGroup; }
234 DeclList : DeclList Decl
235 { $$= AppendStmt($1,$2); }
239 Decl : OptMergeMode VarDecl
241 $2->merge= StmtSetMerge(&$2->common,$1);
244 | OptMergeMode VModDecl
246 $2->merge= StmtSetMerge(&$2->common,$1);
249 | OptMergeMode InterpretDecl
251 $2->merge= StmtSetMerge(&$2->common,$1);
254 | OptMergeMode KeyNameDecl
256 $2->merge= StmtSetMerge(&$2->common,$1);
259 | OptMergeMode KeyAliasDecl
261 $2->merge= StmtSetMerge(&$2->common,$1);
264 | OptMergeMode KeyTypeDecl
266 $2->merge= StmtSetMerge(&$2->common,$1);
269 | OptMergeMode SymbolsDecl
271 $2->merge= StmtSetMerge(&$2->common,$1);
274 | OptMergeMode ModMapDecl
276 $2->merge= StmtSetMerge(&$2->common,$1);
279 | OptMergeMode GroupCompatDecl
281 $2->merge= StmtSetMerge(&$2->common,$1);
284 | OptMergeMode IndicatorMapDecl
286 $2->merge= StmtSetMerge(&$2->common,$1);
289 | OptMergeMode IndicatorNameDecl
291 $2->merge= StmtSetMerge(&$2->common,$1);
294 | OptMergeMode ShapeDecl
296 $2->merge= StmtSetMerge(&$2->common,$1);
299 | OptMergeMode SectionDecl
301 $2->merge= StmtSetMerge(&$2->common,$1);
304 | OptMergeMode DoodadDecl
306 $2->merge= StmtSetMerge(&$2->common,$1);
311 if ($1==MergeAltForm) {
312 yyerror("cannot use 'alternate' to include other maps");
313 $$= &IncludeCreate(scanBuf,MergeDefault)->common;
316 $$= &IncludeCreate(scanBuf,$1)->common;
321 VarDecl : Lhs EQUALS Expr SEMI
322 { $$= VarCreate($1,$3); }
324 { $$= BoolVarCreate($1,1); }
326 { $$= BoolVarCreate($2,0); }
329 KeyNameDecl : KeyName EQUALS Expr SEMI
333 def= KeycodeCreate($1,$3);
340 KeyAliasDecl : ALIAS KeyName EQUALS KeyName SEMI
343 def= KeyAliasCreate($2,$4);
350 VModDecl : VIRTUAL_MODS VModDefList SEMI
354 VModDefList : VModDefList COMMA VModDef
355 { $$= (VModDef *)AppendStmt(&$1->common,&$3->common); }
361 { $$= VModCreate($1,NULL); }
363 { $$= VModCreate($1,$3); }
366 InterpretDecl : INTERPRET InterpretMatch OBRACE
375 InterpretMatch : KeySym PLUS Expr
376 { $$= InterpCreate($1, $3); }
378 { $$= InterpCreate($1, NULL); }
381 VarDeclList : VarDeclList VarDecl
382 { $$= (VarDef *)AppendStmt(&$1->common,&$2->common); }
387 KeyTypeDecl : TYPE String OBRACE
390 { $$= KeyTypeCreate($2,$4); }
393 SymbolsDecl : KEY KeyName OBRACE
396 { $$= SymbolsCreate($2,(ExprDef *)$4); }
399 SymbolsBody : SymbolsBody COMMA SymbolsVarDecl
400 { $$= (VarDef *)AppendStmt(&$1->common,&$3->common); }
406 SymbolsVarDecl : Lhs EQUALS Expr
407 { $$= VarCreate($1,$3); }
408 | Lhs EQUALS ArrayInit
409 { $$= VarCreate($1,$3); }
411 { $$= BoolVarCreate($1,1); }
413 { $$= BoolVarCreate($2,0); }
415 { $$= VarCreate(NULL,$1); }
418 ArrayInit : OBRACKET OptKeySymList CBRACKET
420 | OBRACKET ActionList CBRACKET
421 { $$= ExprCreateUnary(ExprActionList,TypeAction,$2); }
424 GroupCompatDecl : GROUP Integer EQUALS Expr SEMI
425 { $$= GroupCompatCreate($2,$4); }
428 ModMapDecl : MODIFIER_MAP Ident OBRACE ExprList CBRACE SEMI
429 { $$= ModMapCreate($2,$4); }
432 IndicatorMapDecl: INDICATOR String OBRACE VarDeclList CBRACE SEMI
433 { $$= IndicatorMapCreate($2,$4); }
436 IndicatorNameDecl: INDICATOR Integer EQUALS Expr SEMI
437 { $$= IndicatorNameCreate($2,$4,False); }
438 | VIRTUAL INDICATOR Integer EQUALS Expr SEMI
439 { $$= IndicatorNameCreate($3,$5,True); }
442 ShapeDecl : SHAPE String OBRACE OutlineList CBRACE SEMI
443 { $$= ShapeDeclCreate($2,(OutlineDef *)&$4->common); }
444 | SHAPE String OBRACE CoordList CBRACE SEMI
446 OutlineDef *outlines;
447 outlines= OutlineCreate(None,$4);
448 $$= ShapeDeclCreate($2,outlines);
452 SectionDecl : SECTION String OBRACE SectionBody CBRACE SEMI
453 { $$= SectionDeclCreate($2,$4); }
456 SectionBody : SectionBody SectionBodyItem
457 { $$=(RowDef *)AppendStmt(&$1->common,&$2->common);}
462 SectionBodyItem : ROW OBRACE RowBody CBRACE SEMI
463 { $$= RowDeclCreate($3); }
465 { $$= (RowDef *)$1; }
467 { $$= (RowDef *)$1; }
469 { $$= (RowDef *)$1; }
471 { $$= (RowDef *)$1; }
474 RowBody : RowBody RowBodyItem
475 { $$=(KeyDef *)AppendStmt(&$1->common,&$2->common);}
480 RowBodyItem : KEYS OBRACE Keys CBRACE SEMI
483 { $$= (KeyDef *)$1; }
486 Keys : Keys COMMA Key
487 { $$=(KeyDef *)AppendStmt(&$1->common,&$3->common);}
493 { $$= KeyDeclCreate($1,NULL); }
494 | OBRACE ExprList CBRACE
495 { $$= KeyDeclCreate(NULL,$2); }
498 OverlayDecl : OVERLAY String OBRACE OverlayKeyList CBRACE SEMI
499 { $$= OverlayDeclCreate($2,$4); }
502 OverlayKeyList : OverlayKeyList COMMA OverlayKey
504 $$= (OverlayKeyDef *)
505 AppendStmt(&$1->common,&$3->common);
511 OverlayKey : KeyName EQUALS KeyName
512 { $$= OverlayKeyCreate($1,$3); }
515 OutlineList : OutlineList COMMA OutlineInList
516 { $$=(OutlineDef *)AppendStmt(&$1->common,&$3->common);}
521 OutlineInList : OBRACE CoordList CBRACE
522 { $$= OutlineCreate(None,$2); }
523 | Ident EQUALS OBRACE CoordList CBRACE
524 { $$= OutlineCreate($1,$4); }
526 { $$= OutlineCreate($1,$3); }
529 CoordList : CoordList COMMA Coord
530 { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
535 Coord : OBRACKET SignedNumber COMMA SignedNumber CBRACKET
538 expr= ExprCreate(ExprCoord,TypeUnknown);
539 expr->value.coord.x= $2;
540 expr->value.coord.y= $4;
545 DoodadDecl : DoodadType String OBRACE VarDeclList CBRACE SEMI
546 { $$= DoodadCreate($1,$2,$4); }
549 DoodadType : TEXT { $$= XkbTextDoodad; }
550 | OUTLINE { $$= XkbOutlineDoodad; }
551 | SOLID { $$= XkbSolidDoodad; }
552 | LOGO { $$= XkbLogoDoodad; }
555 FieldSpec : Ident { $$= $1; }
556 | Element { $$= $1; }
560 { $$= XkbcInternAtom("action",False); }
562 { $$= XkbcInternAtom("interpret",False); }
564 { $$= XkbcInternAtom("type",False); }
566 { $$= XkbcInternAtom("key",False); }
568 { $$= XkbcInternAtom("group",False); }
570 {$$=XkbcInternAtom("modifier_map",False);}
572 { $$= XkbcInternAtom("indicator",False); }
574 { $$= XkbcInternAtom("shape",False); }
576 { $$= XkbcInternAtom("row",False); }
578 { $$= XkbcInternAtom("section",False); }
580 { $$= XkbcInternAtom("text",False); }
583 OptMergeMode : MergeMode { $$= $1; }
584 | { $$= MergeDefault; }
587 MergeMode : INCLUDE { $$= MergeDefault; }
588 | AUGMENT { $$= MergeAugment; }
589 | OVERRIDE { $$= MergeOverride; }
590 | REPLACE { $$= MergeReplace; }
591 | ALTERNATE { $$= MergeAltForm; }
594 OptExprList : ExprList { $$= $1; }
598 ExprList : ExprList COMMA Expr
599 { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
604 Expr : Expr DIVIDE Expr
605 { $$= ExprCreateBinary(OpDivide,$1,$3); }
607 { $$= ExprCreateBinary(OpAdd,$1,$3); }
609 { $$= ExprCreateBinary(OpSubtract,$1,$3); }
611 { $$= ExprCreateBinary(OpMultiply,$1,$3); }
613 { $$= ExprCreateBinary(OpAssign,$1,$3); }
619 { $$= ExprCreateUnary(OpNegate,$2->type,$2); }
621 { $$= ExprCreateUnary(OpUnaryPlus,$2->type,$2); }
623 { $$= ExprCreateUnary(OpNot,TypeBoolean,$2); }
625 { $$= ExprCreateUnary(OpInvert,$2->type,$2); }
628 | FieldSpec OPAREN OptExprList CPAREN %prec OPAREN
629 { $$= ActionCreate($1,$3); }
636 ActionList : ActionList COMMA Action
637 { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
642 Action : FieldSpec OPAREN OptExprList CPAREN
643 { $$= ActionCreate($1,$3); }
649 expr= ExprCreate(ExprIdent,TypeUnknown);
653 | FieldSpec DOT FieldSpec
656 expr= ExprCreate(ExprFieldRef,TypeUnknown);
657 expr->value.field.element= $1;
658 expr->value.field.field= $3;
661 | FieldSpec OBRACKET Expr CBRACKET
664 expr= ExprCreate(ExprArrayRef,TypeUnknown);
665 expr->value.array.element= None;
666 expr->value.array.field= $1;
667 expr->value.array.entry= $3;
670 | FieldSpec DOT FieldSpec OBRACKET Expr CBRACKET
673 expr= ExprCreate(ExprArrayRef,TypeUnknown);
674 expr->value.array.element= $1;
675 expr->value.array.field= $3;
676 expr->value.array.entry= $5;
684 expr= ExprCreate(ExprValue,TypeString);
691 expr= ExprCreate(ExprValue,TypeInt);
692 expr->value.ival= $1;
698 expr= ExprCreate(ExprValue,TypeFloat);
699 expr->value.ival= $1;
705 expr= ExprCreate(ExprValue,TypeKeyName);
706 memset(expr->value.keyName,0,5);
707 strncpy(expr->value.keyName,$1,4);
713 OptKeySymList : KeySymList { $$= $1; }
717 KeySymList : KeySymList COMMA KeySym
718 { $$= AppendKeysymList($1,$3); }
720 { $$= CreateKeysymList($1); }
723 KeySym : IDENT { $$= strdup(scanBuf); }
724 | SECTION { $$= strdup("section"); }
727 if ($1 < 10) { /* XK_0 .. XK_9 */
734 snprintf($$, 17, "%x", $1);
739 SignedNumber : MINUS Number { $$= -$2; }
743 Number : FLOAT { $$= scanInt; }
744 | INTEGER { $$= scanInt*XkbGeomPtsPerMM; }
747 Float : FLOAT { $$= scanInt; }
750 Integer : INTEGER { $$= scanInt; }
753 KeyName : KEYNAME { $$= strdup(scanBuf); }
756 Ident : IDENT { $$= XkbcInternAtom(scanBuf,False); }
757 | DEFAULT { $$= XkbcInternAtom("default",False); }
760 String : STRING { $$= XkbcInternAtom(scanBuf,False); }
763 OptMapName : MapName { $$= $1; }
767 MapName : STRING { $$= strdup(scanBuf); }