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 _xkbcommon_error(struct YYLTYPE *loc, struct parser_param *param, const char *msg)
35 scanner_error(loc, param->scanner, msg);
38 #define scanner param->scanner
41 %name-prefix "_xkbcommon_"
44 %lex-param { void *scanner }
45 %parse-param { struct parser_param *param }
124 enum xkb_file_type file_type;
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
150 %type <ival> Number Integer Float SignedNumber
151 %type <merge> MergeMode OptMergeMode
152 %type <file_type> XkbCompositeType FileType
153 %type <uval> DoodadType
154 %type <mapFlags> Flag Flags OptFlags
155 %type <str> MapName OptMapName KeySym
156 %type <sval> FieldSpec Ident Element String
157 %type <any> DeclList Decl
158 %type <expr> OptExprList ExprList Expr Term Lhs Terminal ArrayInit KeySyms
159 %type <expr> OptKeySymList KeySymList Action ActionList Coord CoordList
160 %type <var> VarDecl VarDeclList SymbolsBody SymbolsVarDecl
161 %type <vmod> VModDecl VModDefList VModDef
162 %type <interp> InterpretDecl InterpretMatch
163 %type <keyType> KeyTypeDecl
164 %type <syms> SymbolsDecl
165 %type <modMask> ModMapDecl
166 %type <groupCompat> GroupCompatDecl
167 %type <ledMap> IndicatorMapDecl
168 %type <ledName> IndicatorNameDecl
169 %type <keyCode> KeyNameDecl
170 %type <keyAlias> KeyAliasDecl
171 %type <geom> ShapeDecl SectionDecl SectionBody SectionBodyItem RowBody RowBodyItem
172 %type <geom> Keys Key OverlayDecl OverlayKeyList OverlayKey OutlineList OutlineInList
173 %type <geom> DoodadDecl
174 %type <file> XkbFile XkbMapConfigList XkbMapConfig
175 %type <file> XkbCompositeMap XkbCompMapList
179 XkbFile : XkbCompMapList
180 { $$ = param->rtrn = $1; }
182 { $$ = param->rtrn = $1; }
185 XkbCompMapList : XkbCompMapList XkbCompositeMap
186 { $$ = (XkbFile *)AppendStmt(&$1->common, &$2->common); }
191 XkbCompositeMap : OptFlags XkbCompositeType OptMapName OBRACE
194 { $$ = XkbFileCreate(param->ctx, $2, $3, &$5->common, $1); }
197 XkbCompositeType: XKB_KEYMAP { $$ = FILE_TYPE_KEYMAP; }
198 | XKB_SEMANTICS { $$ = FILE_TYPE_KEYMAP; }
199 | XKB_LAYOUT { $$ = FILE_TYPE_KEYMAP; }
202 XkbMapConfigList : XkbMapConfigList XkbMapConfig
207 $$ = (XkbFile *)AppendStmt(&$1->common, &$2->common);
213 XkbMapConfig : OptFlags FileType OptMapName OBRACE
217 if ($2 == FILE_TYPE_GEOMETRY) {
223 $$ = XkbFileCreate(param->ctx, $2, $3, $5, $1);
228 FileType : XKB_KEYCODES { $$ = FILE_TYPE_KEYCODES; }
229 | XKB_TYPES { $$ = FILE_TYPE_TYPES; }
230 | XKB_COMPATMAP { $$ = FILE_TYPE_COMPAT; }
231 | XKB_SYMBOLS { $$ = FILE_TYPE_SYMBOLS; }
232 | XKB_GEOMETRY { $$ = FILE_TYPE_GEOMETRY; }
235 OptFlags : Flags { $$ = $1; }
239 Flags : Flags Flag { $$ = ($1 | $2); }
243 Flag : PARTIAL { $$ = MAP_IS_PARTIAL; }
244 | DEFAULT { $$ = MAP_IS_DEFAULT; }
245 | HIDDEN { $$ = MAP_IS_HIDDEN; }
246 | ALPHANUMERIC_KEYS { $$ = MAP_HAS_ALPHANUMERIC; }
247 | MODIFIER_KEYS { $$ = MAP_HAS_MODIFIER; }
248 | KEYPAD_KEYS { $$ = MAP_HAS_KEYPAD; }
249 | FUNCTION_KEYS { $$ = MAP_HAS_FN; }
250 | ALTERNATE_GROUP { $$ = MAP_IS_ALTGR; }
253 DeclList : DeclList Decl
254 { $$ = AppendStmt($1, $2); }
258 Decl : OptMergeMode VarDecl
263 | OptMergeMode VModDecl
268 | OptMergeMode InterpretDecl
273 | OptMergeMode KeyNameDecl
278 | OptMergeMode KeyAliasDecl
283 | OptMergeMode KeyTypeDecl
288 | OptMergeMode SymbolsDecl
293 | OptMergeMode ModMapDecl
298 | OptMergeMode GroupCompatDecl
303 | OptMergeMode IndicatorMapDecl
308 | OptMergeMode IndicatorNameDecl
313 | OptMergeMode ShapeDecl { }
314 | OptMergeMode SectionDecl { }
315 | OptMergeMode DoodadDecl { }
318 $$ = &IncludeCreate(param->ctx, $2, $1)->common;
323 VarDecl : Lhs EQUALS Expr SEMI
324 { $$ = VarCreate($1, $3); }
326 { $$ = BoolVarCreate($1, 1); }
328 { $$ = BoolVarCreate($2, 0); }
331 KeyNameDecl : KEYNAME EQUALS KeyCode SEMI
332 { $$ = KeycodeCreate($1, $3); }
335 KeyAliasDecl : ALIAS KEYNAME EQUALS KEYNAME SEMI
336 { $$ = KeyAliasCreate($2, $4); }
339 VModDecl : VIRTUAL_MODS VModDefList SEMI
343 VModDefList : VModDefList COMMA VModDef
344 { $$ = (VModDef *)AppendStmt(&$1->common, &$3->common); }
350 { $$ = VModCreate($1, NULL); }
352 { $$ = VModCreate($1, $3); }
355 InterpretDecl : INTERPRET InterpretMatch OBRACE
358 { $2->def = $4; $$ = $2; }
361 InterpretMatch : KeySym PLUS Expr
362 { $$ = InterpCreate($1, $3); }
364 { $$ = InterpCreate($1, NULL); }
367 VarDeclList : VarDeclList VarDecl
368 { $$ = (VarDef *)AppendStmt(&$1->common, &$2->common); }
373 KeyTypeDecl : TYPE String OBRACE
376 { $$ = KeyTypeCreate($2, $4); }
379 SymbolsDecl : KEY KEYNAME OBRACE
382 { $$ = SymbolsCreate($2, (ExprDef *)$4); }
385 SymbolsBody : SymbolsBody COMMA SymbolsVarDecl
386 { $$ = (VarDef *)AppendStmt(&$1->common, &$3->common); }
392 SymbolsVarDecl : Lhs EQUALS Expr { $$ = VarCreate($1, $3); }
393 | Lhs EQUALS ArrayInit { $$ = VarCreate($1, $3); }
394 | Ident { $$ = BoolVarCreate($1, 1); }
395 | EXCLAM Ident { $$ = BoolVarCreate($2, 0); }
396 | ArrayInit { $$ = VarCreate(NULL, $1); }
399 ArrayInit : OBRACKET OptKeySymList CBRACKET
401 | OBRACKET ActionList CBRACKET
402 { $$ = ExprCreateUnary(EXPR_ACTION_LIST, EXPR_TYPE_ACTION, $2); }
405 GroupCompatDecl : GROUP Integer EQUALS Expr SEMI
406 { $$ = GroupCompatCreate($2, $4); }
409 ModMapDecl : MODIFIER_MAP Ident OBRACE ExprList CBRACE SEMI
410 { $$ = ModMapCreate($2, $4); }
413 IndicatorMapDecl: INDICATOR String OBRACE VarDeclList CBRACE SEMI
414 { $$ = IndicatorMapCreate($2, $4); }
417 IndicatorNameDecl: INDICATOR Integer EQUALS Expr SEMI
418 { $$ = IndicatorNameCreate($2, $4, false); }
419 | VIRTUAL INDICATOR Integer EQUALS Expr SEMI
420 { $$ = IndicatorNameCreate($3, $5, true); }
423 ShapeDecl : SHAPE String OBRACE OutlineList CBRACE SEMI
425 | SHAPE String OBRACE CoordList CBRACE SEMI
429 SectionDecl : SECTION String OBRACE SectionBody CBRACE SEMI
433 SectionBody : SectionBody SectionBodyItem { $$ = NULL;}
434 | SectionBodyItem { $$ = NULL; }
437 SectionBodyItem : ROW OBRACE RowBody CBRACE SEMI
440 { FreeStmt(&$1->common); $$ = NULL; }
444 { FreeStmt(&$1->common); $$ = NULL; }
449 RowBody : RowBody RowBodyItem { $$ = NULL;}
450 | RowBodyItem { $$ = NULL; }
453 RowBodyItem : KEYS OBRACE Keys CBRACE SEMI { $$ = NULL; }
455 { FreeStmt(&$1->common); $$ = NULL; }
458 Keys : Keys COMMA Key { $$ = NULL; }
464 | OBRACE ExprList CBRACE
465 { FreeStmt(&$2->common); $$ = NULL; }
468 OverlayDecl : OVERLAY String OBRACE OverlayKeyList CBRACE SEMI
472 OverlayKeyList : OverlayKeyList COMMA OverlayKey { $$ = NULL; }
473 | OverlayKey { $$ = NULL; }
476 OverlayKey : KEYNAME EQUALS KEYNAME { $$ = NULL; }
479 OutlineList : OutlineList COMMA OutlineInList
485 OutlineInList : OBRACE CoordList CBRACE
487 | Ident EQUALS OBRACE CoordList CBRACE
490 { FreeStmt(&$3->common); $$ = NULL; }
493 CoordList : CoordList COMMA Coord
499 Coord : OBRACKET SignedNumber COMMA SignedNumber CBRACKET
503 DoodadDecl : DoodadType String OBRACE VarDeclList CBRACE SEMI
504 { FreeStmt(&$4->common); $$ = NULL; }
507 DoodadType : TEXT { $$ = 0; }
508 | OUTLINE { $$ = 0; }
513 FieldSpec : Ident { $$ = $1; }
514 | Element { $$ = $1; }
518 { $$ = xkb_atom_intern(param->ctx, "action"); }
520 { $$ = xkb_atom_intern(param->ctx, "interpret"); }
522 { $$ = xkb_atom_intern(param->ctx, "type"); }
524 { $$ = xkb_atom_intern(param->ctx, "key"); }
526 { $$ = xkb_atom_intern(param->ctx, "group"); }
528 {$$ = xkb_atom_intern(param->ctx, "modifier_map");}
530 { $$ = xkb_atom_intern(param->ctx, "indicator"); }
532 { $$ = xkb_atom_intern(param->ctx, "shape"); }
534 { $$ = XKB_ATOM_NONE; }
536 { $$ = XKB_ATOM_NONE; }
538 { $$ = XKB_ATOM_NONE; }
541 OptMergeMode : MergeMode { $$ = $1; }
542 | { $$ = MERGE_DEFAULT; }
545 MergeMode : INCLUDE { $$ = MERGE_DEFAULT; }
546 | AUGMENT { $$ = MERGE_AUGMENT; }
547 | OVERRIDE { $$ = MERGE_OVERRIDE; }
548 | REPLACE { $$ = MERGE_REPLACE; }
552 * This used to be MERGE_ALT_FORM. This functionality was
553 * unused and has been removed.
559 OptExprList : ExprList { $$ = $1; }
563 ExprList : ExprList COMMA Expr
564 { $$ = (ExprDef *)AppendStmt(&$1->common, &$3->common); }
569 Expr : Expr DIVIDE Expr
570 { $$ = ExprCreateBinary(EXPR_DIVIDE, $1, $3); }
572 { $$ = ExprCreateBinary(EXPR_ADD, $1, $3); }
574 { $$ = ExprCreateBinary(EXPR_SUBTRACT, $1, $3); }
576 { $$ = ExprCreateBinary(EXPR_MULTIPLY, $1, $3); }
578 { $$ = ExprCreateBinary(EXPR_ASSIGN, $1, $3); }
584 { $$ = ExprCreateUnary(EXPR_NEGATE, $2->value_type, $2); }
586 { $$ = ExprCreateUnary(EXPR_UNARY_PLUS, $2->value_type, $2); }
588 { $$ = ExprCreateUnary(EXPR_NOT, EXPR_TYPE_BOOLEAN, $2); }
590 { $$ = ExprCreateUnary(EXPR_INVERT, $2->value_type, $2); }
593 | FieldSpec OPAREN OptExprList CPAREN %prec OPAREN
594 { $$ = ActionCreate($1, $3); }
601 ActionList : ActionList COMMA Action
602 { $$ = (ExprDef *)AppendStmt(&$1->common, &$3->common); }
607 Action : FieldSpec OPAREN OptExprList CPAREN
608 { $$ = ActionCreate($1, $3); }
614 expr = ExprCreate(EXPR_IDENT, EXPR_TYPE_UNKNOWN);
615 expr->value.str = $1;
618 | FieldSpec DOT FieldSpec
621 expr = ExprCreate(EXPR_FIELD_REF, EXPR_TYPE_UNKNOWN);
622 expr->value.field.element = $1;
623 expr->value.field.field = $3;
626 | FieldSpec OBRACKET Expr CBRACKET
629 expr = ExprCreate(EXPR_ARRAY_REF, EXPR_TYPE_UNKNOWN);
630 expr->value.array.element = XKB_ATOM_NONE;
631 expr->value.array.field = $1;
632 expr->value.array.entry = $3;
635 | FieldSpec DOT FieldSpec OBRACKET Expr CBRACKET
638 expr = ExprCreate(EXPR_ARRAY_REF, EXPR_TYPE_UNKNOWN);
639 expr->value.array.element = $1;
640 expr->value.array.field = $3;
641 expr->value.array.entry = $5;
649 expr = ExprCreate(EXPR_VALUE, EXPR_TYPE_STRING);
650 expr->value.str = $1;
656 expr = ExprCreate(EXPR_VALUE, EXPR_TYPE_INT);
657 expr->value.ival = $1;
667 expr = ExprCreate(EXPR_VALUE, EXPR_TYPE_KEYNAME);
668 expr->value.keyName = $1;
673 OptKeySymList : KeySymList { $$ = $1; }
677 KeySymList : KeySymList COMMA KeySym
678 { $$ = AppendKeysymList($1, $3); }
679 | KeySymList COMMA KeySyms
680 { $$ = AppendMultiKeysymList($1, $3); }
682 { $$ = CreateKeysymList($1); }
684 { $$ = CreateMultiKeysymList($1); }
687 KeySyms : OBRACE KeySymList CBRACE
691 KeySym : IDENT { $$ = $1; }
692 | SECTION { $$ = strdup("section"); }
695 if ($1 < 10) { /* XK_0 .. XK_9 */
702 snprintf($$, 17, "0x%x", $1);
707 SignedNumber : MINUS Number { $$ = -$2; }
708 | Number { $$ = $1; }
711 Number : FLOAT { $$ = $1; }
712 | INTEGER { $$ = $1; }
715 Float : FLOAT { $$ = 0; }
718 Integer : INTEGER { $$ = $1; }
721 KeyCode : INTEGER { $$ = $1; }
724 Ident : IDENT { $$ = xkb_atom_steal(param->ctx, $1); }
725 | DEFAULT { $$ = xkb_atom_intern(param->ctx, "default"); }
728 String : STRING { $$ = xkb_atom_steal(param->ctx, $1); }
731 OptMapName : MapName { $$ = $1; }
735 MapName : STRING { $$ = $1; }