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 "ast-build.h"
30 #include "parser-priv.h"
33 yyerror(struct YYLTYPE *loc, struct parser_param *param, const char *msg)
35 scanner_error(loc, param->scanner, msg);
38 #define scanner param->scanner
43 %lex-param { void *scanner }
44 %parse-param { struct parser_param *param }
123 enum xkb_file_type file_type;
125 char keyName[XKB_KEY_NAME_LENGTH];
127 enum merge_mode merge;
128 enum xkb_map_flags mapFlags;
137 GroupCompatDef *groupCompat;
138 IndicatorMapDef *ledMap;
139 IndicatorNameDef *ledName;
141 KeyAliasDef *keyAlias;
146 %type <num> INTEGER FLOAT
147 %type <str> IDENT STRING
148 %type <keyName> KEYNAME KeyName
149 %type <ival> Number Integer Float SignedNumber
150 %type <merge> MergeMode OptMergeMode
151 %type <file_type> XkbCompositeType FileType
152 %type <uval> DoodadType
153 %type <mapFlags> Flag Flags OptFlags KeyCode
154 %type <str> MapName OptMapName KeySym
155 %type <sval> FieldSpec Ident Element String
156 %type <any> DeclList Decl
157 %type <expr> OptExprList ExprList Expr Term Lhs Terminal ArrayInit KeySyms
158 %type <expr> OptKeySymList KeySymList Action ActionList Coord CoordList
159 %type <var> VarDecl VarDeclList SymbolsBody SymbolsVarDecl
160 %type <vmod> VModDecl VModDefList VModDef
161 %type <interp> InterpretDecl InterpretMatch
162 %type <keyType> KeyTypeDecl
163 %type <syms> SymbolsDecl
164 %type <modMask> ModMapDecl
165 %type <groupCompat> GroupCompatDecl
166 %type <ledMap> IndicatorMapDecl
167 %type <ledName> IndicatorNameDecl
168 %type <keyCode> KeyNameDecl
169 %type <keyAlias> KeyAliasDecl
170 %type <geom> ShapeDecl SectionDecl SectionBody SectionBodyItem RowBody RowBodyItem
171 %type <geom> Keys Key OverlayDecl OverlayKeyList OverlayKey OutlineList OutlineInList
172 %type <geom> DoodadDecl
173 %type <file> XkbFile XkbMapConfigList XkbMapConfig XkbConfig
174 %type <file> XkbCompositeMap XkbCompMapList
178 XkbFile : XkbCompMapList
179 { $$ = param->rtrn = $1; }
181 { $$ = param->rtrn = $1; }
183 { $$ = param->rtrn = $1; }
186 XkbCompMapList : XkbCompMapList XkbCompositeMap
187 { $$ = (XkbFile *)AppendStmt(&$1->common, &$2->common); }
192 XkbCompositeMap : OptFlags XkbCompositeType OptMapName OBRACE
195 { $$ = XkbFileCreate(param->ctx, $2, $3, &$5->common, $1); }
198 XkbCompositeType: XKB_KEYMAP { $$ = FILE_TYPE_KEYMAP; }
199 | XKB_SEMANTICS { $$ = FILE_TYPE_KEYMAP; }
200 | XKB_LAYOUT { $$ = FILE_TYPE_KEYMAP; }
203 XkbMapConfigList : XkbMapConfigList XkbMapConfig
208 $$ = (XkbFile *)AppendStmt(&$1->common, &$2->common);
214 XkbMapConfig : OptFlags FileType OptMapName OBRACE
218 if ($2 == FILE_TYPE_GEOMETRY) {
224 $$ = XkbFileCreate(param->ctx, $2, $3, $5, $1);
229 XkbConfig : OptFlags FileType OptMapName DeclList
231 if ($2 == FILE_TYPE_GEOMETRY) {
237 $$ = XkbFileCreate(param->ctx, $2, $3, $4, $1);
243 FileType : XKB_KEYCODES { $$ = FILE_TYPE_KEYCODES; }
244 | XKB_TYPES { $$ = FILE_TYPE_TYPES; }
245 | XKB_COMPATMAP { $$ = FILE_TYPE_COMPAT; }
246 | XKB_SYMBOLS { $$ = FILE_TYPE_SYMBOLS; }
247 | XKB_GEOMETRY { $$ = FILE_TYPE_GEOMETRY; }
250 OptFlags : Flags { $$ = $1; }
254 Flags : Flags Flag { $$ = ($1 | $2); }
258 Flag : PARTIAL { $$ = MAP_IS_PARTIAL; }
259 | DEFAULT { $$ = MAP_IS_DEFAULT; }
260 | HIDDEN { $$ = MAP_IS_HIDDEN; }
261 | ALPHANUMERIC_KEYS { $$ = MAP_HAS_ALPHANUMERIC; }
262 | MODIFIER_KEYS { $$ = MAP_HAS_MODIFIER; }
263 | KEYPAD_KEYS { $$ = MAP_HAS_KEYPAD; }
264 | FUNCTION_KEYS { $$ = MAP_HAS_FN; }
265 | ALTERNATE_GROUP { $$ = MAP_IS_ALTGR; }
268 DeclList : DeclList Decl
269 { $$ = AppendStmt($1, $2); }
273 Decl : OptMergeMode VarDecl
278 | OptMergeMode VModDecl
283 | OptMergeMode InterpretDecl
288 | OptMergeMode KeyNameDecl
293 | OptMergeMode KeyAliasDecl
298 | OptMergeMode KeyTypeDecl
303 | OptMergeMode SymbolsDecl
308 | OptMergeMode ModMapDecl
313 | OptMergeMode GroupCompatDecl
318 | OptMergeMode IndicatorMapDecl
323 | OptMergeMode IndicatorNameDecl
328 | OptMergeMode ShapeDecl { }
329 | OptMergeMode SectionDecl { }
330 | OptMergeMode DoodadDecl { }
333 $$ = &IncludeCreate(param->ctx, $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
347 { $$ = KeycodeCreate($1, $3); }
350 KeyAliasDecl : ALIAS KeyName EQUALS KeyName SEMI
351 { $$ = KeyAliasCreate($2, $4); }
354 VModDecl : VIRTUAL_MODS VModDefList SEMI
358 VModDefList : VModDefList COMMA VModDef
359 { $$ = (VModDef *)AppendStmt(&$1->common, &$3->common); }
365 { $$ = VModCreate($1, NULL); }
367 { $$ = VModCreate($1, $3); }
370 InterpretDecl : INTERPRET InterpretMatch OBRACE
373 { $2->def = $4; $$ = $2; }
376 InterpretMatch : KeySym PLUS Expr
377 { $$ = InterpCreate($1, $3); }
379 { $$ = InterpCreate($1, NULL); }
382 VarDeclList : VarDeclList VarDecl
383 { $$ = (VarDef *)AppendStmt(&$1->common, &$2->common); }
388 KeyTypeDecl : TYPE String OBRACE
391 { $$ = KeyTypeCreate($2, $4); }
394 SymbolsDecl : KEY KeyName OBRACE
397 { $$ = SymbolsCreate($2, (ExprDef *)$4); }
400 SymbolsBody : SymbolsBody COMMA SymbolsVarDecl
401 { $$ = (VarDef *)AppendStmt(&$1->common, &$3->common); }
407 SymbolsVarDecl : Lhs EQUALS Expr { $$ = VarCreate($1, $3); }
408 | Lhs EQUALS ArrayInit { $$ = VarCreate($1, $3); }
409 | Ident { $$ = BoolVarCreate($1, 1); }
410 | EXCLAM Ident { $$ = BoolVarCreate($2, 0); }
411 | ArrayInit { $$ = VarCreate(NULL, $1); }
414 ArrayInit : OBRACKET OptKeySymList CBRACKET
416 | OBRACKET ActionList CBRACKET
417 { $$ = ExprCreateUnary(EXPR_ACTION_LIST, EXPR_TYPE_ACTION, $2); }
420 GroupCompatDecl : GROUP Integer EQUALS Expr SEMI
421 { $$ = GroupCompatCreate($2, $4); }
424 ModMapDecl : MODIFIER_MAP Ident OBRACE ExprList CBRACE SEMI
425 { $$ = ModMapCreate($2, $4); }
428 IndicatorMapDecl: INDICATOR String OBRACE VarDeclList CBRACE SEMI
429 { $$ = IndicatorMapCreate($2, $4); }
432 IndicatorNameDecl: INDICATOR Integer EQUALS Expr SEMI
433 { $$ = IndicatorNameCreate($2, $4, false); }
434 | VIRTUAL INDICATOR Integer EQUALS Expr SEMI
435 { $$ = IndicatorNameCreate($3, $5, true); }
438 ShapeDecl : SHAPE String OBRACE OutlineList CBRACE SEMI
440 | SHAPE String OBRACE CoordList CBRACE SEMI
444 SectionDecl : SECTION String OBRACE SectionBody CBRACE SEMI
448 SectionBody : SectionBody SectionBodyItem { $$ = NULL;}
449 | SectionBodyItem { $$ = NULL; }
452 SectionBodyItem : ROW OBRACE RowBody CBRACE SEMI
455 { FreeStmt(&$1->common); $$ = NULL; }
459 { FreeStmt(&$1->common); $$ = NULL; }
464 RowBody : RowBody RowBodyItem { $$ = NULL;}
465 | RowBodyItem { $$ = NULL; }
468 RowBodyItem : KEYS OBRACE Keys CBRACE SEMI { $$ = NULL; }
470 { FreeStmt(&$1->common); $$ = NULL; }
473 Keys : Keys COMMA Key { $$ = NULL; }
479 | OBRACE ExprList CBRACE
480 { FreeStmt(&$2->common); $$ = NULL; }
483 OverlayDecl : OVERLAY String OBRACE OverlayKeyList CBRACE SEMI
487 OverlayKeyList : OverlayKeyList COMMA OverlayKey { $$ = NULL; }
488 | OverlayKey { $$ = NULL; }
491 OverlayKey : KeyName EQUALS KeyName { $$ = NULL; }
494 OutlineList : OutlineList COMMA OutlineInList
500 OutlineInList : OBRACE CoordList CBRACE
502 | Ident EQUALS OBRACE CoordList CBRACE
505 { FreeStmt(&$3->common); $$ = NULL; }
508 CoordList : CoordList COMMA Coord
514 Coord : OBRACKET SignedNumber COMMA SignedNumber CBRACKET
518 DoodadDecl : DoodadType String OBRACE VarDeclList CBRACE SEMI
519 { FreeStmt(&$4->common); $$ = NULL; }
522 DoodadType : TEXT { $$ = 0; }
523 | OUTLINE { $$ = 0; }
528 FieldSpec : Ident { $$ = $1; }
529 | Element { $$ = $1; }
533 { $$ = xkb_atom_intern(param->ctx, "action"); }
535 { $$ = xkb_atom_intern(param->ctx, "interpret"); }
537 { $$ = xkb_atom_intern(param->ctx, "type"); }
539 { $$ = xkb_atom_intern(param->ctx, "key"); }
541 { $$ = xkb_atom_intern(param->ctx, "group"); }
543 {$$ = xkb_atom_intern(param->ctx, "modifier_map");}
545 { $$ = xkb_atom_intern(param->ctx, "indicator"); }
547 { $$ = xkb_atom_intern(param->ctx, "shape"); }
549 { $$ = XKB_ATOM_NONE; }
551 { $$ = XKB_ATOM_NONE; }
553 { $$ = XKB_ATOM_NONE; }
556 OptMergeMode : MergeMode { $$ = $1; }
557 | { $$ = MERGE_DEFAULT; }
560 MergeMode : INCLUDE { $$ = MERGE_DEFAULT; }
561 | AUGMENT { $$ = MERGE_AUGMENT; }
562 | OVERRIDE { $$ = MERGE_OVERRIDE; }
563 | REPLACE { $$ = MERGE_REPLACE; }
567 * This used to be MERGE_ALT_FORM. This functionality was
568 * unused and has been removed.
574 OptExprList : ExprList { $$ = $1; }
578 ExprList : ExprList COMMA Expr
579 { $$ = (ExprDef *)AppendStmt(&$1->common, &$3->common); }
584 Expr : Expr DIVIDE Expr
585 { $$ = ExprCreateBinary(EXPR_DIVIDE, $1, $3); }
587 { $$ = ExprCreateBinary(EXPR_ADD, $1, $3); }
589 { $$ = ExprCreateBinary(EXPR_SUBTRACT, $1, $3); }
591 { $$ = ExprCreateBinary(EXPR_MULTIPLY, $1, $3); }
593 { $$ = ExprCreateBinary(EXPR_ASSIGN, $1, $3); }
599 { $$ = ExprCreateUnary(EXPR_NEGATE, $2->value_type, $2); }
601 { $$ = ExprCreateUnary(EXPR_UNARY_PLUS, $2->value_type, $2); }
603 { $$ = ExprCreateUnary(EXPR_NOT, EXPR_TYPE_BOOLEAN, $2); }
605 { $$ = ExprCreateUnary(EXPR_INVERT, $2->value_type, $2); }
608 | FieldSpec OPAREN OptExprList CPAREN %prec OPAREN
609 { $$ = ActionCreate($1, $3); }
616 ActionList : ActionList COMMA Action
617 { $$ = (ExprDef *)AppendStmt(&$1->common, &$3->common); }
622 Action : FieldSpec OPAREN OptExprList CPAREN
623 { $$ = ActionCreate($1, $3); }
629 expr = ExprCreate(EXPR_IDENT, EXPR_TYPE_UNKNOWN);
630 expr->value.str = $1;
633 | FieldSpec DOT FieldSpec
636 expr = ExprCreate(EXPR_FIELD_REF, EXPR_TYPE_UNKNOWN);
637 expr->value.field.element = $1;
638 expr->value.field.field = $3;
641 | FieldSpec OBRACKET Expr CBRACKET
644 expr = ExprCreate(EXPR_ARRAY_REF, EXPR_TYPE_UNKNOWN);
645 expr->value.array.element = XKB_ATOM_NONE;
646 expr->value.array.field = $1;
647 expr->value.array.entry = $3;
650 | FieldSpec DOT FieldSpec OBRACKET Expr CBRACKET
653 expr = ExprCreate(EXPR_ARRAY_REF, EXPR_TYPE_UNKNOWN);
654 expr->value.array.element = $1;
655 expr->value.array.field = $3;
656 expr->value.array.entry = $5;
664 expr = ExprCreate(EXPR_VALUE, EXPR_TYPE_STRING);
665 expr->value.str = $1;
671 expr = ExprCreate(EXPR_VALUE, EXPR_TYPE_INT);
672 expr->value.ival = $1;
682 expr = ExprCreate(EXPR_VALUE, EXPR_TYPE_KEYNAME);
683 strncpy(expr->value.keyName, $1, XKB_KEY_NAME_LENGTH);
688 OptKeySymList : KeySymList { $$ = $1; }
692 KeySymList : KeySymList COMMA KeySym
693 { $$ = AppendKeysymList($1, $3); }
694 | KeySymList COMMA KeySyms
695 { $$ = AppendMultiKeysymList($1, $3); }
697 { $$ = CreateKeysymList($1); }
699 { $$ = CreateMultiKeysymList($1); }
702 KeySyms : OBRACE KeySymList CBRACE
706 KeySym : IDENT { $$ = $1; }
707 | SECTION { $$ = strdup("section"); }
710 if ($1 < 10) { /* XK_0 .. XK_9 */
717 snprintf($$, 17, "0x%x", $1);
722 SignedNumber : MINUS Number { $$ = -$2; }
723 | Number { $$ = $1; }
726 Number : FLOAT { $$ = $1; }
727 | INTEGER { $$ = $1; }
730 Float : FLOAT { $$ = 0; }
733 Integer : INTEGER { $$ = $1; }
736 KeyCode : INTEGER { $$ = $1; }
739 KeyName : KEYNAME { strncpy($$, $1, XKB_KEY_NAME_LENGTH); }
742 Ident : IDENT { $$ = xkb_atom_steal(param->ctx, $1); }
743 | DEFAULT { $$ = xkb_atom_intern(param->ctx, "default"); }
746 String : STRING { $$ = xkb_atom_steal(param->ctx, $1); }
749 OptMapName : MapName { $$ = $1; }
753 MapName : STRING { $$ = $1; }