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 ********************************************************/
95 #define DEBUG_VAR parseDebug
96 #include "parseutils.h"
97 #include <X11/keysym.h>
98 #include <X11/extensions/XKBgeomcommon.h>
101 unsigned int parseDebug;
123 GroupCompatDef *groupCompat;
124 IndicatorMapDef *ledMap;
125 IndicatorNameDef *ledName;
127 KeyAliasDef *keyAlias;
133 OverlayKeyDef *olKey;
138 %type <ival> Number Integer Float SignedNumber
139 %type <uval> XkbCompositeType FileType MergeMode OptMergeMode KeySym
140 %type <uval> DoodadType Flag Flags OptFlags
141 %type <str> KeyName MapName OptMapName
142 %type <sval> FieldSpec Ident Element String
143 %type <any> DeclList Decl
144 %type <expr> OptExprList ExprList Expr Term Lhs Terminal ArrayInit
145 %type <expr> OptKeySymList KeySymList Action ActionList Coord CoordList
146 %type <var> VarDecl VarDeclList SymbolsBody SymbolsVarDecl
147 %type <vmod> VModDecl VModDefList VModDef
148 %type <interp> InterpretDecl InterpretMatch
149 %type <keyType> KeyTypeDecl
150 %type <syms> SymbolsDecl
151 %type <modMask> ModMapDecl
152 %type <groupCompat> GroupCompatDecl
153 %type <ledMap> IndicatorMapDecl
154 %type <ledName> IndicatorNameDecl
155 %type <keyName> KeyNameDecl
156 %type <keyAlias> KeyAliasDecl
157 %type <shape> ShapeDecl
158 %type <section> SectionDecl
159 %type <row> SectionBody SectionBodyItem
160 %type <key> RowBody RowBodyItem Keys Key
161 %type <overlay> OverlayDecl
162 %type <olKey> OverlayKeyList OverlayKey
163 %type <outline> OutlineList OutlineInList
164 %type <doodad> DoodadDecl
165 %type <file> XkbFile XkbMapConfigList XkbMapConfig XkbConfig
166 %type <file> XkbCompositeMap XkbCompMapList
168 XkbFile : XkbCompMapList
169 { $$= rtrnValue= $1; }
171 { $$= rtrnValue= $1; }
173 { $$= rtrnValue= $1; }
176 XkbCompMapList : XkbCompMapList XkbCompositeMap
177 { $$= (XkbFile *)AppendStmt(&$1->common,&$2->common); }
182 XkbCompositeMap : OptFlags XkbCompositeType OptMapName OBRACE
185 { $$= CreateXKBFile($2,$3,&$5->common,$1); }
188 XkbCompositeType: XKB_KEYMAP { $$= XkmKeymapFile; }
189 | XKB_SEMANTICS { $$= XkmSemanticsFile; }
190 | XKB_LAYOUT { $$= XkmLayoutFile; }
193 XkbMapConfigList : XkbMapConfigList XkbMapConfig
194 { $$= (XkbFile *)AppendStmt(&$1->common,&$2->common); }
199 XkbMapConfig : OptFlags FileType OptMapName OBRACE
202 { $$= CreateXKBFile($2,$3,$5,$1); }
205 XkbConfig : OptFlags FileType OptMapName DeclList
206 { $$= CreateXKBFile($2,$3,$4,$1); }
210 FileType : XKB_KEYCODES { $$= XkmKeyNamesIndex; }
211 | XKB_TYPES { $$= XkmTypesIndex; }
212 | XKB_COMPATMAP { $$= XkmCompatMapIndex; }
213 | XKB_SYMBOLS { $$= XkmSymbolsIndex; }
214 | XKB_GEOMETRY { $$= XkmGeometryIndex; }
217 OptFlags : Flags { $$= $1; }
221 Flags : Flags Flag { $$= (($1)|($2)); }
225 Flag : PARTIAL { $$= XkbLC_Partial; }
226 | DEFAULT { $$= XkbLC_Default; }
227 | HIDDEN { $$= XkbLC_Hidden; }
228 | ALPHANUMERIC_KEYS { $$= XkbLC_AlphanumericKeys; }
229 | MODIFIER_KEYS { $$= XkbLC_ModifierKeys; }
230 | KEYPAD_KEYS { $$= XkbLC_KeypadKeys; }
231 | FUNCTION_KEYS { $$= XkbLC_FunctionKeys; }
232 | ALTERNATE_GROUP { $$= XkbLC_AlternateGroup; }
235 DeclList : DeclList Decl
236 { $$= AppendStmt($1,$2); }
240 Decl : OptMergeMode VarDecl
242 $2->merge= StmtSetMerge(&$2->common,$1);
245 | OptMergeMode VModDecl
247 $2->merge= StmtSetMerge(&$2->common,$1);
250 | OptMergeMode InterpretDecl
252 $2->merge= StmtSetMerge(&$2->common,$1);
255 | OptMergeMode KeyNameDecl
257 $2->merge= StmtSetMerge(&$2->common,$1);
260 | OptMergeMode KeyAliasDecl
262 $2->merge= StmtSetMerge(&$2->common,$1);
265 | OptMergeMode KeyTypeDecl
267 $2->merge= StmtSetMerge(&$2->common,$1);
270 | OptMergeMode SymbolsDecl
272 $2->merge= StmtSetMerge(&$2->common,$1);
275 | OptMergeMode ModMapDecl
277 $2->merge= StmtSetMerge(&$2->common,$1);
280 | OptMergeMode GroupCompatDecl
282 $2->merge= StmtSetMerge(&$2->common,$1);
285 | OptMergeMode IndicatorMapDecl
287 $2->merge= StmtSetMerge(&$2->common,$1);
290 | OptMergeMode IndicatorNameDecl
292 $2->merge= StmtSetMerge(&$2->common,$1);
295 | OptMergeMode ShapeDecl
297 $2->merge= StmtSetMerge(&$2->common,$1);
300 | OptMergeMode SectionDecl
302 $2->merge= StmtSetMerge(&$2->common,$1);
305 | OptMergeMode DoodadDecl
307 $2->merge= StmtSetMerge(&$2->common,$1);
312 if ($1==MergeAltForm) {
313 yyerror("cannot use 'alternate' to include other maps");
314 $$= &IncludeCreate(scanStr,MergeDefault)->common;
317 $$= &IncludeCreate(scanStr,$1)->common;
322 VarDecl : Lhs EQUALS Expr SEMI
323 { $$= VarCreate($1,$3); }
325 { $$= BoolVarCreate($1,1); }
327 { $$= BoolVarCreate($2,0); }
330 KeyNameDecl : KeyName EQUALS Expr SEMI
334 def= KeycodeCreate($1,$3);
341 KeyAliasDecl : ALIAS KeyName EQUALS KeyName SEMI
344 def= KeyAliasCreate($2,$4);
351 VModDecl : VIRTUAL_MODS VModDefList SEMI
355 VModDefList : VModDefList COMMA VModDef
356 { $$= (VModDef *)AppendStmt(&$1->common,&$3->common); }
362 { $$= VModCreate($1,NULL); }
364 { $$= VModCreate($1,$3); }
367 InterpretDecl : INTERPRET InterpretMatch OBRACE
376 InterpretMatch : KeySym PLUS Expr
377 { $$= InterpCreate((KeySym)$1,$3); }
379 { $$= InterpCreate((KeySym)$1,NULL); }
382 VarDeclList : VarDeclList VarDecl
383 { $$= (VarDef *)AppendStmt(&$1->common,&$2->common); }
388 KeyTypeDecl : TYPE String OBRACE
391 { $$= KeyTypeCreate($2,$4); }
394 SymbolsDecl : KEY KeyName OBRACE
397 { $$= SymbolsCreate($2,(ExprDef *)$4); }
400 SymbolsBody : SymbolsBody COMMA SymbolsVarDecl
401 { $$= (VarDef *)AppendStmt(&$1->common,&$3->common); }
407 SymbolsVarDecl : Lhs EQUALS Expr
408 { $$= VarCreate($1,$3); }
409 | Lhs EQUALS ArrayInit
410 { $$= VarCreate($1,$3); }
412 { $$= BoolVarCreate($1,1); }
414 { $$= BoolVarCreate($2,0); }
416 { $$= VarCreate(NULL,$1); }
419 ArrayInit : OBRACKET OptKeySymList CBRACKET
421 | OBRACKET ActionList CBRACKET
422 { $$= ExprCreateUnary(ExprActionList,TypeAction,$2); }
425 GroupCompatDecl : GROUP Integer EQUALS Expr SEMI
426 { $$= GroupCompatCreate($2,$4); }
429 ModMapDecl : MODIFIER_MAP Ident OBRACE ExprList CBRACE SEMI
430 { $$= ModMapCreate($2,$4); }
433 IndicatorMapDecl: INDICATOR String OBRACE VarDeclList CBRACE SEMI
434 { $$= IndicatorMapCreate($2,$4); }
437 IndicatorNameDecl: INDICATOR Integer EQUALS Expr SEMI
438 { $$= IndicatorNameCreate($2,$4,False); }
439 | VIRTUAL INDICATOR Integer EQUALS Expr SEMI
440 { $$= IndicatorNameCreate($3,$5,True); }
443 ShapeDecl : SHAPE String OBRACE OutlineList CBRACE SEMI
444 { $$= ShapeDeclCreate($2,(OutlineDef *)&$4->common); }
445 | SHAPE String OBRACE CoordList CBRACE SEMI
447 OutlineDef *outlines;
448 outlines= OutlineCreate(None,$4);
449 $$= ShapeDeclCreate($2,outlines);
453 SectionDecl : SECTION String OBRACE SectionBody CBRACE SEMI
454 { $$= SectionDeclCreate($2,$4); }
457 SectionBody : SectionBody SectionBodyItem
458 { $$=(RowDef *)AppendStmt(&$1->common,&$2->common);}
463 SectionBodyItem : ROW OBRACE RowBody CBRACE SEMI
464 { $$= RowDeclCreate($3); }
466 { $$= (RowDef *)$1; }
468 { $$= (RowDef *)$1; }
470 { $$= (RowDef *)$1; }
472 { $$= (RowDef *)$1; }
475 RowBody : RowBody RowBodyItem
476 { $$=(KeyDef *)AppendStmt(&$1->common,&$2->common);}
481 RowBodyItem : KEYS OBRACE Keys CBRACE SEMI
484 { $$= (KeyDef *)$1; }
487 Keys : Keys COMMA Key
488 { $$=(KeyDef *)AppendStmt(&$1->common,&$3->common);}
494 { $$= KeyDeclCreate($1,NULL); }
495 | OBRACE ExprList CBRACE
496 { $$= KeyDeclCreate(NULL,$2); }
499 OverlayDecl : OVERLAY String OBRACE OverlayKeyList CBRACE SEMI
500 { $$= OverlayDeclCreate($2,$4); }
503 OverlayKeyList : OverlayKeyList COMMA OverlayKey
505 $$= (OverlayKeyDef *)
506 AppendStmt(&$1->common,&$3->common);
512 OverlayKey : KeyName EQUALS KeyName
513 { $$= OverlayKeyCreate($1,$3); }
516 OutlineList : OutlineList COMMA OutlineInList
517 { $$=(OutlineDef *)AppendStmt(&$1->common,&$3->common);}
522 OutlineInList : OBRACE CoordList CBRACE
523 { $$= OutlineCreate(None,$2); }
524 | Ident EQUALS OBRACE CoordList CBRACE
525 { $$= OutlineCreate($1,$4); }
527 { $$= OutlineCreate($1,$3); }
530 CoordList : CoordList COMMA Coord
531 { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
536 Coord : OBRACKET SignedNumber COMMA SignedNumber CBRACKET
539 expr= ExprCreate(ExprCoord,TypeUnknown);
540 expr->value.coord.x= $2;
541 expr->value.coord.y= $4;
546 DoodadDecl : DoodadType String OBRACE VarDeclList CBRACE SEMI
547 { $$= DoodadCreate($1,$2,$4); }
550 DoodadType : TEXT { $$= XkbTextDoodad; }
551 | OUTLINE { $$= XkbOutlineDoodad; }
552 | SOLID { $$= XkbSolidDoodad; }
553 | LOGO { $$= XkbLogoDoodad; }
556 FieldSpec : Ident { $$= $1; }
557 | Element { $$= $1; }
561 { $$= XkbInternAtom(NULL,"action",False); }
563 { $$= XkbInternAtom(NULL,"interpret",False); }
565 { $$= XkbInternAtom(NULL,"type",False); }
567 { $$= XkbInternAtom(NULL,"key",False); }
569 { $$= XkbInternAtom(NULL,"group",False); }
571 {$$=XkbInternAtom(NULL,"modifier_map",False);}
573 { $$= XkbInternAtom(NULL,"indicator",False); }
575 { $$= XkbInternAtom(NULL,"shape",False); }
577 { $$= XkbInternAtom(NULL,"row",False); }
579 { $$= XkbInternAtom(NULL,"section",False); }
581 { $$= XkbInternAtom(NULL,"text",False); }
584 OptMergeMode : MergeMode { $$= $1; }
585 | { $$= MergeDefault; }
588 MergeMode : INCLUDE { $$= MergeDefault; }
589 | AUGMENT { $$= MergeAugment; }
590 | OVERRIDE { $$= MergeOverride; }
591 | REPLACE { $$= MergeReplace; }
592 | ALTERNATE { $$= MergeAltForm; }
595 OptExprList : ExprList { $$= $1; }
599 ExprList : ExprList COMMA Expr
600 { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
605 Expr : Expr DIVIDE Expr
606 { $$= ExprCreateBinary(OpDivide,$1,$3); }
608 { $$= ExprCreateBinary(OpAdd,$1,$3); }
610 { $$= ExprCreateBinary(OpSubtract,$1,$3); }
612 { $$= ExprCreateBinary(OpMultiply,$1,$3); }
614 { $$= ExprCreateBinary(OpAssign,$1,$3); }
620 { $$= ExprCreateUnary(OpNegate,$2->type,$2); }
622 { $$= ExprCreateUnary(OpUnaryPlus,$2->type,$2); }
624 { $$= ExprCreateUnary(OpNot,TypeBoolean,$2); }
626 { $$= ExprCreateUnary(OpInvert,$2->type,$2); }
629 | FieldSpec OPAREN OptExprList CPAREN %prec OPAREN
630 { $$= ActionCreate($1,$3); }
637 ActionList : ActionList COMMA Action
638 { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
643 Action : FieldSpec OPAREN OptExprList CPAREN
644 { $$= ActionCreate($1,$3); }
650 expr= ExprCreate(ExprIdent,TypeUnknown);
654 | FieldSpec DOT FieldSpec
657 expr= ExprCreate(ExprFieldRef,TypeUnknown);
658 expr->value.field.element= $1;
659 expr->value.field.field= $3;
662 | FieldSpec OBRACKET Expr CBRACKET
665 expr= ExprCreate(ExprArrayRef,TypeUnknown);
666 expr->value.array.element= None;
667 expr->value.array.field= $1;
668 expr->value.array.entry= $3;
671 | FieldSpec DOT FieldSpec OBRACKET Expr CBRACKET
674 expr= ExprCreate(ExprArrayRef,TypeUnknown);
675 expr->value.array.element= $1;
676 expr->value.array.field= $3;
677 expr->value.array.entry= $5;
685 expr= ExprCreate(ExprValue,TypeString);
692 expr= ExprCreate(ExprValue,TypeInt);
693 expr->value.ival= $1;
699 expr= ExprCreate(ExprValue,TypeFloat);
700 expr->value.ival= $1;
706 expr= ExprCreate(ExprValue,TypeKeyName);
707 memset(expr->value.keyName,0,5);
708 strncpy(expr->value.keyName,$1,4);
714 OptKeySymList : KeySymList { $$= $1; }
718 KeySymList : KeySymList COMMA KeySym
719 { $$= AppendKeysymList($1,(KeySym)$3); }
721 { $$= CreateKeysymList((KeySym)$1); }
727 if (LookupKeysym(scanStr,&sym))
731 snprintf(buf, sizeof(buf),
732 "expected keysym, got %s",
733 uStringText(scanStr));
745 if ($1<10) $$= $1+'0'; /* XK_0 .. XK_9 */
750 SignedNumber : MINUS Number { $$= -$2; }
754 Number : FLOAT { $$= scanInt; }
755 | INTEGER { $$= scanInt*XkbGeomPtsPerMM; }
758 Float : FLOAT { $$= scanInt; }
761 Integer : INTEGER { $$= scanInt; }
764 KeyName : KEYNAME { $$= scanStr; scanStr= NULL; }
767 Ident : IDENT { $$= XkbInternAtom(NULL,scanStr,False); }
768 | DEFAULT { $$= XkbInternAtom(NULL,"default",False); }
771 String : STRING { $$= XkbInternAtom(NULL,scanStr,False); }
774 OptMapName : MapName { $$= $1; }
778 MapName : STRING { $$= scanStr; scanStr= NULL; }
782 yyerror(const char *s)
784 if (warningLevel>0) {
785 (void)fprintf(stderr,"%s: line %d of %s\n",s,lineNum,
786 (scanFile?scanFile:"(unknown)"));
787 if ((scanStr)&&(warningLevel>3))
788 (void)fprintf(stderr,"last scanned symbol is: %s\n",scanStr);