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
267 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
270 | OptMergeMode VModDecl
272 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
275 | OptMergeMode InterpretDecl
277 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
280 | OptMergeMode KeyNameDecl
282 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
285 | OptMergeMode KeyAliasDecl
287 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
290 | OptMergeMode KeyTypeDecl
292 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
295 | OptMergeMode SymbolsDecl
297 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
300 | OptMergeMode ModMapDecl
302 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
305 | OptMergeMode GroupCompatDecl
307 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
310 | OptMergeMode IndicatorMapDecl
312 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
315 | OptMergeMode IndicatorNameDecl
317 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
320 | OptMergeMode ShapeDecl
323 | OptMergeMode SectionDecl
326 | OptMergeMode DoodadDecl
331 if ($1==MERGE_ALT_FORM) {
332 yyerror(&@1, scanner,
333 "cannot use 'alternate' to include other maps");
334 $$= &IncludeCreate($2,MERGE_DEFAULT)->common;
337 $$= &IncludeCreate($2,$1)->common;
343 VarDecl : Lhs EQUALS Expr SEMI
344 { $$= VarCreate($1,$3); }
346 { $$= BoolVarCreate($1,1); }
348 { $$= BoolVarCreate($2,0); }
351 KeyNameDecl : KeyName EQUALS KeyCode SEMI
355 def= KeycodeCreate($1,$3);
361 KeyAliasDecl : ALIAS KeyName EQUALS KeyName SEMI
364 def= KeyAliasCreate($2,$4);
371 VModDecl : VIRTUAL_MODS VModDefList SEMI
375 VModDefList : VModDefList COMMA VModDef
376 { $$= (VModDef *)AppendStmt(&$1->common,&$3->common); }
382 { $$= VModCreate($1,NULL); }
384 { $$= VModCreate($1,$3); }
387 InterpretDecl : INTERPRET InterpretMatch OBRACE
396 InterpretMatch : KeySym PLUS Expr
397 { $$= InterpCreate($1, $3); }
399 { $$= InterpCreate($1, NULL); }
402 VarDeclList : VarDeclList VarDecl
403 { $$= (VarDef *)AppendStmt(&$1->common,&$2->common); }
408 KeyTypeDecl : TYPE String OBRACE
411 { $$= KeyTypeCreate($2,$4); }
414 SymbolsDecl : KEY KeyName OBRACE
417 { $$= SymbolsCreate($2,(ExprDef *)$4); free($2); }
420 SymbolsBody : SymbolsBody COMMA SymbolsVarDecl
421 { $$= (VarDef *)AppendStmt(&$1->common,&$3->common); }
427 SymbolsVarDecl : Lhs EQUALS Expr
428 { $$= VarCreate($1,$3); }
429 | Lhs EQUALS ArrayInit
430 { $$= VarCreate($1,$3); }
432 { $$= BoolVarCreate($1,1); }
434 { $$= BoolVarCreate($2,0); }
436 { $$= VarCreate(NULL,$1); }
439 ArrayInit : OBRACKET OptKeySymList CBRACKET
441 | OBRACKET ActionList CBRACKET
442 { $$= ExprCreateUnary(ExprActionList,TypeAction,$2); }
445 GroupCompatDecl : GROUP Integer EQUALS Expr SEMI
446 { $$= GroupCompatCreate($2,$4); }
449 ModMapDecl : MODIFIER_MAP Ident OBRACE ExprList CBRACE SEMI
450 { $$= ModMapCreate($2,$4); }
453 IndicatorMapDecl: INDICATOR String OBRACE VarDeclList CBRACE SEMI
454 { $$= IndicatorMapCreate($2,$4); }
457 IndicatorNameDecl: INDICATOR Integer EQUALS Expr SEMI
458 { $$= IndicatorNameCreate($2,$4,false); }
459 | VIRTUAL INDICATOR Integer EQUALS Expr SEMI
460 { $$= IndicatorNameCreate($3,$5,true); }
463 ShapeDecl : SHAPE String OBRACE OutlineList CBRACE SEMI
465 | SHAPE String OBRACE CoordList CBRACE SEMI
469 SectionDecl : SECTION String OBRACE SectionBody CBRACE SEMI
473 SectionBody : SectionBody SectionBodyItem
479 SectionBodyItem : ROW OBRACE RowBody CBRACE SEMI
482 { FreeStmt(&$1->common); $$= NULL; }
486 { FreeStmt(&$1->common); $$= NULL; }
491 RowBody : RowBody RowBodyItem
497 RowBodyItem : KEYS OBRACE Keys CBRACE SEMI
500 { FreeStmt(&$1->common); $$= NULL; }
503 Keys : Keys COMMA Key
510 { free($1); $$= NULL; }
511 | OBRACE ExprList CBRACE
512 { FreeStmt(&$2->common); $$= NULL; }
515 OverlayDecl : OVERLAY String OBRACE OverlayKeyList CBRACE SEMI
519 OverlayKeyList : OverlayKeyList COMMA OverlayKey
525 OverlayKey : KeyName EQUALS KeyName
526 { free($1); free($3); $$= NULL; }
529 OutlineList : OutlineList COMMA OutlineInList
535 OutlineInList : OBRACE CoordList CBRACE
537 | Ident EQUALS OBRACE CoordList CBRACE
540 { FreeStmt(&$3->common); $$= NULL; }
543 CoordList : CoordList COMMA Coord
549 Coord : OBRACKET SignedNumber COMMA SignedNumber CBRACKET
553 DoodadDecl : DoodadType String OBRACE VarDeclList CBRACE SEMI
554 { FreeStmt(&$4->common); $$= NULL; }
557 DoodadType : TEXT { $$= 0; }
563 FieldSpec : Ident { $$= $1; }
564 | Element { $$= $1; }
568 { $$= xkb_atom_intern(param->ctx, "action"); }
570 { $$= xkb_atom_intern(param->ctx, "interpret"); }
572 { $$= xkb_atom_intern(param->ctx, "type"); }
574 { $$= xkb_atom_intern(param->ctx, "key"); }
576 { $$= xkb_atom_intern(param->ctx, "group"); }
578 {$$= xkb_atom_intern(param->ctx, "modifier_map");}
580 { $$= xkb_atom_intern(param->ctx, "indicator"); }
582 { $$= xkb_atom_intern(param->ctx, "shape"); }
584 { $$= XKB_ATOM_NONE; }
586 { $$= XKB_ATOM_NONE; }
588 { $$= XKB_ATOM_NONE; }
591 OptMergeMode : MergeMode { $$= $1; }
592 | { $$= MERGE_DEFAULT; }
595 MergeMode : INCLUDE { $$= MERGE_DEFAULT; }
596 | AUGMENT { $$= MERGE_AUGMENT; }
597 | OVERRIDE { $$= MERGE_OVERRIDE; }
598 | REPLACE { $$= MERGE_REPLACE; }
599 | ALTERNATE { $$= MERGE_ALT_FORM; }
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; }