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"
99 #include <X11/keysym.h>
100 #include <X11/extensions/XKBgeomcommon.h>
103 unsigned int parseDebug;
125 GroupCompatDef *groupCompat;
126 IndicatorMapDef *ledMap;
127 IndicatorNameDef *ledName;
129 KeyAliasDef *keyAlias;
135 OverlayKeyDef *olKey;
140 %type <ival> Number Integer Float SignedNumber
141 %type <uval> XkbCompositeType FileType MergeMode OptMergeMode
142 %type <uval> DoodadType Flag Flags OptFlags
143 %type <str> KeyName MapName OptMapName KeySym
144 %type <sval> FieldSpec Ident Element String
145 %type <any> DeclList Decl
146 %type <expr> OptExprList ExprList Expr Term Lhs Terminal ArrayInit
147 %type <expr> OptKeySymList KeySymList Action ActionList Coord CoordList
148 %type <var> VarDecl VarDeclList SymbolsBody SymbolsVarDecl
149 %type <vmod> VModDecl VModDefList VModDef
150 %type <interp> InterpretDecl InterpretMatch
151 %type <keyType> KeyTypeDecl
152 %type <syms> SymbolsDecl
153 %type <modMask> ModMapDecl
154 %type <groupCompat> GroupCompatDecl
155 %type <ledMap> IndicatorMapDecl
156 %type <ledName> IndicatorNameDecl
157 %type <keyName> KeyNameDecl
158 %type <keyAlias> KeyAliasDecl
159 %type <shape> ShapeDecl
160 %type <section> SectionDecl
161 %type <row> SectionBody SectionBodyItem
162 %type <key> RowBody RowBodyItem Keys Key
163 %type <overlay> OverlayDecl
164 %type <olKey> OverlayKeyList OverlayKey
165 %type <outline> OutlineList OutlineInList
166 %type <doodad> DoodadDecl
167 %type <file> XkbFile XkbMapConfigList XkbMapConfig XkbConfig
168 %type <file> XkbCompositeMap XkbCompMapList
170 XkbFile : XkbCompMapList
171 { $$= rtrnValue= $1; }
173 { $$= rtrnValue= $1; }
175 { $$= rtrnValue= $1; }
178 XkbCompMapList : XkbCompMapList XkbCompositeMap
179 { $$= (XkbFile *)AppendStmt(&$1->common,&$2->common); }
184 XkbCompositeMap : OptFlags XkbCompositeType OptMapName OBRACE
187 { $$= CreateXKBFile($2,$3,&$5->common,$1); }
190 XkbCompositeType: XKB_KEYMAP { $$= XkmKeymapFile; }
191 | XKB_SEMANTICS { $$= XkmSemanticsFile; }
192 | XKB_LAYOUT { $$= XkmLayoutFile; }
195 XkbMapConfigList : XkbMapConfigList XkbMapConfig
196 { $$= (XkbFile *)AppendStmt(&$1->common,&$2->common); }
201 XkbMapConfig : OptFlags FileType OptMapName OBRACE
204 { $$= CreateXKBFile($2,$3,$5,$1); }
207 XkbConfig : OptFlags FileType OptMapName DeclList
208 { $$= CreateXKBFile($2,$3,$4,$1); }
212 FileType : XKB_KEYCODES { $$= XkmKeyNamesIndex; }
213 | XKB_TYPES { $$= XkmTypesIndex; }
214 | XKB_COMPATMAP { $$= XkmCompatMapIndex; }
215 | XKB_SYMBOLS { $$= XkmSymbolsIndex; }
216 | XKB_GEOMETRY { $$= XkmGeometryIndex; }
219 OptFlags : Flags { $$= $1; }
223 Flags : Flags Flag { $$= (($1)|($2)); }
227 Flag : PARTIAL { $$= XkbLC_Partial; }
228 | DEFAULT { $$= XkbLC_Default; }
229 | HIDDEN { $$= XkbLC_Hidden; }
230 | ALPHANUMERIC_KEYS { $$= XkbLC_AlphanumericKeys; }
231 | MODIFIER_KEYS { $$= XkbLC_ModifierKeys; }
232 | KEYPAD_KEYS { $$= XkbLC_KeypadKeys; }
233 | FUNCTION_KEYS { $$= XkbLC_FunctionKeys; }
234 | ALTERNATE_GROUP { $$= XkbLC_AlternateGroup; }
237 DeclList : DeclList Decl
238 { $$= AppendStmt($1,$2); }
242 Decl : OptMergeMode VarDecl
244 $2->merge= StmtSetMerge(&$2->common,$1);
247 | OptMergeMode VModDecl
249 $2->merge= StmtSetMerge(&$2->common,$1);
252 | OptMergeMode InterpretDecl
254 $2->merge= StmtSetMerge(&$2->common,$1);
257 | OptMergeMode KeyNameDecl
259 $2->merge= StmtSetMerge(&$2->common,$1);
262 | OptMergeMode KeyAliasDecl
264 $2->merge= StmtSetMerge(&$2->common,$1);
267 | OptMergeMode KeyTypeDecl
269 $2->merge= StmtSetMerge(&$2->common,$1);
272 | OptMergeMode SymbolsDecl
274 $2->merge= StmtSetMerge(&$2->common,$1);
277 | OptMergeMode ModMapDecl
279 $2->merge= StmtSetMerge(&$2->common,$1);
282 | OptMergeMode GroupCompatDecl
284 $2->merge= StmtSetMerge(&$2->common,$1);
287 | OptMergeMode IndicatorMapDecl
289 $2->merge= StmtSetMerge(&$2->common,$1);
292 | OptMergeMode IndicatorNameDecl
294 $2->merge= StmtSetMerge(&$2->common,$1);
297 | OptMergeMode ShapeDecl
299 $2->merge= StmtSetMerge(&$2->common,$1);
302 | OptMergeMode SectionDecl
304 $2->merge= StmtSetMerge(&$2->common,$1);
307 | OptMergeMode DoodadDecl
309 $2->merge= StmtSetMerge(&$2->common,$1);
314 if ($1==MergeAltForm) {
315 yyerror("cannot use 'alternate' to include other maps");
316 $$= &IncludeCreate(scanStr,MergeDefault)->common;
319 $$= &IncludeCreate(scanStr,$1)->common;
324 VarDecl : Lhs EQUALS Expr SEMI
325 { $$= VarCreate($1,$3); }
327 { $$= BoolVarCreate($1,1); }
329 { $$= BoolVarCreate($2,0); }
332 KeyNameDecl : KeyName EQUALS Expr SEMI
336 def= KeycodeCreate($1,$3);
343 KeyAliasDecl : ALIAS KeyName EQUALS KeyName SEMI
346 def= KeyAliasCreate($2,$4);
353 VModDecl : VIRTUAL_MODS VModDefList SEMI
357 VModDefList : VModDefList COMMA VModDef
358 { $$= (VModDef *)AppendStmt(&$1->common,&$3->common); }
364 { $$= VModCreate($1,NULL); }
366 { $$= VModCreate($1,$3); }
369 InterpretDecl : INTERPRET InterpretMatch OBRACE
378 InterpretMatch : KeySym PLUS Expr
379 { $$= InterpCreate(XStringToKeysym($1), $3); }
381 { $$= InterpCreate(XStringToKeysym($1), NULL); }
384 VarDeclList : VarDeclList VarDecl
385 { $$= (VarDef *)AppendStmt(&$1->common,&$2->common); }
390 KeyTypeDecl : TYPE String OBRACE
393 { $$= KeyTypeCreate($2,$4); }
396 SymbolsDecl : KEY KeyName OBRACE
399 { $$= SymbolsCreate($2,(ExprDef *)$4); }
402 SymbolsBody : SymbolsBody COMMA SymbolsVarDecl
403 { $$= (VarDef *)AppendStmt(&$1->common,&$3->common); }
409 SymbolsVarDecl : Lhs EQUALS Expr
410 { $$= VarCreate($1,$3); }
411 | Lhs EQUALS ArrayInit
412 { $$= VarCreate($1,$3); }
414 { $$= BoolVarCreate($1,1); }
416 { $$= BoolVarCreate($2,0); }
418 { $$= VarCreate(NULL,$1); }
421 ArrayInit : OBRACKET OptKeySymList CBRACKET
423 | OBRACKET ActionList CBRACKET
424 { $$= ExprCreateUnary(ExprActionList,TypeAction,$2); }
427 GroupCompatDecl : GROUP Integer EQUALS Expr SEMI
428 { $$= GroupCompatCreate($2,$4); }
431 ModMapDecl : MODIFIER_MAP Ident OBRACE ExprList CBRACE SEMI
432 { $$= ModMapCreate($2,$4); }
435 IndicatorMapDecl: INDICATOR String OBRACE VarDeclList CBRACE SEMI
436 { $$= IndicatorMapCreate($2,$4); }
439 IndicatorNameDecl: INDICATOR Integer EQUALS Expr SEMI
440 { $$= IndicatorNameCreate($2,$4,False); }
441 | VIRTUAL INDICATOR Integer EQUALS Expr SEMI
442 { $$= IndicatorNameCreate($3,$5,True); }
445 ShapeDecl : SHAPE String OBRACE OutlineList CBRACE SEMI
446 { $$= ShapeDeclCreate($2,(OutlineDef *)&$4->common); }
447 | SHAPE String OBRACE CoordList CBRACE SEMI
449 OutlineDef *outlines;
450 outlines= OutlineCreate(None,$4);
451 $$= ShapeDeclCreate($2,outlines);
455 SectionDecl : SECTION String OBRACE SectionBody CBRACE SEMI
456 { $$= SectionDeclCreate($2,$4); }
459 SectionBody : SectionBody SectionBodyItem
460 { $$=(RowDef *)AppendStmt(&$1->common,&$2->common);}
465 SectionBodyItem : ROW OBRACE RowBody CBRACE SEMI
466 { $$= RowDeclCreate($3); }
468 { $$= (RowDef *)$1; }
470 { $$= (RowDef *)$1; }
472 { $$= (RowDef *)$1; }
474 { $$= (RowDef *)$1; }
477 RowBody : RowBody RowBodyItem
478 { $$=(KeyDef *)AppendStmt(&$1->common,&$2->common);}
483 RowBodyItem : KEYS OBRACE Keys CBRACE SEMI
486 { $$= (KeyDef *)$1; }
489 Keys : Keys COMMA Key
490 { $$=(KeyDef *)AppendStmt(&$1->common,&$3->common);}
496 { $$= KeyDeclCreate($1,NULL); }
497 | OBRACE ExprList CBRACE
498 { $$= KeyDeclCreate(NULL,$2); }
501 OverlayDecl : OVERLAY String OBRACE OverlayKeyList CBRACE SEMI
502 { $$= OverlayDeclCreate($2,$4); }
505 OverlayKeyList : OverlayKeyList COMMA OverlayKey
507 $$= (OverlayKeyDef *)
508 AppendStmt(&$1->common,&$3->common);
514 OverlayKey : KeyName EQUALS KeyName
515 { $$= OverlayKeyCreate($1,$3); }
518 OutlineList : OutlineList COMMA OutlineInList
519 { $$=(OutlineDef *)AppendStmt(&$1->common,&$3->common);}
524 OutlineInList : OBRACE CoordList CBRACE
525 { $$= OutlineCreate(None,$2); }
526 | Ident EQUALS OBRACE CoordList CBRACE
527 { $$= OutlineCreate($1,$4); }
529 { $$= OutlineCreate($1,$3); }
532 CoordList : CoordList COMMA Coord
533 { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
538 Coord : OBRACKET SignedNumber COMMA SignedNumber CBRACKET
541 expr= ExprCreate(ExprCoord,TypeUnknown);
542 expr->value.coord.x= $2;
543 expr->value.coord.y= $4;
548 DoodadDecl : DoodadType String OBRACE VarDeclList CBRACE SEMI
549 { $$= DoodadCreate($1,$2,$4); }
552 DoodadType : TEXT { $$= XkbTextDoodad; }
553 | OUTLINE { $$= XkbOutlineDoodad; }
554 | SOLID { $$= XkbSolidDoodad; }
555 | LOGO { $$= XkbLogoDoodad; }
558 FieldSpec : Ident { $$= $1; }
559 | Element { $$= $1; }
563 { $$= XkbcInternAtom("action",False); }
565 { $$= XkbcInternAtom("interpret",False); }
567 { $$= XkbcInternAtom("type",False); }
569 { $$= XkbcInternAtom("key",False); }
571 { $$= XkbcInternAtom("group",False); }
573 {$$=XkbcInternAtom("modifier_map",False);}
575 { $$= XkbcInternAtom("indicator",False); }
577 { $$= XkbcInternAtom("shape",False); }
579 { $$= XkbcInternAtom("row",False); }
581 { $$= XkbcInternAtom("section",False); }
583 { $$= XkbcInternAtom("text",False); }
586 OptMergeMode : MergeMode { $$= $1; }
587 | { $$= MergeDefault; }
590 MergeMode : INCLUDE { $$= MergeDefault; }
591 | AUGMENT { $$= MergeAugment; }
592 | OVERRIDE { $$= MergeOverride; }
593 | REPLACE { $$= MergeReplace; }
594 | ALTERNATE { $$= MergeAltForm; }
597 OptExprList : ExprList { $$= $1; }
601 ExprList : ExprList COMMA Expr
602 { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
607 Expr : Expr DIVIDE Expr
608 { $$= ExprCreateBinary(OpDivide,$1,$3); }
610 { $$= ExprCreateBinary(OpAdd,$1,$3); }
612 { $$= ExprCreateBinary(OpSubtract,$1,$3); }
614 { $$= ExprCreateBinary(OpMultiply,$1,$3); }
616 { $$= ExprCreateBinary(OpAssign,$1,$3); }
622 { $$= ExprCreateUnary(OpNegate,$2->type,$2); }
624 { $$= ExprCreateUnary(OpUnaryPlus,$2->type,$2); }
626 { $$= ExprCreateUnary(OpNot,TypeBoolean,$2); }
628 { $$= ExprCreateUnary(OpInvert,$2->type,$2); }
631 | FieldSpec OPAREN OptExprList CPAREN %prec OPAREN
632 { $$= ActionCreate($1,$3); }
639 ActionList : ActionList COMMA Action
640 { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
645 Action : FieldSpec OPAREN OptExprList CPAREN
646 { $$= ActionCreate($1,$3); }
652 expr= ExprCreate(ExprIdent,TypeUnknown);
656 | FieldSpec DOT FieldSpec
659 expr= ExprCreate(ExprFieldRef,TypeUnknown);
660 expr->value.field.element= $1;
661 expr->value.field.field= $3;
664 | FieldSpec OBRACKET Expr CBRACKET
667 expr= ExprCreate(ExprArrayRef,TypeUnknown);
668 expr->value.array.element= None;
669 expr->value.array.field= $1;
670 expr->value.array.entry= $3;
673 | FieldSpec DOT FieldSpec OBRACKET Expr CBRACKET
676 expr= ExprCreate(ExprArrayRef,TypeUnknown);
677 expr->value.array.element= $1;
678 expr->value.array.field= $3;
679 expr->value.array.entry= $5;
687 expr= ExprCreate(ExprValue,TypeString);
694 expr= ExprCreate(ExprValue,TypeInt);
695 expr->value.ival= $1;
701 expr= ExprCreate(ExprValue,TypeFloat);
702 expr->value.ival= $1;
708 expr= ExprCreate(ExprValue,TypeKeyName);
709 memset(expr->value.keyName,0,5);
710 strncpy(expr->value.keyName,$1,4);
716 OptKeySymList : KeySymList { $$= $1; }
720 KeySymList : KeySymList COMMA KeySym
721 { $$= AppendKeysymList($1,$3); }
723 { $$= CreateKeysymList($1); }
726 KeySym : IDENT { $$= scanStr; scanStr= NULL; }
727 | SECTION { $$= strdup("section"); }
730 if ($1 < 10) { /* XK_0 .. XK_9 */
737 snprintf($$, 17, "%x", $1);
742 SignedNumber : MINUS Number { $$= -$2; }
746 Number : FLOAT { $$= scanInt; }
747 | INTEGER { $$= scanInt*XkbGeomPtsPerMM; }
750 Float : FLOAT { $$= scanInt; }
753 Integer : INTEGER { $$= scanInt; }
756 KeyName : KEYNAME { $$= scanStr; scanStr= NULL; }
759 Ident : IDENT { $$= XkbcInternAtom(scanStr,False); }
760 | DEFAULT { $$= XkbcInternAtom("default",False); }
763 String : STRING { $$= XkbcInternAtom(scanStr,False); }
766 OptMapName : MapName { $$= $1; }
770 MapName : STRING { $$= scanStr; scanStr= NULL; }
774 yyerror(const char *s)
776 if (warningLevel>0) {
777 (void)fprintf(stderr,"%s: line %d of %s\n",s,lineNum,
778 (scanFile?scanFile:"(unknown)"));
779 if ((scanStr)&&(warningLevel>3))
780 (void)fprintf(stderr,"last scanned symbol is: %s\n",scanStr);