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;
119 enum merge_mode merge;
128 GroupCompatDef *groupCompat;
129 IndicatorMapDef *ledMap;
130 IndicatorNameDef *ledName;
132 KeyAliasDef *keyAlias;
136 %type <num> INTEGER FLOAT
137 %type <str> IDENT KEYNAME STRING
138 %type <ival> Number Integer Float SignedNumber
139 %type <merge> MergeMode OptMergeMode
140 %type <file_type> XkbCompositeType FileType
141 %type <uval> DoodadType Flag Flags OptFlags KeyCode
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 KeySyms
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 <geom> ShapeDecl SectionDecl SectionBody SectionBodyItem RowBody RowBodyItem
159 %type <geom> Keys Key OverlayDecl OverlayKeyList OverlayKey OutlineList OutlineInList
160 %type <geom> DoodadDecl
161 %type <file> XkbFile XkbMapConfigList XkbMapConfig XkbConfig
162 %type <file> XkbCompositeMap XkbCompMapList
164 XkbFile : XkbCompMapList
165 { $$= param->rtrn= $1; }
167 { $$= param->rtrn= $1; }
169 { $$= param->rtrn= $1; }
172 XkbCompMapList : XkbCompMapList XkbCompositeMap
173 { $$= (XkbFile *)AppendStmt(&$1->common,&$2->common); }
178 XkbCompositeMap : OptFlags XkbCompositeType OptMapName OBRACE
182 $$ = CreateXKBFile(param->ctx, $2, $3,
187 XkbCompositeType: XKB_KEYMAP { $$= FILE_TYPE_KEYMAP; }
188 | XKB_SEMANTICS { $$= FILE_TYPE_KEYMAP; }
189 | XKB_LAYOUT { $$= FILE_TYPE_KEYMAP; }
192 XkbMapConfigList : XkbMapConfigList XkbMapConfig
197 $$= (XkbFile *)AppendStmt(&$1->common,&$2->common);
203 XkbMapConfig : OptFlags FileType OptMapName OBRACE
207 if ($2 == FILE_TYPE_GEOMETRY)
215 $$ = CreateXKBFile(param->ctx, $2, $3, $5, $1);
220 XkbConfig : OptFlags FileType OptMapName DeclList
222 if ($2 == FILE_TYPE_GEOMETRY)
230 $$ = CreateXKBFile(param->ctx, $2, $3, $4, $1);
236 FileType : XKB_KEYCODES { $$= FILE_TYPE_KEYCODES; }
237 | XKB_TYPES { $$= FILE_TYPE_TYPES; }
238 | XKB_COMPATMAP { $$= FILE_TYPE_COMPAT; }
239 | XKB_SYMBOLS { $$= FILE_TYPE_SYMBOLS; }
240 | XKB_GEOMETRY { $$= FILE_TYPE_GEOMETRY; }
243 OptFlags : Flags { $$= $1; }
247 Flags : Flags Flag { $$= (($1)|($2)); }
251 Flag : PARTIAL { $$= XkbLC_Partial; }
252 | DEFAULT { $$= XkbLC_Default; }
253 | HIDDEN { $$= XkbLC_Hidden; }
254 | ALPHANUMERIC_KEYS { $$= XkbLC_AlphanumericKeys; }
255 | MODIFIER_KEYS { $$= XkbLC_ModifierKeys; }
256 | KEYPAD_KEYS { $$= XkbLC_KeypadKeys; }
257 | FUNCTION_KEYS { $$= XkbLC_FunctionKeys; }
258 | ALTERNATE_GROUP { $$= XkbLC_AlternateGroup; }
261 DeclList : DeclList Decl
262 { $$= AppendStmt($1,$2); }
266 Decl : OptMergeMode VarDecl
271 | OptMergeMode VModDecl
276 | OptMergeMode InterpretDecl
281 | OptMergeMode KeyNameDecl
286 | OptMergeMode KeyAliasDecl
291 | OptMergeMode KeyTypeDecl
296 | OptMergeMode SymbolsDecl
301 | OptMergeMode ModMapDecl
306 | OptMergeMode GroupCompatDecl
311 | OptMergeMode IndicatorMapDecl
316 | OptMergeMode IndicatorNameDecl
321 | OptMergeMode ShapeDecl
324 | OptMergeMode SectionDecl
327 | OptMergeMode DoodadDecl
332 $$= &IncludeCreate($2,$1)->common;
337 VarDecl : Lhs EQUALS Expr SEMI
338 { $$= VarCreate($1,$3); }
340 { $$= BoolVarCreate($1,1); }
342 { $$= BoolVarCreate($2,0); }
345 KeyNameDecl : KeyName EQUALS KeyCode SEMI
349 def= KeycodeCreate($1,$3);
355 KeyAliasDecl : ALIAS KeyName EQUALS KeyName SEMI
358 def= KeyAliasCreate($2,$4);
365 VModDecl : VIRTUAL_MODS VModDefList SEMI
369 VModDefList : VModDefList COMMA VModDef
370 { $$= (VModDef *)AppendStmt(&$1->common,&$3->common); }
376 { $$= VModCreate($1,NULL); }
378 { $$= VModCreate($1,$3); }
381 InterpretDecl : INTERPRET InterpretMatch OBRACE
390 InterpretMatch : KeySym PLUS Expr
391 { $$= InterpCreate($1, $3); }
393 { $$= InterpCreate($1, NULL); }
396 VarDeclList : VarDeclList VarDecl
397 { $$= (VarDef *)AppendStmt(&$1->common,&$2->common); }
402 KeyTypeDecl : TYPE String OBRACE
405 { $$= KeyTypeCreate($2,$4); }
408 SymbolsDecl : KEY KeyName OBRACE
411 { $$= SymbolsCreate($2,(ExprDef *)$4); free($2); }
414 SymbolsBody : SymbolsBody COMMA SymbolsVarDecl
415 { $$= (VarDef *)AppendStmt(&$1->common,&$3->common); }
421 SymbolsVarDecl : Lhs EQUALS Expr
422 { $$= VarCreate($1,$3); }
423 | Lhs EQUALS ArrayInit
424 { $$= VarCreate($1,$3); }
426 { $$= BoolVarCreate($1,1); }
428 { $$= BoolVarCreate($2,0); }
430 { $$= VarCreate(NULL,$1); }
433 ArrayInit : OBRACKET OptKeySymList CBRACKET
435 | OBRACKET ActionList CBRACKET
436 { $$= ExprCreateUnary(ExprActionList,TypeAction,$2); }
439 GroupCompatDecl : GROUP Integer EQUALS Expr SEMI
440 { $$= GroupCompatCreate($2,$4); }
443 ModMapDecl : MODIFIER_MAP Ident OBRACE ExprList CBRACE SEMI
444 { $$= ModMapCreate($2,$4); }
447 IndicatorMapDecl: INDICATOR String OBRACE VarDeclList CBRACE SEMI
448 { $$= IndicatorMapCreate($2,$4); }
451 IndicatorNameDecl: INDICATOR Integer EQUALS Expr SEMI
452 { $$= IndicatorNameCreate($2,$4,false); }
453 | VIRTUAL INDICATOR Integer EQUALS Expr SEMI
454 { $$= IndicatorNameCreate($3,$5,true); }
457 ShapeDecl : SHAPE String OBRACE OutlineList CBRACE SEMI
459 | SHAPE String OBRACE CoordList CBRACE SEMI
463 SectionDecl : SECTION String OBRACE SectionBody CBRACE SEMI
467 SectionBody : SectionBody SectionBodyItem
473 SectionBodyItem : ROW OBRACE RowBody CBRACE SEMI
476 { FreeStmt(&$1->common); $$= NULL; }
480 { FreeStmt(&$1->common); $$= NULL; }
485 RowBody : RowBody RowBodyItem
491 RowBodyItem : KEYS OBRACE Keys CBRACE SEMI
494 { FreeStmt(&$1->common); $$= NULL; }
497 Keys : Keys COMMA Key
504 { free($1); $$= NULL; }
505 | OBRACE ExprList CBRACE
506 { FreeStmt(&$2->common); $$= NULL; }
509 OverlayDecl : OVERLAY String OBRACE OverlayKeyList CBRACE SEMI
513 OverlayKeyList : OverlayKeyList COMMA OverlayKey
519 OverlayKey : KeyName EQUALS KeyName
520 { free($1); free($3); $$= NULL; }
523 OutlineList : OutlineList COMMA OutlineInList
529 OutlineInList : OBRACE CoordList CBRACE
531 | Ident EQUALS OBRACE CoordList CBRACE
534 { FreeStmt(&$3->common); $$= NULL; }
537 CoordList : CoordList COMMA Coord
543 Coord : OBRACKET SignedNumber COMMA SignedNumber CBRACKET
547 DoodadDecl : DoodadType String OBRACE VarDeclList CBRACE SEMI
548 { FreeStmt(&$4->common); $$= NULL; }
551 DoodadType : TEXT { $$= 0; }
557 FieldSpec : Ident { $$= $1; }
558 | Element { $$= $1; }
562 { $$= xkb_atom_intern(param->ctx, "action"); }
564 { $$= xkb_atom_intern(param->ctx, "interpret"); }
566 { $$= xkb_atom_intern(param->ctx, "type"); }
568 { $$= xkb_atom_intern(param->ctx, "key"); }
570 { $$= xkb_atom_intern(param->ctx, "group"); }
572 {$$= xkb_atom_intern(param->ctx, "modifier_map");}
574 { $$= xkb_atom_intern(param->ctx, "indicator"); }
576 { $$= xkb_atom_intern(param->ctx, "shape"); }
578 { $$= XKB_ATOM_NONE; }
580 { $$= XKB_ATOM_NONE; }
582 { $$= XKB_ATOM_NONE; }
585 OptMergeMode : MergeMode { $$= $1; }
586 | { $$= MERGE_DEFAULT; }
589 MergeMode : INCLUDE { $$= MERGE_DEFAULT; }
590 | AUGMENT { $$= MERGE_AUGMENT; }
591 | OVERRIDE { $$= MERGE_OVERRIDE; }
592 | REPLACE { $$= MERGE_REPLACE; }
596 * This used to be MERGE_ALT_FORM. This functionality was
597 * unused and has been removed.
603 OptExprList : ExprList { $$= $1; }
607 ExprList : ExprList COMMA Expr
608 { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
613 Expr : Expr DIVIDE Expr
614 { $$= ExprCreateBinary(OpDivide,$1,$3); }
616 { $$= ExprCreateBinary(OpAdd,$1,$3); }
618 { $$= ExprCreateBinary(OpSubtract,$1,$3); }
620 { $$= ExprCreateBinary(OpMultiply,$1,$3); }
622 { $$= ExprCreateBinary(OpAssign,$1,$3); }
628 { $$= ExprCreateUnary(OpNegate,$2->type,$2); }
630 { $$= ExprCreateUnary(OpUnaryPlus,$2->type,$2); }
632 { $$= ExprCreateUnary(OpNot,TypeBoolean,$2); }
634 { $$= ExprCreateUnary(OpInvert,$2->type,$2); }
637 | FieldSpec OPAREN OptExprList CPAREN %prec OPAREN
638 { $$= ActionCreate($1,$3); }
645 ActionList : ActionList COMMA Action
646 { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
651 Action : FieldSpec OPAREN OptExprList CPAREN
652 { $$= ActionCreate($1,$3); }
658 expr= ExprCreate(ExprIdent,TypeUnknown);
662 | FieldSpec DOT FieldSpec
665 expr= ExprCreate(ExprFieldRef,TypeUnknown);
666 expr->value.field.element= $1;
667 expr->value.field.field= $3;
670 | FieldSpec OBRACKET Expr CBRACKET
673 expr= ExprCreate(ExprArrayRef,TypeUnknown);
674 expr->value.array.element= XKB_ATOM_NONE;
675 expr->value.array.field= $1;
676 expr->value.array.entry= $3;
679 | FieldSpec DOT FieldSpec OBRACKET Expr CBRACKET
682 expr= ExprCreate(ExprArrayRef,TypeUnknown);
683 expr->value.array.element= $1;
684 expr->value.array.field= $3;
685 expr->value.array.entry= $5;
693 expr= ExprCreate(ExprValue,TypeString);
700 expr= ExprCreate(ExprValue,TypeInt);
701 expr->value.ival= $1;
711 expr= ExprCreate(ExprValue,TypeKeyName);
712 memset(expr->value.keyName,0,5);
713 strncpy(expr->value.keyName,$1,4);
719 OptKeySymList : KeySymList { $$= $1; }
723 KeySymList : KeySymList COMMA KeySym
724 { $$= AppendKeysymList($1,$3); }
725 | KeySymList COMMA KeySyms
726 { $$= AppendMultiKeysymList($1,$3); }
728 { $$= CreateKeysymList($1); }
730 { $$= CreateMultiKeysymList($1); }
733 KeySyms : OBRACE KeySymList CBRACE
737 KeySym : IDENT { $$= $1; }
738 | SECTION { $$= strdup("section"); }
741 if ($1 < 10) { /* XK_0 .. XK_9 */
748 snprintf($$, 17, "0x%x", $1);
753 SignedNumber : MINUS Number { $$= -$2; }
757 Number : FLOAT { $$= $1; }
758 | INTEGER { $$= $1*XkbGeomPtsPerMM; }
761 Float : FLOAT { $$= 0; }
764 Integer : INTEGER { $$= $1; }
767 KeyCode : INTEGER { $$= $1; }
770 KeyName : KEYNAME { $$= $1; }
775 $$ = xkb_atom_intern(param->ctx, $1);
780 $$ = xkb_atom_intern(param->ctx, "default");
786 $$ = xkb_atom_intern(param->ctx, $1);
791 OptMapName : MapName { $$= $1; }
795 MapName : STRING { $$= $1; }