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
178 { $$= CreateXKBFile($2,$3,&$5->common,$1); }
181 XkbCompositeType: XKB_KEYMAP { $$= XkmKeymapFile; }
182 | XKB_SEMANTICS { $$= XkmSemanticsFile; }
183 | XKB_LAYOUT { $$= XkmLayoutFile; }
186 XkbMapConfigList : XkbMapConfigList XkbMapConfig
191 $$= (XkbFile *)AppendStmt(&$1->common,&$2->common);
197 XkbMapConfig : OptFlags FileType OptMapName OBRACE
201 if ($2 == XkmGeometryIndex)
209 $$= CreateXKBFile($2,$3,$5,$1);
214 XkbConfig : OptFlags FileType OptMapName DeclList
216 if ($2 == XkmGeometryIndex)
224 $$= CreateXKBFile($2,$3,$4,$1);
230 FileType : XKB_KEYCODES { $$= XkmKeyNamesIndex; }
231 | XKB_TYPES { $$= XkmTypesIndex; }
232 | XKB_COMPATMAP { $$= XkmCompatMapIndex; }
233 | XKB_SYMBOLS { $$= XkmSymbolsIndex; }
234 | XKB_GEOMETRY { $$= XkmGeometryIndex; }
237 OptFlags : Flags { $$= $1; }
241 Flags : Flags Flag { $$= (($1)|($2)); }
245 Flag : PARTIAL { $$= XkbLC_Partial; }
246 | DEFAULT { $$= XkbLC_Default; }
247 | HIDDEN { $$= XkbLC_Hidden; }
248 | ALPHANUMERIC_KEYS { $$= XkbLC_AlphanumericKeys; }
249 | MODIFIER_KEYS { $$= XkbLC_ModifierKeys; }
250 | KEYPAD_KEYS { $$= XkbLC_KeypadKeys; }
251 | FUNCTION_KEYS { $$= XkbLC_FunctionKeys; }
252 | ALTERNATE_GROUP { $$= XkbLC_AlternateGroup; }
255 DeclList : DeclList Decl
256 { $$= AppendStmt($1,$2); }
260 Decl : OptMergeMode VarDecl
262 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
265 | OptMergeMode VModDecl
267 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
270 | OptMergeMode InterpretDecl
272 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
275 | OptMergeMode KeyNameDecl
277 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
280 | OptMergeMode KeyAliasDecl
282 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
285 | OptMergeMode KeyTypeDecl
287 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
290 | OptMergeMode SymbolsDecl
292 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
295 | OptMergeMode ModMapDecl
297 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
300 | OptMergeMode GroupCompatDecl
302 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
305 | OptMergeMode IndicatorMapDecl
307 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
310 | OptMergeMode IndicatorNameDecl
312 $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
315 | OptMergeMode ShapeDecl
318 | OptMergeMode SectionDecl
321 | OptMergeMode DoodadDecl
326 if ($1==MergeAltForm) {
327 yyerror(&@1, scanner,
328 "cannot use 'alternate' to include other maps");
329 $$= &IncludeCreate($2,MergeDefault)->common;
332 $$= &IncludeCreate($2,$1)->common;
338 VarDecl : Lhs EQUALS Expr SEMI
339 { $$= VarCreate($1,$3); }
341 { $$= BoolVarCreate($1,1); }
343 { $$= BoolVarCreate($2,0); }
346 KeyNameDecl : KeyName EQUALS KeyCode SEMI
350 def= KeycodeCreate($1,$3);
356 KeyAliasDecl : ALIAS KeyName EQUALS KeyName SEMI
359 def= KeyAliasCreate($2,$4);
366 VModDecl : VIRTUAL_MODS VModDefList SEMI
370 VModDefList : VModDefList COMMA VModDef
371 { $$= (VModDef *)AppendStmt(&$1->common,&$3->common); }
377 { $$= VModCreate($1,NULL); }
379 { $$= VModCreate($1,$3); }
382 InterpretDecl : INTERPRET InterpretMatch OBRACE
391 InterpretMatch : KeySym PLUS Expr
392 { $$= InterpCreate($1, $3); }
394 { $$= InterpCreate($1, NULL); }
397 VarDeclList : VarDeclList VarDecl
398 { $$= (VarDef *)AppendStmt(&$1->common,&$2->common); }
403 KeyTypeDecl : TYPE String OBRACE
406 { $$= KeyTypeCreate($2,$4); }
409 SymbolsDecl : KEY KeyName OBRACE
412 { $$= SymbolsCreate($2,(ExprDef *)$4); free($2); }
415 SymbolsBody : SymbolsBody COMMA SymbolsVarDecl
416 { $$= (VarDef *)AppendStmt(&$1->common,&$3->common); }
422 SymbolsVarDecl : Lhs EQUALS Expr
423 { $$= VarCreate($1,$3); }
424 | Lhs EQUALS ArrayInit
425 { $$= VarCreate($1,$3); }
427 { $$= BoolVarCreate($1,1); }
429 { $$= BoolVarCreate($2,0); }
431 { $$= VarCreate(NULL,$1); }
434 ArrayInit : OBRACKET OptKeySymList CBRACKET
436 | OBRACKET ActionList CBRACKET
437 { $$= ExprCreateUnary(ExprActionList,TypeAction,$2); }
440 GroupCompatDecl : GROUP Integer EQUALS Expr SEMI
441 { $$= GroupCompatCreate($2,$4); }
444 ModMapDecl : MODIFIER_MAP Ident OBRACE ExprList CBRACE SEMI
445 { $$= ModMapCreate($2,$4); }
448 IndicatorMapDecl: INDICATOR String OBRACE VarDeclList CBRACE SEMI
449 { $$= IndicatorMapCreate($2,$4); }
452 IndicatorNameDecl: INDICATOR Integer EQUALS Expr SEMI
453 { $$= IndicatorNameCreate($2,$4,false); }
454 | VIRTUAL INDICATOR Integer EQUALS Expr SEMI
455 { $$= IndicatorNameCreate($3,$5,true); }
458 ShapeDecl : SHAPE String OBRACE OutlineList CBRACE SEMI
460 | SHAPE String OBRACE CoordList CBRACE SEMI
464 SectionDecl : SECTION String OBRACE SectionBody CBRACE SEMI
468 SectionBody : SectionBody SectionBodyItem
474 SectionBodyItem : ROW OBRACE RowBody CBRACE SEMI
477 { FreeStmt(&$1->common); $$= NULL; }
481 { FreeStmt(&$1->common); $$= NULL; }
486 RowBody : RowBody RowBodyItem
492 RowBodyItem : KEYS OBRACE Keys CBRACE SEMI
495 { FreeStmt(&$1->common); $$= NULL; }
498 Keys : Keys COMMA Key
505 { free($1); $$= NULL; }
506 | OBRACE ExprList CBRACE
507 { FreeStmt(&$2->common); $$= NULL; }
510 OverlayDecl : OVERLAY String OBRACE OverlayKeyList CBRACE SEMI
514 OverlayKeyList : OverlayKeyList COMMA OverlayKey
520 OverlayKey : KeyName EQUALS KeyName
521 { free($1); free($3); $$= NULL; }
524 OutlineList : OutlineList COMMA OutlineInList
530 OutlineInList : OBRACE CoordList CBRACE
532 | Ident EQUALS OBRACE CoordList CBRACE
535 { FreeStmt(&$3->common); $$= NULL; }
538 CoordList : CoordList COMMA Coord
544 Coord : OBRACKET SignedNumber COMMA SignedNumber CBRACKET
548 DoodadDecl : DoodadType String OBRACE VarDeclList CBRACE SEMI
549 { FreeStmt(&$4->common); $$= NULL; }
552 DoodadType : TEXT { $$= 0; }
558 FieldSpec : Ident { $$= $1; }
559 | Element { $$= $1; }
563 { $$= xkb_intern_atom("action"); }
565 { $$= xkb_intern_atom("interpret"); }
567 { $$= xkb_intern_atom("type"); }
569 { $$= xkb_intern_atom("key"); }
571 { $$= xkb_intern_atom("group"); }
573 {$$= xkb_intern_atom("modifier_map");}
575 { $$= xkb_intern_atom("indicator"); }
577 { $$= xkb_intern_atom("shape"); }
579 { $$= XKB_ATOM_NONE; }
581 { $$= XKB_ATOM_NONE; }
583 { $$= XKB_ATOM_NONE; }
586 OptMergeMode : MergeMode { $$= $1; }
587 | { $$= MergeDefault; }
590 MergeMode : INCLUDE { $$= MergeDefault; }
591 | AUGMENT { $$= MergeAugment; }
592 | OVERRIDE { $$= MergeOverride; }
593 | REPLACE { $$= MergeReplace; }
594 | ALTERNATE { $$= MergeAltForm; }
597 OptExprList : ExprList { $$= $1; }
601 ExprList : ExprList COMMA Expr
602 { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
607 Expr : Expr DIVIDE Expr
608 { $$= ExprCreateBinary(OpDivide,$1,$3); }
610 { $$= ExprCreateBinary(OpAdd,$1,$3); }
612 { $$= ExprCreateBinary(OpSubtract,$1,$3); }
614 { $$= ExprCreateBinary(OpMultiply,$1,$3); }
616 { $$= ExprCreateBinary(OpAssign,$1,$3); }
622 { $$= ExprCreateUnary(OpNegate,$2->type,$2); }
624 { $$= ExprCreateUnary(OpUnaryPlus,$2->type,$2); }
626 { $$= ExprCreateUnary(OpNot,TypeBoolean,$2); }
628 { $$= ExprCreateUnary(OpInvert,$2->type,$2); }
631 | FieldSpec OPAREN OptExprList CPAREN %prec OPAREN
632 { $$= ActionCreate($1,$3); }
639 ActionList : ActionList COMMA Action
640 { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
645 Action : FieldSpec OPAREN OptExprList CPAREN
646 { $$= ActionCreate($1,$3); }
652 expr= ExprCreate(ExprIdent,TypeUnknown);
656 | FieldSpec DOT FieldSpec
659 expr= ExprCreate(ExprFieldRef,TypeUnknown);
660 expr->value.field.element= $1;
661 expr->value.field.field= $3;
664 | FieldSpec OBRACKET Expr CBRACKET
667 expr= ExprCreate(ExprArrayRef,TypeUnknown);
668 expr->value.array.element= XKB_ATOM_NONE;
669 expr->value.array.field= $1;
670 expr->value.array.entry= $3;
673 | FieldSpec DOT FieldSpec OBRACKET Expr CBRACKET
676 expr= ExprCreate(ExprArrayRef,TypeUnknown);
677 expr->value.array.element= $1;
678 expr->value.array.field= $3;
679 expr->value.array.entry= $5;
687 expr= ExprCreate(ExprValue,TypeString);
694 expr= ExprCreate(ExprValue,TypeInt);
695 expr->value.ival= $1;
705 expr= ExprCreate(ExprValue,TypeKeyName);
706 memset(expr->value.keyName,0,5);
707 strncpy(expr->value.keyName,$1,4);
713 OptKeySymList : KeySymList { $$= $1; }
717 KeySymList : KeySymList COMMA KeySym
718 { $$= AppendKeysymList($1,$3); }
719 | KeySymList COMMA KeySyms
720 { $$= AppendMultiKeysymList($1,$3); }
722 { $$= CreateKeysymList($1); }
724 { $$= CreateMultiKeysymList($1); }
727 KeySyms : OBRACE KeySymList CBRACE
731 KeySym : IDENT { $$= $1; }
732 | SECTION { $$= strdup("section"); }
735 if ($1 < 10) { /* XK_0 .. XK_9 */
742 snprintf($$, 17, "0x%x", $1);
747 SignedNumber : MINUS Number { $$= -$2; }
751 Number : FLOAT { $$= $1; }
752 | INTEGER { $$= $1*XkbGeomPtsPerMM; }
755 Float : FLOAT { $$= 0; }
758 Integer : INTEGER { $$= $1; }
761 KeyCode : INTEGER { $$= $1; }
764 KeyName : KEYNAME { $$= $1; }
767 Ident : IDENT { $$= xkb_intern_atom($1); free($1); }
768 | DEFAULT { $$= xkb_intern_atom("default"); }
771 String : STRING { $$= xkb_intern_atom($1); free($1); }
774 OptMapName : MapName { $$= $1; }
778 MapName : STRING { $$= $1; }