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 #pragma GCC diagnostic ignored "-Wredundant-decls"
33 extern int yylex(union YYSTYPE *val, struct YYLTYPE *loc, void *scanner);
36 yyerror(struct YYLTYPE *loc, struct parser_param *param, const char *msg)
38 scanner_error(loc, param->scanner, msg);
41 #define scanner param->scanner
46 %lex-param { void *scanner }
47 %parse-param { struct parser_param *param }
124 enum xkb_file_type file_type;
127 enum merge_mode merge;
136 GroupCompatDef *groupCompat;
137 IndicatorMapDef *ledMap;
138 IndicatorNameDef *ledName;
140 KeyAliasDef *keyAlias;
144 %type <num> INTEGER FLOAT
145 %type <str> IDENT KEYNAME STRING
146 %type <ival> Number Integer Float SignedNumber
147 %type <merge> MergeMode OptMergeMode
148 %type <file_type> XkbCompositeType FileType
149 %type <uval> DoodadType Flag Flags OptFlags KeyCode
150 %type <str> KeyName MapName OptMapName KeySym
151 %type <sval> FieldSpec Ident Element String
152 %type <any> DeclList Decl
153 %type <expr> OptExprList ExprList Expr Term Lhs Terminal ArrayInit KeySyms
154 %type <expr> OptKeySymList KeySymList Action ActionList Coord CoordList
155 %type <var> VarDecl VarDeclList SymbolsBody SymbolsVarDecl
156 %type <vmod> VModDecl VModDefList VModDef
157 %type <interp> InterpretDecl InterpretMatch
158 %type <keyType> KeyTypeDecl
159 %type <syms> SymbolsDecl
160 %type <modMask> ModMapDecl
161 %type <groupCompat> GroupCompatDecl
162 %type <ledMap> IndicatorMapDecl
163 %type <ledName> IndicatorNameDecl
164 %type <keyName> KeyNameDecl
165 %type <keyAlias> KeyAliasDecl
166 %type <geom> ShapeDecl SectionDecl SectionBody SectionBodyItem RowBody RowBodyItem
167 %type <geom> Keys Key OverlayDecl OverlayKeyList OverlayKey OutlineList OutlineInList
168 %type <geom> DoodadDecl
169 %type <file> XkbFile XkbMapConfigList XkbMapConfig XkbConfig
170 %type <file> XkbCompositeMap XkbCompMapList
172 XkbFile : XkbCompMapList
173 { $$= param->rtrn= $1; }
175 { $$= param->rtrn= $1; }
177 { $$= param->rtrn= $1; }
180 XkbCompMapList : XkbCompMapList XkbCompositeMap
181 { $$= (XkbFile *)AppendStmt(&$1->common,&$2->common); }
186 XkbCompositeMap : OptFlags XkbCompositeType OptMapName OBRACE
190 $$ = CreateXKBFile(param->ctx, $2, $3,
195 XkbCompositeType: XKB_KEYMAP { $$= FILE_TYPE_KEYMAP; }
196 | XKB_SEMANTICS { $$= FILE_TYPE_KEYMAP; }
197 | XKB_LAYOUT { $$= FILE_TYPE_KEYMAP; }
200 XkbMapConfigList : XkbMapConfigList XkbMapConfig
205 $$= (XkbFile *)AppendStmt(&$1->common,&$2->common);
211 XkbMapConfig : OptFlags FileType OptMapName OBRACE
215 if ($2 == FILE_TYPE_GEOMETRY)
223 $$ = CreateXKBFile(param->ctx, $2, $3, $5, $1);
228 XkbConfig : OptFlags FileType OptMapName DeclList
230 if ($2 == FILE_TYPE_GEOMETRY)
238 $$ = CreateXKBFile(param->ctx, $2, $3, $4, $1);
244 FileType : XKB_KEYCODES { $$= FILE_TYPE_KEYCODES; }
245 | XKB_TYPES { $$= FILE_TYPE_TYPES; }
246 | XKB_COMPATMAP { $$= FILE_TYPE_COMPAT; }
247 | XKB_SYMBOLS { $$= FILE_TYPE_SYMBOLS; }
248 | XKB_GEOMETRY { $$= FILE_TYPE_GEOMETRY; }
251 OptFlags : Flags { $$= $1; }
255 Flags : Flags Flag { $$= (($1)|($2)); }
259 Flag : PARTIAL { $$= XkbLC_Partial; }
260 | DEFAULT { $$= XkbLC_Default; }
261 | HIDDEN { $$= XkbLC_Hidden; }
262 | ALPHANUMERIC_KEYS { $$= XkbLC_AlphanumericKeys; }
263 | MODIFIER_KEYS { $$= XkbLC_ModifierKeys; }
264 | KEYPAD_KEYS { $$= XkbLC_KeypadKeys; }
265 | FUNCTION_KEYS { $$= XkbLC_FunctionKeys; }
266 | ALTERNATE_GROUP { $$= XkbLC_AlternateGroup; }
269 DeclList : DeclList Decl
270 { $$= AppendStmt($1,$2); }
274 Decl : OptMergeMode VarDecl
279 | OptMergeMode VModDecl
284 | OptMergeMode InterpretDecl
289 | OptMergeMode KeyNameDecl
294 | OptMergeMode KeyAliasDecl
299 | OptMergeMode KeyTypeDecl
304 | OptMergeMode SymbolsDecl
309 | OptMergeMode ModMapDecl
314 | OptMergeMode GroupCompatDecl
319 | OptMergeMode IndicatorMapDecl
324 | OptMergeMode IndicatorNameDecl
329 | OptMergeMode ShapeDecl
332 | OptMergeMode SectionDecl
335 | OptMergeMode DoodadDecl
340 $$= &IncludeCreate(param->ctx, $2, $1)->common;
345 VarDecl : Lhs EQUALS Expr SEMI
346 { $$= VarCreate($1,$3); }
348 { $$= BoolVarCreate($1,1); }
350 { $$= BoolVarCreate($2,0); }
353 KeyNameDecl : KeyName EQUALS KeyCode SEMI
357 def= KeycodeCreate($1,$3);
363 KeyAliasDecl : ALIAS KeyName EQUALS KeyName SEMI
366 def= KeyAliasCreate($2,$4);
373 VModDecl : VIRTUAL_MODS VModDefList SEMI
377 VModDefList : VModDefList COMMA VModDef
378 { $$= (VModDef *)AppendStmt(&$1->common,&$3->common); }
384 { $$= VModCreate($1,NULL); }
386 { $$= VModCreate($1,$3); }
389 InterpretDecl : INTERPRET InterpretMatch OBRACE
398 InterpretMatch : KeySym PLUS Expr
399 { $$= InterpCreate($1, $3); }
401 { $$= InterpCreate($1, NULL); }
404 VarDeclList : VarDeclList VarDecl
405 { $$= (VarDef *)AppendStmt(&$1->common,&$2->common); }
410 KeyTypeDecl : TYPE String OBRACE
413 { $$= KeyTypeCreate($2,$4); }
416 SymbolsDecl : KEY KeyName OBRACE
419 { $$= SymbolsCreate($2,(ExprDef *)$4); free($2); }
422 SymbolsBody : SymbolsBody COMMA SymbolsVarDecl
423 { $$= (VarDef *)AppendStmt(&$1->common,&$3->common); }
429 SymbolsVarDecl : Lhs EQUALS Expr
430 { $$= VarCreate($1,$3); }
431 | Lhs EQUALS ArrayInit
432 { $$= VarCreate($1,$3); }
434 { $$= BoolVarCreate($1,1); }
436 { $$= BoolVarCreate($2,0); }
438 { $$= VarCreate(NULL,$1); }
441 ArrayInit : OBRACKET OptKeySymList CBRACKET
443 | OBRACKET ActionList CBRACKET
444 { $$= ExprCreateUnary(ExprActionList,TypeAction,$2); }
447 GroupCompatDecl : GROUP Integer EQUALS Expr SEMI
448 { $$= GroupCompatCreate($2,$4); }
451 ModMapDecl : MODIFIER_MAP Ident OBRACE ExprList CBRACE SEMI
452 { $$= ModMapCreate($2,$4); }
455 IndicatorMapDecl: INDICATOR String OBRACE VarDeclList CBRACE SEMI
456 { $$= IndicatorMapCreate($2,$4); }
459 IndicatorNameDecl: INDICATOR Integer EQUALS Expr SEMI
460 { $$= IndicatorNameCreate($2,$4,false); }
461 | VIRTUAL INDICATOR Integer EQUALS Expr SEMI
462 { $$= IndicatorNameCreate($3,$5,true); }
465 ShapeDecl : SHAPE String OBRACE OutlineList CBRACE SEMI
467 | SHAPE String OBRACE CoordList CBRACE SEMI
471 SectionDecl : SECTION String OBRACE SectionBody CBRACE SEMI
475 SectionBody : SectionBody SectionBodyItem
481 SectionBodyItem : ROW OBRACE RowBody CBRACE SEMI
484 { FreeStmt(&$1->common); $$= NULL; }
488 { FreeStmt(&$1->common); $$= NULL; }
493 RowBody : RowBody RowBodyItem
499 RowBodyItem : KEYS OBRACE Keys CBRACE SEMI
502 { FreeStmt(&$1->common); $$= NULL; }
505 Keys : Keys COMMA Key
512 { free($1); $$= NULL; }
513 | OBRACE ExprList CBRACE
514 { FreeStmt(&$2->common); $$= NULL; }
517 OverlayDecl : OVERLAY String OBRACE OverlayKeyList CBRACE SEMI
521 OverlayKeyList : OverlayKeyList COMMA OverlayKey
527 OverlayKey : KeyName EQUALS KeyName
528 { free($1); free($3); $$= NULL; }
531 OutlineList : OutlineList COMMA OutlineInList
537 OutlineInList : OBRACE CoordList CBRACE
539 | Ident EQUALS OBRACE CoordList CBRACE
542 { FreeStmt(&$3->common); $$= NULL; }
545 CoordList : CoordList COMMA Coord
551 Coord : OBRACKET SignedNumber COMMA SignedNumber CBRACKET
555 DoodadDecl : DoodadType String OBRACE VarDeclList CBRACE SEMI
556 { FreeStmt(&$4->common); $$= NULL; }
559 DoodadType : TEXT { $$= 0; }
565 FieldSpec : Ident { $$= $1; }
566 | Element { $$= $1; }
570 { $$= xkb_atom_intern(param->ctx, "action"); }
572 { $$= xkb_atom_intern(param->ctx, "interpret"); }
574 { $$= xkb_atom_intern(param->ctx, "type"); }
576 { $$= xkb_atom_intern(param->ctx, "key"); }
578 { $$= xkb_atom_intern(param->ctx, "group"); }
580 {$$= xkb_atom_intern(param->ctx, "modifier_map");}
582 { $$= xkb_atom_intern(param->ctx, "indicator"); }
584 { $$= xkb_atom_intern(param->ctx, "shape"); }
586 { $$= XKB_ATOM_NONE; }
588 { $$= XKB_ATOM_NONE; }
590 { $$= XKB_ATOM_NONE; }
593 OptMergeMode : MergeMode { $$= $1; }
594 | { $$= MERGE_DEFAULT; }
597 MergeMode : INCLUDE { $$= MERGE_DEFAULT; }
598 | AUGMENT { $$= MERGE_AUGMENT; }
599 | OVERRIDE { $$= MERGE_OVERRIDE; }
600 | REPLACE { $$= MERGE_REPLACE; }
604 * This used to be MERGE_ALT_FORM. This functionality was
605 * unused and has been removed.
611 OptExprList : ExprList { $$= $1; }
615 ExprList : ExprList COMMA Expr
616 { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
621 Expr : Expr DIVIDE Expr
622 { $$= ExprCreateBinary(OpDivide,$1,$3); }
624 { $$= ExprCreateBinary(OpAdd,$1,$3); }
626 { $$= ExprCreateBinary(OpSubtract,$1,$3); }
628 { $$= ExprCreateBinary(OpMultiply,$1,$3); }
630 { $$= ExprCreateBinary(OpAssign,$1,$3); }
636 { $$= ExprCreateUnary(OpNegate,$2->type,$2); }
638 { $$= ExprCreateUnary(OpUnaryPlus,$2->type,$2); }
640 { $$= ExprCreateUnary(OpNot,TypeBoolean,$2); }
642 { $$= ExprCreateUnary(OpInvert,$2->type,$2); }
645 | FieldSpec OPAREN OptExprList CPAREN %prec OPAREN
646 { $$= ActionCreate($1,$3); }
653 ActionList : ActionList COMMA Action
654 { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
659 Action : FieldSpec OPAREN OptExprList CPAREN
660 { $$= ActionCreate($1,$3); }
666 expr= ExprCreate(ExprIdent,TypeUnknown);
670 | FieldSpec DOT FieldSpec
673 expr= ExprCreate(ExprFieldRef,TypeUnknown);
674 expr->value.field.element= $1;
675 expr->value.field.field= $3;
678 | FieldSpec OBRACKET Expr CBRACKET
681 expr= ExprCreate(ExprArrayRef,TypeUnknown);
682 expr->value.array.element= XKB_ATOM_NONE;
683 expr->value.array.field= $1;
684 expr->value.array.entry= $3;
687 | FieldSpec DOT FieldSpec OBRACKET Expr CBRACKET
690 expr= ExprCreate(ExprArrayRef,TypeUnknown);
691 expr->value.array.element= $1;
692 expr->value.array.field= $3;
693 expr->value.array.entry= $5;
701 expr= ExprCreate(ExprValue,TypeString);
708 expr= ExprCreate(ExprValue,TypeInt);
709 expr->value.ival= $1;
719 expr= ExprCreate(ExprValue,TypeKeyName);
720 memset(expr->value.keyName,0,5);
721 strncpy(expr->value.keyName,$1,4);
727 OptKeySymList : KeySymList { $$= $1; }
731 KeySymList : KeySymList COMMA KeySym
732 { $$= AppendKeysymList($1,$3); }
733 | KeySymList COMMA KeySyms
734 { $$= AppendMultiKeysymList($1,$3); }
736 { $$= CreateKeysymList($1); }
738 { $$= CreateMultiKeysymList($1); }
741 KeySyms : OBRACE KeySymList CBRACE
745 KeySym : IDENT { $$= $1; }
746 | SECTION { $$= strdup("section"); }
749 if ($1 < 10) { /* XK_0 .. XK_9 */
756 snprintf($$, 17, "0x%x", $1);
761 SignedNumber : MINUS Number { $$= -$2; }
765 Number : FLOAT { $$= $1; }
766 | INTEGER { $$= $1*XkbGeomPtsPerMM; }
769 Float : FLOAT { $$= 0; }
772 Integer : INTEGER { $$= $1; }
775 KeyCode : INTEGER { $$= $1; }
778 KeyName : KEYNAME { $$= $1; }
783 $$ = xkb_atom_intern(param->ctx, $1);
788 $$ = xkb_atom_intern(param->ctx, "default");
794 $$ = xkb_atom_intern(param->ctx, $1);
799 OptMapName : MapName { $$= $1; }
803 MapName : STRING { $$= $1; }