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>
101 extern int yylex(void);
123 GroupCompatDef *groupCompat;
124 IndicatorMapDef *ledMap;
125 IndicatorNameDef *ledName;
127 KeyAliasDef *keyAlias;
131 %type <ival> Number Integer Float SignedNumber
132 %type <uval> XkbCompositeType FileType MergeMode OptMergeMode
133 %type <uval> DoodadType Flag Flags OptFlags KeyCode
134 %type <str> KeyName MapName OptMapName KeySym
135 %type <sval> FieldSpec Ident Element String
136 %type <any> DeclList Decl
137 %type <expr> OptExprList ExprList Expr Term Lhs Terminal ArrayInit
138 %type <expr> OptKeySymList KeySymList Action ActionList Coord CoordList
139 %type <var> VarDecl VarDeclList SymbolsBody SymbolsVarDecl
140 %type <vmod> VModDecl VModDefList VModDef
141 %type <interp> InterpretDecl InterpretMatch
142 %type <keyType> KeyTypeDecl
143 %type <syms> SymbolsDecl
144 %type <modMask> ModMapDecl
145 %type <groupCompat> GroupCompatDecl
146 %type <ledMap> IndicatorMapDecl
147 %type <ledName> IndicatorNameDecl
148 %type <keyName> KeyNameDecl
149 %type <keyAlias> KeyAliasDecl
150 %type <geom> ShapeDecl SectionDecl SectionBody SectionBodyItem RowBody RowBodyItem
151 %type <geom> Keys Key OverlayDecl OverlayKeyList OverlayKey OutlineList OutlineInList
152 %type <geom> DoodadDecl
153 %type <file> XkbFile XkbMapConfigList XkbMapConfig XkbConfig
154 %type <file> XkbCompositeMap XkbCompMapList
156 XkbFile : XkbCompMapList
157 { $$= rtrnValue= $1; }
159 { $$= rtrnValue= $1; }
161 { $$= rtrnValue= $1; }
164 XkbCompMapList : XkbCompMapList XkbCompositeMap
165 { $$= (XkbFile *)AppendStmt(&$1->common,&$2->common); }
170 XkbCompositeMap : OptFlags XkbCompositeType OptMapName OBRACE
173 { $$= CreateXKBFile($2,$3,&$5->common,$1); }
176 XkbCompositeType: XKB_KEYMAP { $$= XkmKeymapFile; }
177 | XKB_SEMANTICS { $$= XkmSemanticsFile; }
178 | XKB_LAYOUT { $$= XkmLayoutFile; }
181 XkbMapConfigList : XkbMapConfigList XkbMapConfig
186 $$= (XkbFile *)AppendStmt(&$1->common,&$2->common);
192 XkbMapConfig : OptFlags FileType OptMapName OBRACE
196 if ($2 == XkmGeometryIndex)
199 $$= CreateXKBFile($2,$3,$5,$1);
203 XkbConfig : OptFlags FileType OptMapName DeclList
205 if ($2 == XkmGeometryIndex)
208 $$= CreateXKBFile($2,$3,$4,$1);
213 FileType : XKB_KEYCODES { $$= XkmKeyNamesIndex; }
214 | XKB_TYPES { $$= XkmTypesIndex; }
215 | XKB_COMPATMAP { $$= XkmCompatMapIndex; }
216 | XKB_SYMBOLS { $$= XkmSymbolsIndex; }
217 | XKB_GEOMETRY { $$= XkmGeometryIndex; }
220 OptFlags : Flags { $$= $1; }
224 Flags : Flags Flag { $$= (($1)|($2)); }
228 Flag : PARTIAL { $$= XkbLC_Partial; }
229 | DEFAULT { $$= XkbLC_Default; }
230 | HIDDEN { $$= XkbLC_Hidden; }
231 | ALPHANUMERIC_KEYS { $$= XkbLC_AlphanumericKeys; }
232 | MODIFIER_KEYS { $$= XkbLC_ModifierKeys; }
233 | KEYPAD_KEYS { $$= XkbLC_KeypadKeys; }
234 | FUNCTION_KEYS { $$= XkbLC_FunctionKeys; }
235 | ALTERNATE_GROUP { $$= XkbLC_AlternateGroup; }
238 DeclList : DeclList Decl
239 { $$= AppendStmt($1,$2); }
243 Decl : OptMergeMode VarDecl
245 $2->merge= StmtSetMerge(&$2->common,$1);
248 | OptMergeMode VModDecl
250 $2->merge= StmtSetMerge(&$2->common,$1);
253 | OptMergeMode InterpretDecl
255 $2->merge= StmtSetMerge(&$2->common,$1);
258 | OptMergeMode KeyNameDecl
260 $2->merge= StmtSetMerge(&$2->common,$1);
263 | OptMergeMode KeyAliasDecl
265 $2->merge= StmtSetMerge(&$2->common,$1);
268 | OptMergeMode KeyTypeDecl
270 $2->merge= StmtSetMerge(&$2->common,$1);
273 | OptMergeMode SymbolsDecl
275 $2->merge= StmtSetMerge(&$2->common,$1);
278 | OptMergeMode ModMapDecl
280 $2->merge= StmtSetMerge(&$2->common,$1);
283 | OptMergeMode GroupCompatDecl
285 $2->merge= StmtSetMerge(&$2->common,$1);
288 | OptMergeMode IndicatorMapDecl
290 $2->merge= StmtSetMerge(&$2->common,$1);
293 | OptMergeMode IndicatorNameDecl
295 $2->merge= StmtSetMerge(&$2->common,$1);
298 | OptMergeMode ShapeDecl
301 | OptMergeMode SectionDecl
304 | OptMergeMode DoodadDecl
309 if ($1==MergeAltForm) {
310 yyerror("cannot use 'alternate' to include other maps");
311 $$= &IncludeCreate(scanBuf,MergeDefault)->common;
314 $$= &IncludeCreate(scanBuf,$1)->common;
319 VarDecl : Lhs EQUALS Expr SEMI
320 { $$= VarCreate($1,$3); }
322 { $$= BoolVarCreate($1,1); }
324 { $$= BoolVarCreate($2,0); }
327 KeyNameDecl : KeyName EQUALS KeyCode SEMI
331 def= KeycodeCreate($1,$3);
337 KeyAliasDecl : ALIAS KeyName EQUALS KeyName SEMI
340 def= KeyAliasCreate($2,$4);
347 VModDecl : VIRTUAL_MODS VModDefList SEMI
351 VModDefList : VModDefList COMMA VModDef
352 { $$= (VModDef *)AppendStmt(&$1->common,&$3->common); }
358 { $$= VModCreate($1,NULL); }
360 { $$= VModCreate($1,$3); }
363 InterpretDecl : INTERPRET InterpretMatch OBRACE
372 InterpretMatch : KeySym PLUS Expr
373 { $$= InterpCreate($1, $3); }
375 { $$= InterpCreate($1, NULL); }
378 VarDeclList : VarDeclList VarDecl
379 { $$= (VarDef *)AppendStmt(&$1->common,&$2->common); }
384 KeyTypeDecl : TYPE String OBRACE
387 { $$= KeyTypeCreate($2,$4); }
390 SymbolsDecl : KEY KeyName OBRACE
393 { $$= SymbolsCreate($2,(ExprDef *)$4); free($2); }
396 SymbolsBody : SymbolsBody COMMA SymbolsVarDecl
397 { $$= (VarDef *)AppendStmt(&$1->common,&$3->common); }
403 SymbolsVarDecl : Lhs EQUALS Expr
404 { $$= VarCreate($1,$3); }
405 | Lhs EQUALS ArrayInit
406 { $$= VarCreate($1,$3); }
408 { $$= BoolVarCreate($1,1); }
410 { $$= BoolVarCreate($2,0); }
412 { $$= VarCreate(NULL,$1); }
415 ArrayInit : OBRACKET OptKeySymList CBRACKET
417 | OBRACKET ActionList CBRACKET
418 { $$= ExprCreateUnary(ExprActionList,TypeAction,$2); }
421 GroupCompatDecl : GROUP Integer EQUALS Expr SEMI
422 { $$= GroupCompatCreate($2,$4); }
425 ModMapDecl : MODIFIER_MAP Ident OBRACE ExprList CBRACE SEMI
426 { $$= ModMapCreate($2,$4); }
429 IndicatorMapDecl: INDICATOR String OBRACE VarDeclList CBRACE SEMI
430 { $$= IndicatorMapCreate($2,$4); }
433 IndicatorNameDecl: INDICATOR Integer EQUALS Expr SEMI
434 { $$= IndicatorNameCreate($2,$4,False); }
435 | VIRTUAL INDICATOR Integer EQUALS Expr SEMI
436 { $$= IndicatorNameCreate($3,$5,True); }
439 ShapeDecl : SHAPE String OBRACE OutlineList CBRACE SEMI
441 | SHAPE String OBRACE CoordList CBRACE SEMI
445 SectionDecl : SECTION String OBRACE SectionBody CBRACE SEMI
449 SectionBody : SectionBody SectionBodyItem
455 SectionBodyItem : ROW OBRACE RowBody CBRACE SEMI
467 RowBody : RowBody RowBodyItem
473 RowBodyItem : KEYS OBRACE Keys CBRACE SEMI
479 Keys : Keys COMMA Key
487 | OBRACE ExprList CBRACE
491 OverlayDecl : OVERLAY String OBRACE OverlayKeyList CBRACE SEMI
495 OverlayKeyList : OverlayKeyList COMMA OverlayKey
503 OverlayKey : KeyName EQUALS KeyName
507 OutlineList : OutlineList COMMA OutlineInList
513 OutlineInList : OBRACE CoordList CBRACE
515 | Ident EQUALS OBRACE CoordList CBRACE
521 CoordList : CoordList COMMA Coord
527 Coord : OBRACKET SignedNumber COMMA SignedNumber CBRACKET
531 DoodadDecl : DoodadType String OBRACE VarDeclList CBRACE SEMI
535 DoodadType : TEXT { $$= 0; }
541 FieldSpec : Ident { $$= $1; }
542 | Element { $$= $1; }
546 { $$= xkb_intern_atom("action"); }
548 { $$= xkb_intern_atom("interpret"); }
550 { $$= xkb_intern_atom("type"); }
552 { $$= xkb_intern_atom("key"); }
554 { $$= xkb_intern_atom("group"); }
556 {$$= xkb_intern_atom("modifier_map");}
558 { $$= xkb_intern_atom("indicator"); }
560 { $$= xkb_intern_atom("shape"); }
569 OptMergeMode : MergeMode { $$= $1; }
570 | { $$= MergeDefault; }
573 MergeMode : INCLUDE { $$= MergeDefault; }
574 | AUGMENT { $$= MergeAugment; }
575 | OVERRIDE { $$= MergeOverride; }
576 | REPLACE { $$= MergeReplace; }
577 | ALTERNATE { $$= MergeAltForm; }
580 OptExprList : ExprList { $$= $1; }
584 ExprList : ExprList COMMA Expr
585 { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
590 Expr : Expr DIVIDE Expr
591 { $$= ExprCreateBinary(OpDivide,$1,$3); }
593 { $$= ExprCreateBinary(OpAdd,$1,$3); }
595 { $$= ExprCreateBinary(OpSubtract,$1,$3); }
597 { $$= ExprCreateBinary(OpMultiply,$1,$3); }
599 { $$= ExprCreateBinary(OpAssign,$1,$3); }
605 { $$= ExprCreateUnary(OpNegate,$2->type,$2); }
607 { $$= ExprCreateUnary(OpUnaryPlus,$2->type,$2); }
609 { $$= ExprCreateUnary(OpNot,TypeBoolean,$2); }
611 { $$= ExprCreateUnary(OpInvert,$2->type,$2); }
614 | FieldSpec OPAREN OptExprList CPAREN %prec OPAREN
615 { $$= ActionCreate($1,$3); }
622 ActionList : ActionList COMMA Action
623 { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
628 Action : FieldSpec OPAREN OptExprList CPAREN
629 { $$= ActionCreate($1,$3); }
635 expr= ExprCreate(ExprIdent,TypeUnknown);
639 | FieldSpec DOT FieldSpec
642 expr= ExprCreate(ExprFieldRef,TypeUnknown);
643 expr->value.field.element= $1;
644 expr->value.field.field= $3;
647 | FieldSpec OBRACKET Expr CBRACKET
650 expr= ExprCreate(ExprArrayRef,TypeUnknown);
651 expr->value.array.element= None;
652 expr->value.array.field= $1;
653 expr->value.array.entry= $3;
656 | FieldSpec DOT FieldSpec OBRACKET Expr CBRACKET
659 expr= ExprCreate(ExprArrayRef,TypeUnknown);
660 expr->value.array.element= $1;
661 expr->value.array.field= $3;
662 expr->value.array.entry= $5;
670 expr= ExprCreate(ExprValue,TypeString);
677 expr= ExprCreate(ExprValue,TypeInt);
678 expr->value.ival= $1;
684 expr= ExprCreate(ExprValue,TypeFloat);
685 expr->value.ival= $1;
691 expr= ExprCreate(ExprValue,TypeKeyName);
692 memset(expr->value.keyName,0,5);
693 strncpy(expr->value.keyName,$1,4);
699 OptKeySymList : KeySymList { $$= $1; }
703 KeySymList : KeySymList COMMA KeySym
704 { $$= AppendKeysymList($1,$3); }
706 { $$= CreateKeysymList($1); }
709 KeySym : IDENT { $$= strdup(scanBuf); }
710 | SECTION { $$= strdup("section"); }
713 if ($1 < 10) { /* XK_0 .. XK_9 */
720 snprintf($$, 17, "0x%x", $1);
725 SignedNumber : MINUS Number { $$= -$2; }
729 Number : FLOAT { $$= scanInt; }
730 | INTEGER { $$= scanInt*XkbGeomPtsPerMM; }
733 Float : FLOAT { $$= 0; }
736 Integer : INTEGER { $$= scanInt; }
739 KeyCode : INTEGER { $$= scanULong; }
742 KeyName : KEYNAME { $$= strdup(scanBuf); }
745 Ident : IDENT { $$= xkb_intern_atom(scanBuf); }
746 | DEFAULT { $$= xkb_intern_atom("default"); }
749 String : STRING { $$= xkb_intern_atom(scanBuf); }
752 OptMapName : MapName { $$= $1; }
756 MapName : STRING { $$= strdup(scanBuf); }