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 ********************************************************/
28 #include "xkbcomp-priv.h"
29 #include "parseutils.h"
31 extern int yylex(union YYSTYPE *val, struct YYLTYPE *loc, void *scanner);
33 #define scanner param->scanner
38 %lex-param { void *scanner }
39 %parse-param { struct parser_param *param }
116 enum xkb_file_type file_type;
127 GroupCompatDef *groupCompat;
128 IndicatorMapDef *ledMap;
129 IndicatorNameDef *ledName;
131 KeyAliasDef *keyAlias;
135 %type <num> INTEGER FLOAT
136 %type <str> IDENT KEYNAME STRING
137 %type <ival> Number Integer Float SignedNumber
138 %type <uval> MergeMode OptMergeMode
139 %type <file_type> XkbCompositeType FileType
140 %type <uval> DoodadType Flag Flags OptFlags KeyCode
141 %type <str> KeyName MapName OptMapName KeySym
142 %type <sval> FieldSpec Ident Element String
143 %type <any> DeclList Decl
144 %type <expr> OptExprList ExprList Expr Term Lhs Terminal ArrayInit KeySyms
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 <geom> ShapeDecl SectionDecl SectionBody SectionBodyItem RowBody RowBodyItem
158 %type <geom> Keys Key OverlayDecl OverlayKeyList OverlayKey OutlineList OutlineInList
159 %type <geom> DoodadDecl
160 %type <file> XkbFile XkbMapConfigList XkbMapConfig XkbConfig
161 %type <file> XkbCompositeMap XkbCompMapList
163 XkbFile : XkbCompMapList
164 { $$= param->rtrn= $1; }
166 { $$= param->rtrn= $1; }
168 { $$= param->rtrn= $1; }
171 XkbCompMapList : XkbCompMapList XkbCompositeMap
172 { $$= (XkbFile *)AppendStmt(&$1->common,&$2->common); }
177 XkbCompositeMap : OptFlags XkbCompositeType OptMapName OBRACE
181 $$ = CreateXKBFile(param->ctx, $2, $3,
186 XkbCompositeType: XKB_KEYMAP { $$= FILE_TYPE_KEYMAP; }
187 | XKB_SEMANTICS { $$= FILE_TYPE_KEYMAP; }
188 | XKB_LAYOUT { $$= FILE_TYPE_KEYMAP; }
191 XkbMapConfigList : XkbMapConfigList XkbMapConfig
196 $$= (XkbFile *)AppendStmt(&$1->common,&$2->common);
202 XkbMapConfig : OptFlags FileType OptMapName OBRACE
206 if ($2 == FILE_TYPE_GEOMETRY)
214 $$ = CreateXKBFile(param->ctx, $2, $3, $5, $1);
219 XkbConfig : OptFlags FileType OptMapName DeclList
221 if ($2 == FILE_TYPE_GEOMETRY)
229 $$ = CreateXKBFile(param->ctx, $2, $3, $4, $1);
235 FileType : XKB_KEYCODES { $$= FILE_TYPE_KEYCODES; }
236 | XKB_TYPES { $$= FILE_TYPE_TYPES; }
237 | XKB_COMPATMAP { $$= FILE_TYPE_COMPAT; }
238 | XKB_SYMBOLS { $$= FILE_TYPE_SYMBOLS; }
239 | XKB_GEOMETRY { $$= FILE_TYPE_GEOMETRY; }
242 OptFlags : Flags { $$= $1; }
246 Flags : Flags Flag { $$= (($1)|($2)); }
250 Flag : PARTIAL { $$= XkbLC_Partial; }
251 | DEFAULT { $$= XkbLC_Default; }
252 | HIDDEN { $$= XkbLC_Hidden; }
253 | ALPHANUMERIC_KEYS { $$= XkbLC_AlphanumericKeys; }
254 | MODIFIER_KEYS { $$= XkbLC_ModifierKeys; }
255 | KEYPAD_KEYS { $$= XkbLC_KeypadKeys; }
256 | FUNCTION_KEYS { $$= XkbLC_FunctionKeys; }
257 | ALTERNATE_GROUP { $$= XkbLC_AlternateGroup; }
260 DeclList : DeclList Decl
261 { $$= AppendStmt($1,$2); }
265 Decl : OptMergeMode VarDecl
270 | OptMergeMode VModDecl
275 | OptMergeMode InterpretDecl
280 | OptMergeMode KeyNameDecl
285 | OptMergeMode KeyAliasDecl
290 | OptMergeMode KeyTypeDecl
295 | OptMergeMode SymbolsDecl
300 | OptMergeMode ModMapDecl
305 | OptMergeMode GroupCompatDecl
310 | OptMergeMode IndicatorMapDecl
315 | OptMergeMode IndicatorNameDecl
320 | OptMergeMode ShapeDecl
323 | OptMergeMode SectionDecl
326 | OptMergeMode DoodadDecl
331 $$= &IncludeCreate($2,$1)->common;
336 VarDecl : Lhs EQUALS Expr SEMI
337 { $$= VarCreate($1,$3); }
339 { $$= BoolVarCreate($1,1); }
341 { $$= BoolVarCreate($2,0); }
344 KeyNameDecl : KeyName EQUALS KeyCode SEMI
348 def= KeycodeCreate($1,$3);
354 KeyAliasDecl : ALIAS KeyName EQUALS KeyName SEMI
357 def= KeyAliasCreate($2,$4);
364 VModDecl : VIRTUAL_MODS VModDefList SEMI
368 VModDefList : VModDefList COMMA VModDef
369 { $$= (VModDef *)AppendStmt(&$1->common,&$3->common); }
375 { $$= VModCreate($1,NULL); }
377 { $$= VModCreate($1,$3); }
380 InterpretDecl : INTERPRET InterpretMatch OBRACE
389 InterpretMatch : KeySym PLUS Expr
390 { $$= InterpCreate($1, $3); }
392 { $$= InterpCreate($1, NULL); }
395 VarDeclList : VarDeclList VarDecl
396 { $$= (VarDef *)AppendStmt(&$1->common,&$2->common); }
401 KeyTypeDecl : TYPE String OBRACE
404 { $$= KeyTypeCreate($2,$4); }
407 SymbolsDecl : KEY KeyName OBRACE
410 { $$= SymbolsCreate($2,(ExprDef *)$4); free($2); }
413 SymbolsBody : SymbolsBody COMMA SymbolsVarDecl
414 { $$= (VarDef *)AppendStmt(&$1->common,&$3->common); }
420 SymbolsVarDecl : Lhs EQUALS Expr
421 { $$= VarCreate($1,$3); }
422 | Lhs EQUALS ArrayInit
423 { $$= VarCreate($1,$3); }
425 { $$= BoolVarCreate($1,1); }
427 { $$= BoolVarCreate($2,0); }
429 { $$= VarCreate(NULL,$1); }
432 ArrayInit : OBRACKET OptKeySymList CBRACKET
434 | OBRACKET ActionList CBRACKET
435 { $$= ExprCreateUnary(ExprActionList,TypeAction,$2); }
438 GroupCompatDecl : GROUP Integer EQUALS Expr SEMI
439 { $$= GroupCompatCreate($2,$4); }
442 ModMapDecl : MODIFIER_MAP Ident OBRACE ExprList CBRACE SEMI
443 { $$= ModMapCreate($2,$4); }
446 IndicatorMapDecl: INDICATOR String OBRACE VarDeclList CBRACE SEMI
447 { $$= IndicatorMapCreate($2,$4); }
450 IndicatorNameDecl: INDICATOR Integer EQUALS Expr SEMI
451 { $$= IndicatorNameCreate($2,$4,false); }
452 | VIRTUAL INDICATOR Integer EQUALS Expr SEMI
453 { $$= IndicatorNameCreate($3,$5,true); }
456 ShapeDecl : SHAPE String OBRACE OutlineList CBRACE SEMI
458 | SHAPE String OBRACE CoordList CBRACE SEMI
462 SectionDecl : SECTION String OBRACE SectionBody CBRACE SEMI
466 SectionBody : SectionBody SectionBodyItem
472 SectionBodyItem : ROW OBRACE RowBody CBRACE SEMI
475 { FreeStmt(&$1->common); $$= NULL; }
479 { FreeStmt(&$1->common); $$= NULL; }
484 RowBody : RowBody RowBodyItem
490 RowBodyItem : KEYS OBRACE Keys CBRACE SEMI
493 { FreeStmt(&$1->common); $$= NULL; }
496 Keys : Keys COMMA Key
503 { free($1); $$= NULL; }
504 | OBRACE ExprList CBRACE
505 { FreeStmt(&$2->common); $$= NULL; }
508 OverlayDecl : OVERLAY String OBRACE OverlayKeyList CBRACE SEMI
512 OverlayKeyList : OverlayKeyList COMMA OverlayKey
518 OverlayKey : KeyName EQUALS KeyName
519 { free($1); free($3); $$= NULL; }
522 OutlineList : OutlineList COMMA OutlineInList
528 OutlineInList : OBRACE CoordList CBRACE
530 | Ident EQUALS OBRACE CoordList CBRACE
533 { FreeStmt(&$3->common); $$= NULL; }
536 CoordList : CoordList COMMA Coord
542 Coord : OBRACKET SignedNumber COMMA SignedNumber CBRACKET
546 DoodadDecl : DoodadType String OBRACE VarDeclList CBRACE SEMI
547 { FreeStmt(&$4->common); $$= NULL; }
550 DoodadType : TEXT { $$= 0; }
556 FieldSpec : Ident { $$= $1; }
557 | Element { $$= $1; }
561 { $$= xkb_atom_intern(param->ctx, "action"); }
563 { $$= xkb_atom_intern(param->ctx, "interpret"); }
565 { $$= xkb_atom_intern(param->ctx, "type"); }
567 { $$= xkb_atom_intern(param->ctx, "key"); }
569 { $$= xkb_atom_intern(param->ctx, "group"); }
571 {$$= xkb_atom_intern(param->ctx, "modifier_map");}
573 { $$= xkb_atom_intern(param->ctx, "indicator"); }
575 { $$= xkb_atom_intern(param->ctx, "shape"); }
577 { $$= XKB_ATOM_NONE; }
579 { $$= XKB_ATOM_NONE; }
581 { $$= XKB_ATOM_NONE; }
584 OptMergeMode : MergeMode { $$= $1; }
585 | { $$= MERGE_DEFAULT; }
588 MergeMode : INCLUDE { $$= MERGE_DEFAULT; }
589 | AUGMENT { $$= MERGE_AUGMENT; }
590 | OVERRIDE { $$= MERGE_OVERRIDE; }
591 | REPLACE { $$= MERGE_REPLACE; }
595 * This used to be MERGE_ALT_FORM. This functionality was
596 * unused and has been removed.
602 OptExprList : ExprList { $$= $1; }
606 ExprList : ExprList COMMA Expr
607 { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
612 Expr : Expr DIVIDE Expr
613 { $$= ExprCreateBinary(OpDivide,$1,$3); }
615 { $$= ExprCreateBinary(OpAdd,$1,$3); }
617 { $$= ExprCreateBinary(OpSubtract,$1,$3); }
619 { $$= ExprCreateBinary(OpMultiply,$1,$3); }
621 { $$= ExprCreateBinary(OpAssign,$1,$3); }
627 { $$= ExprCreateUnary(OpNegate,$2->type,$2); }
629 { $$= ExprCreateUnary(OpUnaryPlus,$2->type,$2); }
631 { $$= ExprCreateUnary(OpNot,TypeBoolean,$2); }
633 { $$= ExprCreateUnary(OpInvert,$2->type,$2); }
636 | FieldSpec OPAREN OptExprList CPAREN %prec OPAREN
637 { $$= ActionCreate($1,$3); }
644 ActionList : ActionList COMMA Action
645 { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
650 Action : FieldSpec OPAREN OptExprList CPAREN
651 { $$= ActionCreate($1,$3); }
657 expr= ExprCreate(ExprIdent,TypeUnknown);
661 | FieldSpec DOT FieldSpec
664 expr= ExprCreate(ExprFieldRef,TypeUnknown);
665 expr->value.field.element= $1;
666 expr->value.field.field= $3;
669 | FieldSpec OBRACKET Expr CBRACKET
672 expr= ExprCreate(ExprArrayRef,TypeUnknown);
673 expr->value.array.element= XKB_ATOM_NONE;
674 expr->value.array.field= $1;
675 expr->value.array.entry= $3;
678 | FieldSpec DOT FieldSpec OBRACKET Expr CBRACKET
681 expr= ExprCreate(ExprArrayRef,TypeUnknown);
682 expr->value.array.element= $1;
683 expr->value.array.field= $3;
684 expr->value.array.entry= $5;
692 expr= ExprCreate(ExprValue,TypeString);
699 expr= ExprCreate(ExprValue,TypeInt);
700 expr->value.ival= $1;
710 expr= ExprCreate(ExprValue,TypeKeyName);
711 memset(expr->value.keyName,0,5);
712 strncpy(expr->value.keyName,$1,4);
718 OptKeySymList : KeySymList { $$= $1; }
722 KeySymList : KeySymList COMMA KeySym
723 { $$= AppendKeysymList($1,$3); }
724 | KeySymList COMMA KeySyms
725 { $$= AppendMultiKeysymList($1,$3); }
727 { $$= CreateKeysymList($1); }
729 { $$= CreateMultiKeysymList($1); }
732 KeySyms : OBRACE KeySymList CBRACE
736 KeySym : IDENT { $$= $1; }
737 | SECTION { $$= strdup("section"); }
740 if ($1 < 10) { /* XK_0 .. XK_9 */
747 snprintf($$, 17, "0x%x", $1);
752 SignedNumber : MINUS Number { $$= -$2; }
756 Number : FLOAT { $$= $1; }
757 | INTEGER { $$= $1*XkbGeomPtsPerMM; }
760 Float : FLOAT { $$= 0; }
763 Integer : INTEGER { $$= $1; }
766 KeyCode : INTEGER { $$= $1; }
769 KeyName : KEYNAME { $$= $1; }
774 $$ = xkb_atom_intern(param->ctx, $1);
779 $$ = xkb_atom_intern(param->ctx, "default");
785 $$ = xkb_atom_intern(param->ctx, $1);
790 OptMapName : MapName { $$= $1; }
794 MapName : STRING { $$= $1; }