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>
102 unsigned int parseDebug;
124 GroupCompatDef *groupCompat;
125 IndicatorMapDef *ledMap;
126 IndicatorNameDef *ledName;
128 KeyAliasDef *keyAlias;
134 OverlayKeyDef *olKey;
139 %type <ival> Number Integer Float SignedNumber
140 %type <uval> XkbCompositeType FileType MergeMode OptMergeMode
141 %type <uval> DoodadType Flag Flags OptFlags
142 %type <str> KeyName MapName OptMapName KeySym
143 %type <sval> FieldSpec Ident Element String
144 %type <any> DeclList Decl
145 %type <expr> OptExprList ExprList Expr Term Lhs Terminal ArrayInit
146 %type <expr> OptKeySymList KeySymList Action ActionList Coord CoordList
147 %type <var> VarDecl VarDeclList SymbolsBody SymbolsVarDecl
148 %type <vmod> VModDecl VModDefList VModDef
149 %type <interp> InterpretDecl InterpretMatch
150 %type <keyType> KeyTypeDecl
151 %type <syms> SymbolsDecl
152 %type <modMask> ModMapDecl
153 %type <groupCompat> GroupCompatDecl
154 %type <ledMap> IndicatorMapDecl
155 %type <ledName> IndicatorNameDecl
156 %type <keyName> KeyNameDecl
157 %type <keyAlias> KeyAliasDecl
158 %type <shape> ShapeDecl
159 %type <section> SectionDecl
160 %type <row> SectionBody SectionBodyItem
161 %type <key> RowBody RowBodyItem Keys Key
162 %type <overlay> OverlayDecl
163 %type <olKey> OverlayKeyList OverlayKey
164 %type <outline> OutlineList OutlineInList
165 %type <doodad> DoodadDecl
166 %type <file> XkbFile XkbMapConfigList XkbMapConfig XkbConfig
167 %type <file> XkbCompositeMap XkbCompMapList
169 XkbFile : XkbCompMapList
170 { $$= rtrnValue= $1; }
172 { $$= rtrnValue= $1; }
174 { $$= rtrnValue= $1; }
177 XkbCompMapList : XkbCompMapList XkbCompositeMap
178 { $$= (XkbFile *)AppendStmt(&$1->common,&$2->common); }
183 XkbCompositeMap : OptFlags XkbCompositeType OptMapName OBRACE
186 { $$= CreateXKBFile($2,$3,&$5->common,$1); }
189 XkbCompositeType: XKB_KEYMAP { $$= XkmKeymapFile; }
190 | XKB_SEMANTICS { $$= XkmSemanticsFile; }
191 | XKB_LAYOUT { $$= XkmLayoutFile; }
194 XkbMapConfigList : XkbMapConfigList XkbMapConfig
195 { $$= (XkbFile *)AppendStmt(&$1->common,&$2->common); }
200 XkbMapConfig : OptFlags FileType OptMapName OBRACE
203 { $$= CreateXKBFile($2,$3,$5,$1); }
206 XkbConfig : OptFlags FileType OptMapName DeclList
207 { $$= CreateXKBFile($2,$3,$4,$1); }
211 FileType : XKB_KEYCODES { $$= XkmKeyNamesIndex; }
212 | XKB_TYPES { $$= XkmTypesIndex; }
213 | XKB_COMPATMAP { $$= XkmCompatMapIndex; }
214 | XKB_SYMBOLS { $$= XkmSymbolsIndex; }
215 | XKB_GEOMETRY { $$= XkmGeometryIndex; }
218 OptFlags : Flags { $$= $1; }
222 Flags : Flags Flag { $$= (($1)|($2)); }
226 Flag : PARTIAL { $$= XkbLC_Partial; }
227 | DEFAULT { $$= XkbLC_Default; }
228 | HIDDEN { $$= XkbLC_Hidden; }
229 | ALPHANUMERIC_KEYS { $$= XkbLC_AlphanumericKeys; }
230 | MODIFIER_KEYS { $$= XkbLC_ModifierKeys; }
231 | KEYPAD_KEYS { $$= XkbLC_KeypadKeys; }
232 | FUNCTION_KEYS { $$= XkbLC_FunctionKeys; }
233 | ALTERNATE_GROUP { $$= XkbLC_AlternateGroup; }
236 DeclList : DeclList Decl
237 { $$= AppendStmt($1,$2); }
241 Decl : OptMergeMode VarDecl
243 $2->merge= StmtSetMerge(&$2->common,$1);
246 | OptMergeMode VModDecl
248 $2->merge= StmtSetMerge(&$2->common,$1);
251 | OptMergeMode InterpretDecl
253 $2->merge= StmtSetMerge(&$2->common,$1);
256 | OptMergeMode KeyNameDecl
258 $2->merge= StmtSetMerge(&$2->common,$1);
261 | OptMergeMode KeyAliasDecl
263 $2->merge= StmtSetMerge(&$2->common,$1);
266 | OptMergeMode KeyTypeDecl
268 $2->merge= StmtSetMerge(&$2->common,$1);
271 | OptMergeMode SymbolsDecl
273 $2->merge= StmtSetMerge(&$2->common,$1);
276 | OptMergeMode ModMapDecl
278 $2->merge= StmtSetMerge(&$2->common,$1);
281 | OptMergeMode GroupCompatDecl
283 $2->merge= StmtSetMerge(&$2->common,$1);
286 | OptMergeMode IndicatorMapDecl
288 $2->merge= StmtSetMerge(&$2->common,$1);
291 | OptMergeMode IndicatorNameDecl
293 $2->merge= StmtSetMerge(&$2->common,$1);
296 | OptMergeMode ShapeDecl
298 $2->merge= StmtSetMerge(&$2->common,$1);
301 | OptMergeMode SectionDecl
303 $2->merge= StmtSetMerge(&$2->common,$1);
306 | OptMergeMode DoodadDecl
308 $2->merge= StmtSetMerge(&$2->common,$1);
313 if ($1==MergeAltForm) {
314 yyerror("cannot use 'alternate' to include other maps");
315 $$= &IncludeCreate(scanBuf,MergeDefault)->common;
318 $$= &IncludeCreate(scanBuf,$1)->common;
323 VarDecl : Lhs EQUALS Expr SEMI
324 { $$= VarCreate($1,$3); }
326 { $$= BoolVarCreate($1,1); }
328 { $$= BoolVarCreate($2,0); }
331 KeyNameDecl : KeyName EQUALS Expr SEMI
335 def= KeycodeCreate($1,$3);
342 KeyAliasDecl : ALIAS KeyName EQUALS KeyName SEMI
345 def= KeyAliasCreate($2,$4);
352 VModDecl : VIRTUAL_MODS VModDefList SEMI
356 VModDefList : VModDefList COMMA VModDef
357 { $$= (VModDef *)AppendStmt(&$1->common,&$3->common); }
363 { $$= VModCreate($1,NULL); }
365 { $$= VModCreate($1,$3); }
368 InterpretDecl : INTERPRET InterpretMatch OBRACE
377 InterpretMatch : KeySym PLUS Expr
378 { $$= InterpCreate($1, $3); }
380 { $$= InterpCreate($1, NULL); }
383 VarDeclList : VarDeclList VarDecl
384 { $$= (VarDef *)AppendStmt(&$1->common,&$2->common); }
389 KeyTypeDecl : TYPE String OBRACE
392 { $$= KeyTypeCreate($2,$4); }
395 SymbolsDecl : KEY KeyName OBRACE
398 { $$= SymbolsCreate($2,(ExprDef *)$4); }
401 SymbolsBody : SymbolsBody COMMA SymbolsVarDecl
402 { $$= (VarDef *)AppendStmt(&$1->common,&$3->common); }
408 SymbolsVarDecl : Lhs EQUALS Expr
409 { $$= VarCreate($1,$3); }
410 | Lhs EQUALS ArrayInit
411 { $$= VarCreate($1,$3); }
413 { $$= BoolVarCreate($1,1); }
415 { $$= BoolVarCreate($2,0); }
417 { $$= VarCreate(NULL,$1); }
420 ArrayInit : OBRACKET OptKeySymList CBRACKET
422 | OBRACKET ActionList CBRACKET
423 { $$= ExprCreateUnary(ExprActionList,TypeAction,$2); }
426 GroupCompatDecl : GROUP Integer EQUALS Expr SEMI
427 { $$= GroupCompatCreate($2,$4); }
430 ModMapDecl : MODIFIER_MAP Ident OBRACE ExprList CBRACE SEMI
431 { $$= ModMapCreate($2,$4); }
434 IndicatorMapDecl: INDICATOR String OBRACE VarDeclList CBRACE SEMI
435 { $$= IndicatorMapCreate($2,$4); }
438 IndicatorNameDecl: INDICATOR Integer EQUALS Expr SEMI
439 { $$= IndicatorNameCreate($2,$4,False); }
440 | VIRTUAL INDICATOR Integer EQUALS Expr SEMI
441 { $$= IndicatorNameCreate($3,$5,True); }
444 ShapeDecl : SHAPE String OBRACE OutlineList CBRACE SEMI
445 { $$= ShapeDeclCreate($2,(OutlineDef *)&$4->common); }
446 | SHAPE String OBRACE CoordList CBRACE SEMI
448 OutlineDef *outlines;
449 outlines= OutlineCreate(None,$4);
450 $$= ShapeDeclCreate($2,outlines);
454 SectionDecl : SECTION String OBRACE SectionBody CBRACE SEMI
455 { $$= SectionDeclCreate($2,$4); }
458 SectionBody : SectionBody SectionBodyItem
459 { $$=(RowDef *)AppendStmt(&$1->common,&$2->common);}
464 SectionBodyItem : ROW OBRACE RowBody CBRACE SEMI
465 { $$= RowDeclCreate($3); }
467 { $$= (RowDef *)$1; }
469 { $$= (RowDef *)$1; }
471 { $$= (RowDef *)$1; }
473 { $$= (RowDef *)$1; }
476 RowBody : RowBody RowBodyItem
477 { $$=(KeyDef *)AppendStmt(&$1->common,&$2->common);}
482 RowBodyItem : KEYS OBRACE Keys CBRACE SEMI
485 { $$= (KeyDef *)$1; }
488 Keys : Keys COMMA Key
489 { $$=(KeyDef *)AppendStmt(&$1->common,&$3->common);}
495 { $$= KeyDeclCreate($1,NULL); }
496 | OBRACE ExprList CBRACE
497 { $$= KeyDeclCreate(NULL,$2); }
500 OverlayDecl : OVERLAY String OBRACE OverlayKeyList CBRACE SEMI
501 { $$= OverlayDeclCreate($2,$4); }
504 OverlayKeyList : OverlayKeyList COMMA OverlayKey
506 $$= (OverlayKeyDef *)
507 AppendStmt(&$1->common,&$3->common);
513 OverlayKey : KeyName EQUALS KeyName
514 { $$= OverlayKeyCreate($1,$3); }
517 OutlineList : OutlineList COMMA OutlineInList
518 { $$=(OutlineDef *)AppendStmt(&$1->common,&$3->common);}
523 OutlineInList : OBRACE CoordList CBRACE
524 { $$= OutlineCreate(None,$2); }
525 | Ident EQUALS OBRACE CoordList CBRACE
526 { $$= OutlineCreate($1,$4); }
528 { $$= OutlineCreate($1,$3); }
531 CoordList : CoordList COMMA Coord
532 { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
537 Coord : OBRACKET SignedNumber COMMA SignedNumber CBRACKET
540 expr= ExprCreate(ExprCoord,TypeUnknown);
541 expr->value.coord.x= $2;
542 expr->value.coord.y= $4;
547 DoodadDecl : DoodadType String OBRACE VarDeclList CBRACE SEMI
548 { $$= DoodadCreate($1,$2,$4); }
551 DoodadType : TEXT { $$= XkbTextDoodad; }
552 | OUTLINE { $$= XkbOutlineDoodad; }
553 | SOLID { $$= XkbSolidDoodad; }
554 | LOGO { $$= XkbLogoDoodad; }
557 FieldSpec : Ident { $$= $1; }
558 | Element { $$= $1; }
562 { $$= XkbcInternAtom("action",False); }
564 { $$= XkbcInternAtom("interpret",False); }
566 { $$= XkbcInternAtom("type",False); }
568 { $$= XkbcInternAtom("key",False); }
570 { $$= XkbcInternAtom("group",False); }
572 {$$=XkbcInternAtom("modifier_map",False);}
574 { $$= XkbcInternAtom("indicator",False); }
576 { $$= XkbcInternAtom("shape",False); }
578 { $$= XkbcInternAtom("row",False); }
580 { $$= XkbcInternAtom("section",False); }
582 { $$= XkbcInternAtom("text",False); }
585 OptMergeMode : MergeMode { $$= $1; }
586 | { $$= MergeDefault; }
589 MergeMode : INCLUDE { $$= MergeDefault; }
590 | AUGMENT { $$= MergeAugment; }
591 | OVERRIDE { $$= MergeOverride; }
592 | REPLACE { $$= MergeReplace; }
593 | ALTERNATE { $$= MergeAltForm; }
596 OptExprList : ExprList { $$= $1; }
600 ExprList : ExprList COMMA Expr
601 { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
606 Expr : Expr DIVIDE Expr
607 { $$= ExprCreateBinary(OpDivide,$1,$3); }
609 { $$= ExprCreateBinary(OpAdd,$1,$3); }
611 { $$= ExprCreateBinary(OpSubtract,$1,$3); }
613 { $$= ExprCreateBinary(OpMultiply,$1,$3); }
615 { $$= ExprCreateBinary(OpAssign,$1,$3); }
621 { $$= ExprCreateUnary(OpNegate,$2->type,$2); }
623 { $$= ExprCreateUnary(OpUnaryPlus,$2->type,$2); }
625 { $$= ExprCreateUnary(OpNot,TypeBoolean,$2); }
627 { $$= ExprCreateUnary(OpInvert,$2->type,$2); }
630 | FieldSpec OPAREN OptExprList CPAREN %prec OPAREN
631 { $$= ActionCreate($1,$3); }
638 ActionList : ActionList COMMA Action
639 { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
644 Action : FieldSpec OPAREN OptExprList CPAREN
645 { $$= ActionCreate($1,$3); }
651 expr= ExprCreate(ExprIdent,TypeUnknown);
655 | FieldSpec DOT FieldSpec
658 expr= ExprCreate(ExprFieldRef,TypeUnknown);
659 expr->value.field.element= $1;
660 expr->value.field.field= $3;
663 | FieldSpec OBRACKET Expr CBRACKET
666 expr= ExprCreate(ExprArrayRef,TypeUnknown);
667 expr->value.array.element= None;
668 expr->value.array.field= $1;
669 expr->value.array.entry= $3;
672 | FieldSpec DOT FieldSpec OBRACKET Expr CBRACKET
675 expr= ExprCreate(ExprArrayRef,TypeUnknown);
676 expr->value.array.element= $1;
677 expr->value.array.field= $3;
678 expr->value.array.entry= $5;
686 expr= ExprCreate(ExprValue,TypeString);
693 expr= ExprCreate(ExprValue,TypeInt);
694 expr->value.ival= $1;
700 expr= ExprCreate(ExprValue,TypeFloat);
701 expr->value.ival= $1;
707 expr= ExprCreate(ExprValue,TypeKeyName);
708 memset(expr->value.keyName,0,5);
709 strncpy(expr->value.keyName,$1,4);
715 OptKeySymList : KeySymList { $$= $1; }
719 KeySymList : KeySymList COMMA KeySym
720 { $$= AppendKeysymList($1,$3); }
722 { $$= CreateKeysymList($1); }
725 KeySym : IDENT { $$= strdup(scanBuf); }
726 | SECTION { $$= strdup("section"); }
729 if ($1 < 10) { /* XK_0 .. XK_9 */
736 snprintf($$, 17, "%x", $1);
741 SignedNumber : MINUS Number { $$= -$2; }
745 Number : FLOAT { $$= scanInt; }
746 | INTEGER { $$= scanInt*XkbGeomPtsPerMM; }
749 Float : FLOAT { $$= scanInt; }
752 Integer : INTEGER { $$= scanInt; }
755 KeyName : KEYNAME { $$= strdup(scanBuf); }
758 Ident : IDENT { $$= XkbcInternAtom(scanBuf,False); }
759 | DEFAULT { $$= XkbcInternAtom("default",False); }
762 String : STRING { $$= XkbcInternAtom(scanBuf,False); }
765 OptMapName : MapName { $$= $1; }
769 MapName : STRING { $$= strdup(scanBuf); }
773 yyerror(const char *s)
775 if (warningLevel>0) {
776 (void)fprintf(stderr,"%s: line %d of %s\n",s,lineNum,
777 (scanFile?scanFile:"(unknown)"));
778 if ((warningLevel>3))
779 (void)fprintf(stderr,"last scanned symbol is: %s\n",scanBuf);