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 }
126 GroupCompatDef *groupCompat;
127 IndicatorMapDef *ledMap;
128 IndicatorNameDef *ledName;
130 KeyAliasDef *keyAlias;
134 %type <num> INTEGER FLOAT
135 %type <str> IDENT KEYNAME STRING
136 %type <ival> Number Integer Float SignedNumber
137 %type <uval> XkbCompositeType FileType MergeMode OptMergeMode
138 %type <uval> DoodadType Flag Flags OptFlags KeyCode
139 %type <str> KeyName MapName OptMapName KeySym
140 %type <sval> FieldSpec Ident Element String
141 %type <any> DeclList Decl
142 %type <expr> OptExprList ExprList Expr Term Lhs Terminal ArrayInit KeySyms
143 %type <expr> OptKeySymList KeySymList Action ActionList Coord CoordList
144 %type <var> VarDecl VarDeclList SymbolsBody SymbolsVarDecl
145 %type <vmod> VModDecl VModDefList VModDef
146 %type <interp> InterpretDecl InterpretMatch
147 %type <keyType> KeyTypeDecl
148 %type <syms> SymbolsDecl
149 %type <modMask> ModMapDecl
150 %type <groupCompat> GroupCompatDecl
151 %type <ledMap> IndicatorMapDecl
152 %type <ledName> IndicatorNameDecl
153 %type <keyName> KeyNameDecl
154 %type <keyAlias> KeyAliasDecl
155 %type <geom> ShapeDecl SectionDecl SectionBody SectionBodyItem RowBody RowBodyItem
156 %type <geom> Keys Key OverlayDecl OverlayKeyList OverlayKey OutlineList OutlineInList
157 %type <geom> DoodadDecl
158 %type <file> XkbFile XkbMapConfigList XkbMapConfig XkbConfig
159 %type <file> XkbCompositeMap XkbCompMapList
161 XkbFile : XkbCompMapList
162 { $$= param->rtrn= $1; }
164 { $$= param->rtrn= $1; }
166 { $$= param->rtrn= $1; }
169 XkbCompMapList : XkbCompMapList XkbCompositeMap
170 { $$= (XkbFile *)AppendStmt(&$1->common,&$2->common); }
175 XkbCompositeMap : OptFlags XkbCompositeType OptMapName OBRACE
179 $$ = CreateXKBFile(param->ctx, $2, $3,
184 XkbCompositeType: XKB_KEYMAP { $$= XkmKeymapFile; }
185 | XKB_SEMANTICS { $$= XkmKeymapFile; }
186 | XKB_LAYOUT { $$= XkmKeymapFile; }
189 XkbMapConfigList : XkbMapConfigList XkbMapConfig
194 $$= (XkbFile *)AppendStmt(&$1->common,&$2->common);
200 XkbMapConfig : OptFlags FileType OptMapName OBRACE
204 if ($2 == XkmGeometryIndex)
212 $$ = CreateXKBFile(param->ctx, $2, $3, $5, $1);
217 XkbConfig : OptFlags FileType OptMapName DeclList
219 if ($2 == XkmGeometryIndex)
227 $$ = CreateXKBFile(param->ctx, $2, $3, $4, $1);
233 FileType : XKB_KEYCODES { $$= XkmKeyNamesIndex; }
234 | XKB_TYPES { $$= XkmTypesIndex; }
235 | XKB_COMPATMAP { $$= XkmCompatMapIndex; }
236 | XKB_SYMBOLS { $$= XkmSymbolsIndex; }
237 | XKB_GEOMETRY { $$= XkmGeometryIndex; }
240 OptFlags : Flags { $$= $1; }
244 Flags : Flags Flag { $$= (($1)|($2)); }
248 Flag : PARTIAL { $$= XkbLC_Partial; }
249 | DEFAULT { $$= XkbLC_Default; }
250 | HIDDEN { $$= XkbLC_Hidden; }
251 | ALPHANUMERIC_KEYS { $$= XkbLC_AlphanumericKeys; }
252 | MODIFIER_KEYS { $$= XkbLC_ModifierKeys; }
253 | KEYPAD_KEYS { $$= XkbLC_KeypadKeys; }
254 | FUNCTION_KEYS { $$= XkbLC_FunctionKeys; }
255 | ALTERNATE_GROUP { $$= XkbLC_AlternateGroup; }
258 DeclList : DeclList Decl
259 { $$= AppendStmt($1,$2); }
263 Decl : OptMergeMode VarDecl
265 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
268 | OptMergeMode VModDecl
270 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
273 | OptMergeMode InterpretDecl
275 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
278 | OptMergeMode KeyNameDecl
280 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
283 | OptMergeMode KeyAliasDecl
285 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
288 | OptMergeMode KeyTypeDecl
290 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
293 | OptMergeMode SymbolsDecl
295 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
298 | OptMergeMode ModMapDecl
300 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
303 | OptMergeMode GroupCompatDecl
305 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
308 | OptMergeMode IndicatorMapDecl
310 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
313 | OptMergeMode IndicatorNameDecl
315 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
318 | OptMergeMode ShapeDecl
321 | OptMergeMode SectionDecl
324 | OptMergeMode DoodadDecl
329 if ($1==MergeAltForm) {
330 yyerror(&@1, scanner,
331 "cannot use 'alternate' to include other maps");
332 $$= &IncludeCreate($2,MergeDefault)->common;
335 $$= &IncludeCreate($2,$1)->common;
341 VarDecl : Lhs EQUALS Expr SEMI
342 { $$= VarCreate($1,$3); }
344 { $$= BoolVarCreate($1,1); }
346 { $$= BoolVarCreate($2,0); }
349 KeyNameDecl : KeyName EQUALS KeyCode SEMI
353 def= KeycodeCreate($1,$3);
359 KeyAliasDecl : ALIAS KeyName EQUALS KeyName SEMI
362 def= KeyAliasCreate($2,$4);
369 VModDecl : VIRTUAL_MODS VModDefList SEMI
373 VModDefList : VModDefList COMMA VModDef
374 { $$= (VModDef *)AppendStmt(&$1->common,&$3->common); }
380 { $$= VModCreate($1,NULL); }
382 { $$= VModCreate($1,$3); }
385 InterpretDecl : INTERPRET InterpretMatch OBRACE
394 InterpretMatch : KeySym PLUS Expr
395 { $$= InterpCreate($1, $3); }
397 { $$= InterpCreate($1, NULL); }
400 VarDeclList : VarDeclList VarDecl
401 { $$= (VarDef *)AppendStmt(&$1->common,&$2->common); }
406 KeyTypeDecl : TYPE String OBRACE
409 { $$= KeyTypeCreate($2,$4); }
412 SymbolsDecl : KEY KeyName OBRACE
415 { $$= SymbolsCreate($2,(ExprDef *)$4); free($2); }
418 SymbolsBody : SymbolsBody COMMA SymbolsVarDecl
419 { $$= (VarDef *)AppendStmt(&$1->common,&$3->common); }
425 SymbolsVarDecl : Lhs EQUALS Expr
426 { $$= VarCreate($1,$3); }
427 | Lhs EQUALS ArrayInit
428 { $$= VarCreate($1,$3); }
430 { $$= BoolVarCreate($1,1); }
432 { $$= BoolVarCreate($2,0); }
434 { $$= VarCreate(NULL,$1); }
437 ArrayInit : OBRACKET OptKeySymList CBRACKET
439 | OBRACKET ActionList CBRACKET
440 { $$= ExprCreateUnary(ExprActionList,TypeAction,$2); }
443 GroupCompatDecl : GROUP Integer EQUALS Expr SEMI
444 { $$= GroupCompatCreate($2,$4); }
447 ModMapDecl : MODIFIER_MAP Ident OBRACE ExprList CBRACE SEMI
448 { $$= ModMapCreate($2,$4); }
451 IndicatorMapDecl: INDICATOR String OBRACE VarDeclList CBRACE SEMI
452 { $$= IndicatorMapCreate($2,$4); }
455 IndicatorNameDecl: INDICATOR Integer EQUALS Expr SEMI
456 { $$= IndicatorNameCreate($2,$4,false); }
457 | VIRTUAL INDICATOR Integer EQUALS Expr SEMI
458 { $$= IndicatorNameCreate($3,$5,true); }
461 ShapeDecl : SHAPE String OBRACE OutlineList CBRACE SEMI
463 | SHAPE String OBRACE CoordList CBRACE SEMI
467 SectionDecl : SECTION String OBRACE SectionBody CBRACE SEMI
471 SectionBody : SectionBody SectionBodyItem
477 SectionBodyItem : ROW OBRACE RowBody CBRACE SEMI
480 { FreeStmt(&$1->common); $$= NULL; }
484 { FreeStmt(&$1->common); $$= NULL; }
489 RowBody : RowBody RowBodyItem
495 RowBodyItem : KEYS OBRACE Keys CBRACE SEMI
498 { FreeStmt(&$1->common); $$= NULL; }
501 Keys : Keys COMMA Key
508 { free($1); $$= NULL; }
509 | OBRACE ExprList CBRACE
510 { FreeStmt(&$2->common); $$= NULL; }
513 OverlayDecl : OVERLAY String OBRACE OverlayKeyList CBRACE SEMI
517 OverlayKeyList : OverlayKeyList COMMA OverlayKey
523 OverlayKey : KeyName EQUALS KeyName
524 { free($1); free($3); $$= NULL; }
527 OutlineList : OutlineList COMMA OutlineInList
533 OutlineInList : OBRACE CoordList CBRACE
535 | Ident EQUALS OBRACE CoordList CBRACE
538 { FreeStmt(&$3->common); $$= NULL; }
541 CoordList : CoordList COMMA Coord
547 Coord : OBRACKET SignedNumber COMMA SignedNumber CBRACKET
551 DoodadDecl : DoodadType String OBRACE VarDeclList CBRACE SEMI
552 { FreeStmt(&$4->common); $$= NULL; }
555 DoodadType : TEXT { $$= 0; }
561 FieldSpec : Ident { $$= $1; }
562 | Element { $$= $1; }
566 { $$= xkb_atom_intern(param->ctx, "action"); }
568 { $$= xkb_atom_intern(param->ctx, "interpret"); }
570 { $$= xkb_atom_intern(param->ctx, "type"); }
572 { $$= xkb_atom_intern(param->ctx, "key"); }
574 { $$= xkb_atom_intern(param->ctx, "group"); }
576 {$$= xkb_atom_intern(param->ctx, "modifier_map");}
578 { $$= xkb_atom_intern(param->ctx, "indicator"); }
580 { $$= xkb_atom_intern(param->ctx, "shape"); }
582 { $$= XKB_ATOM_NONE; }
584 { $$= XKB_ATOM_NONE; }
586 { $$= XKB_ATOM_NONE; }
589 OptMergeMode : MergeMode { $$= $1; }
590 | { $$= MergeDefault; }
593 MergeMode : INCLUDE { $$= MergeDefault; }
594 | AUGMENT { $$= MergeAugment; }
595 | OVERRIDE { $$= MergeOverride; }
596 | REPLACE { $$= MergeReplace; }
597 | ALTERNATE { $$= MergeAltForm; }
600 OptExprList : ExprList { $$= $1; }
604 ExprList : ExprList COMMA Expr
605 { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
610 Expr : Expr DIVIDE Expr
611 { $$= ExprCreateBinary(OpDivide,$1,$3); }
613 { $$= ExprCreateBinary(OpAdd,$1,$3); }
615 { $$= ExprCreateBinary(OpSubtract,$1,$3); }
617 { $$= ExprCreateBinary(OpMultiply,$1,$3); }
619 { $$= ExprCreateBinary(OpAssign,$1,$3); }
625 { $$= ExprCreateUnary(OpNegate,$2->type,$2); }
627 { $$= ExprCreateUnary(OpUnaryPlus,$2->type,$2); }
629 { $$= ExprCreateUnary(OpNot,TypeBoolean,$2); }
631 { $$= ExprCreateUnary(OpInvert,$2->type,$2); }
634 | FieldSpec OPAREN OptExprList CPAREN %prec OPAREN
635 { $$= ActionCreate($1,$3); }
642 ActionList : ActionList COMMA Action
643 { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
648 Action : FieldSpec OPAREN OptExprList CPAREN
649 { $$= ActionCreate($1,$3); }
655 expr= ExprCreate(ExprIdent,TypeUnknown);
659 | FieldSpec DOT FieldSpec
662 expr= ExprCreate(ExprFieldRef,TypeUnknown);
663 expr->value.field.element= $1;
664 expr->value.field.field= $3;
667 | FieldSpec OBRACKET Expr CBRACKET
670 expr= ExprCreate(ExprArrayRef,TypeUnknown);
671 expr->value.array.element= XKB_ATOM_NONE;
672 expr->value.array.field= $1;
673 expr->value.array.entry= $3;
676 | FieldSpec DOT FieldSpec OBRACKET Expr CBRACKET
679 expr= ExprCreate(ExprArrayRef,TypeUnknown);
680 expr->value.array.element= $1;
681 expr->value.array.field= $3;
682 expr->value.array.entry= $5;
690 expr= ExprCreate(ExprValue,TypeString);
697 expr= ExprCreate(ExprValue,TypeInt);
698 expr->value.ival= $1;
708 expr= ExprCreate(ExprValue,TypeKeyName);
709 memset(expr->value.keyName,0,5);
710 strncpy(expr->value.keyName,$1,4);
716 OptKeySymList : KeySymList { $$= $1; }
720 KeySymList : KeySymList COMMA KeySym
721 { $$= AppendKeysymList($1,$3); }
722 | KeySymList COMMA KeySyms
723 { $$= AppendMultiKeysymList($1,$3); }
725 { $$= CreateKeysymList($1); }
727 { $$= CreateMultiKeysymList($1); }
730 KeySyms : OBRACE KeySymList CBRACE
734 KeySym : IDENT { $$= $1; }
735 | SECTION { $$= strdup("section"); }
738 if ($1 < 10) { /* XK_0 .. XK_9 */
745 snprintf($$, 17, "0x%x", $1);
750 SignedNumber : MINUS Number { $$= -$2; }
754 Number : FLOAT { $$= $1; }
755 | INTEGER { $$= $1*XkbGeomPtsPerMM; }
758 Float : FLOAT { $$= 0; }
761 Integer : INTEGER { $$= $1; }
764 KeyCode : INTEGER { $$= $1; }
767 KeyName : KEYNAME { $$= $1; }
772 $$ = xkb_atom_intern(param->ctx, $1);
777 $$ = xkb_atom_intern(param->ctx, "default");
783 $$ = xkb_atom_intern(param->ctx, $1);
788 OptMapName : MapName { $$= $1; }
792 MapName : STRING { $$= $1; }