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
179 XkbFile : XkbCompositeMap
180 { $$ = param->rtrn = $1; }
182 { $$ = param->rtrn = $1; }
185 XkbCompositeMap : OptFlags XkbCompositeType OptMapName OBRACE
188 { $$ = XkbFileCreate(param->ctx, $2, $3, &$5->common, $1); }
191 XkbCompositeType: XKB_KEYMAP { $$ = FILE_TYPE_KEYMAP; }
192 | XKB_SEMANTICS { $$ = FILE_TYPE_KEYMAP; }
193 | XKB_LAYOUT { $$ = FILE_TYPE_KEYMAP; }
196 XkbMapConfigList : XkbMapConfigList XkbMapConfig
201 $$ = (XkbFile *)AppendStmt(&$1->common, &$2->common);
207 XkbMapConfig : OptFlags FileType OptMapName OBRACE
211 if ($2 == FILE_TYPE_GEOMETRY) {
217 $$ = XkbFileCreate(param->ctx, $2, $3, $5, $1);
222 FileType : XKB_KEYCODES { $$ = FILE_TYPE_KEYCODES; }
223 | XKB_TYPES { $$ = FILE_TYPE_TYPES; }
224 | XKB_COMPATMAP { $$ = FILE_TYPE_COMPAT; }
225 | XKB_SYMBOLS { $$ = FILE_TYPE_SYMBOLS; }
226 | XKB_GEOMETRY { $$ = FILE_TYPE_GEOMETRY; }
229 OptFlags : Flags { $$ = $1; }
233 Flags : Flags Flag { $$ = ($1 | $2); }
237 Flag : PARTIAL { $$ = MAP_IS_PARTIAL; }
238 | DEFAULT { $$ = MAP_IS_DEFAULT; }
239 | HIDDEN { $$ = MAP_IS_HIDDEN; }
240 | ALPHANUMERIC_KEYS { $$ = MAP_HAS_ALPHANUMERIC; }
241 | MODIFIER_KEYS { $$ = MAP_HAS_MODIFIER; }
242 | KEYPAD_KEYS { $$ = MAP_HAS_KEYPAD; }
243 | FUNCTION_KEYS { $$ = MAP_HAS_FN; }
244 | ALTERNATE_GROUP { $$ = MAP_IS_ALTGR; }
247 DeclList : DeclList Decl
248 { $$ = AppendStmt($1, $2); }
252 Decl : OptMergeMode VarDecl
257 | OptMergeMode VModDecl
262 | OptMergeMode InterpretDecl
267 | OptMergeMode KeyNameDecl
272 | OptMergeMode KeyAliasDecl
277 | OptMergeMode KeyTypeDecl
282 | OptMergeMode SymbolsDecl
287 | OptMergeMode ModMapDecl
292 | OptMergeMode GroupCompatDecl
297 | OptMergeMode IndicatorMapDecl
302 | OptMergeMode IndicatorNameDecl
307 | OptMergeMode ShapeDecl { }
308 | OptMergeMode SectionDecl { }
309 | OptMergeMode DoodadDecl { }
312 $$ = &IncludeCreate(param->ctx, $2, $1)->common;
317 VarDecl : Lhs EQUALS Expr SEMI
318 { $$ = VarCreate($1, $3); }
320 { $$ = BoolVarCreate($1, 1); }
322 { $$ = BoolVarCreate($2, 0); }
325 KeyNameDecl : KEYNAME EQUALS KeyCode SEMI
326 { $$ = KeycodeCreate($1, $3); }
329 KeyAliasDecl : ALIAS KEYNAME EQUALS KEYNAME SEMI
330 { $$ = KeyAliasCreate($2, $4); }
333 VModDecl : VIRTUAL_MODS VModDefList SEMI
337 VModDefList : VModDefList COMMA VModDef
338 { $$ = (VModDef *)AppendStmt(&$1->common, &$3->common); }
344 { $$ = VModCreate($1, NULL); }
346 { $$ = VModCreate($1, $3); }
349 InterpretDecl : INTERPRET InterpretMatch OBRACE
352 { $2->def = $4; $$ = $2; }
355 InterpretMatch : KeySym PLUS Expr
356 { $$ = InterpCreate($1, $3); }
358 { $$ = InterpCreate($1, NULL); }
361 VarDeclList : VarDeclList VarDecl
362 { $$ = (VarDef *)AppendStmt(&$1->common, &$2->common); }
367 KeyTypeDecl : TYPE String OBRACE
370 { $$ = KeyTypeCreate($2, $4); }
373 SymbolsDecl : KEY KEYNAME OBRACE
376 { $$ = SymbolsCreate($2, (ExprDef *)$4); }
379 SymbolsBody : SymbolsBody COMMA SymbolsVarDecl
380 { $$ = (VarDef *)AppendStmt(&$1->common, &$3->common); }
386 SymbolsVarDecl : Lhs EQUALS Expr { $$ = VarCreate($1, $3); }
387 | Lhs EQUALS ArrayInit { $$ = VarCreate($1, $3); }
388 | Ident { $$ = BoolVarCreate($1, 1); }
389 | EXCLAM Ident { $$ = BoolVarCreate($2, 0); }
390 | ArrayInit { $$ = VarCreate(NULL, $1); }
393 ArrayInit : OBRACKET OptKeySymList CBRACKET
395 | OBRACKET ActionList CBRACKET
396 { $$ = ExprCreateUnary(EXPR_ACTION_LIST, EXPR_TYPE_ACTION, $2); }
399 GroupCompatDecl : GROUP Integer EQUALS Expr SEMI
400 { $$ = GroupCompatCreate($2, $4); }
403 ModMapDecl : MODIFIER_MAP Ident OBRACE ExprList CBRACE SEMI
404 { $$ = ModMapCreate($2, $4); }
407 IndicatorMapDecl: INDICATOR String OBRACE VarDeclList CBRACE SEMI
408 { $$ = IndicatorMapCreate($2, $4); }
411 IndicatorNameDecl: INDICATOR Integer EQUALS Expr SEMI
412 { $$ = IndicatorNameCreate($2, $4, false); }
413 | VIRTUAL INDICATOR Integer EQUALS Expr SEMI
414 { $$ = IndicatorNameCreate($3, $5, true); }
417 ShapeDecl : SHAPE String OBRACE OutlineList CBRACE SEMI
419 | SHAPE String OBRACE CoordList CBRACE SEMI
423 SectionDecl : SECTION String OBRACE SectionBody CBRACE SEMI
427 SectionBody : SectionBody SectionBodyItem { $$ = NULL;}
428 | SectionBodyItem { $$ = NULL; }
431 SectionBodyItem : ROW OBRACE RowBody CBRACE SEMI
434 { FreeStmt(&$1->common); $$ = NULL; }
438 { FreeStmt(&$1->common); $$ = NULL; }
443 RowBody : RowBody RowBodyItem { $$ = NULL;}
444 | RowBodyItem { $$ = NULL; }
447 RowBodyItem : KEYS OBRACE Keys CBRACE SEMI { $$ = NULL; }
449 { FreeStmt(&$1->common); $$ = NULL; }
452 Keys : Keys COMMA Key { $$ = NULL; }
458 | OBRACE ExprList CBRACE
459 { FreeStmt(&$2->common); $$ = NULL; }
462 OverlayDecl : OVERLAY String OBRACE OverlayKeyList CBRACE SEMI
466 OverlayKeyList : OverlayKeyList COMMA OverlayKey { $$ = NULL; }
467 | OverlayKey { $$ = NULL; }
470 OverlayKey : KEYNAME EQUALS KEYNAME { $$ = NULL; }
473 OutlineList : OutlineList COMMA OutlineInList
479 OutlineInList : OBRACE CoordList CBRACE
481 | Ident EQUALS OBRACE CoordList CBRACE
484 { FreeStmt(&$3->common); $$ = NULL; }
487 CoordList : CoordList COMMA Coord
493 Coord : OBRACKET SignedNumber COMMA SignedNumber CBRACKET
497 DoodadDecl : DoodadType String OBRACE VarDeclList CBRACE SEMI
498 { FreeStmt(&$4->common); $$ = NULL; }
501 DoodadType : TEXT { $$ = 0; }
502 | OUTLINE { $$ = 0; }
507 FieldSpec : Ident { $$ = $1; }
508 | Element { $$ = $1; }
512 { $$ = xkb_atom_intern(param->ctx, "action"); }
514 { $$ = xkb_atom_intern(param->ctx, "interpret"); }
516 { $$ = xkb_atom_intern(param->ctx, "type"); }
518 { $$ = xkb_atom_intern(param->ctx, "key"); }
520 { $$ = xkb_atom_intern(param->ctx, "group"); }
522 {$$ = xkb_atom_intern(param->ctx, "modifier_map");}
524 { $$ = xkb_atom_intern(param->ctx, "indicator"); }
526 { $$ = xkb_atom_intern(param->ctx, "shape"); }
528 { $$ = XKB_ATOM_NONE; }
530 { $$ = XKB_ATOM_NONE; }
532 { $$ = XKB_ATOM_NONE; }
535 OptMergeMode : MergeMode { $$ = $1; }
536 | { $$ = MERGE_DEFAULT; }
539 MergeMode : INCLUDE { $$ = MERGE_DEFAULT; }
540 | AUGMENT { $$ = MERGE_AUGMENT; }
541 | OVERRIDE { $$ = MERGE_OVERRIDE; }
542 | REPLACE { $$ = MERGE_REPLACE; }
546 * This used to be MERGE_ALT_FORM. This functionality was
547 * unused and has been removed.
553 OptExprList : ExprList { $$ = $1; }
557 ExprList : ExprList COMMA Expr
558 { $$ = (ExprDef *)AppendStmt(&$1->common, &$3->common); }
563 Expr : Expr DIVIDE Expr
564 { $$ = ExprCreateBinary(EXPR_DIVIDE, $1, $3); }
566 { $$ = ExprCreateBinary(EXPR_ADD, $1, $3); }
568 { $$ = ExprCreateBinary(EXPR_SUBTRACT, $1, $3); }
570 { $$ = ExprCreateBinary(EXPR_MULTIPLY, $1, $3); }
572 { $$ = ExprCreateBinary(EXPR_ASSIGN, $1, $3); }
578 { $$ = ExprCreateUnary(EXPR_NEGATE, $2->value_type, $2); }
580 { $$ = ExprCreateUnary(EXPR_UNARY_PLUS, $2->value_type, $2); }
582 { $$ = ExprCreateUnary(EXPR_NOT, EXPR_TYPE_BOOLEAN, $2); }
584 { $$ = ExprCreateUnary(EXPR_INVERT, $2->value_type, $2); }
587 | FieldSpec OPAREN OptExprList CPAREN %prec OPAREN
588 { $$ = ActionCreate($1, $3); }
595 ActionList : ActionList COMMA Action
596 { $$ = (ExprDef *)AppendStmt(&$1->common, &$3->common); }
601 Action : FieldSpec OPAREN OptExprList CPAREN
602 { $$ = ActionCreate($1, $3); }
608 expr = ExprCreate(EXPR_IDENT, EXPR_TYPE_UNKNOWN);
609 expr->value.str = $1;
612 | FieldSpec DOT FieldSpec
615 expr = ExprCreate(EXPR_FIELD_REF, EXPR_TYPE_UNKNOWN);
616 expr->value.field.element = $1;
617 expr->value.field.field = $3;
620 | FieldSpec OBRACKET Expr CBRACKET
623 expr = ExprCreate(EXPR_ARRAY_REF, EXPR_TYPE_UNKNOWN);
624 expr->value.array.element = XKB_ATOM_NONE;
625 expr->value.array.field = $1;
626 expr->value.array.entry = $3;
629 | FieldSpec DOT FieldSpec OBRACKET Expr CBRACKET
632 expr = ExprCreate(EXPR_ARRAY_REF, EXPR_TYPE_UNKNOWN);
633 expr->value.array.element = $1;
634 expr->value.array.field = $3;
635 expr->value.array.entry = $5;
643 expr = ExprCreate(EXPR_VALUE, EXPR_TYPE_STRING);
644 expr->value.str = $1;
650 expr = ExprCreate(EXPR_VALUE, EXPR_TYPE_INT);
651 expr->value.ival = $1;
661 expr = ExprCreate(EXPR_VALUE, EXPR_TYPE_KEYNAME);
662 expr->value.keyName = $1;
667 OptKeySymList : KeySymList { $$ = $1; }
671 KeySymList : KeySymList COMMA KeySym
672 { $$ = AppendKeysymList($1, $3); }
673 | KeySymList COMMA KeySyms
674 { $$ = AppendMultiKeysymList($1, $3); }
676 { $$ = CreateKeysymList($1); }
678 { $$ = CreateMultiKeysymList($1); }
681 KeySyms : OBRACE KeySymList CBRACE
685 KeySym : IDENT { $$ = $1; }
686 | SECTION { $$ = strdup("section"); }
689 if ($1 < 10) { /* XK_0 .. XK_9 */
696 snprintf($$, 17, "0x%x", $1);
701 SignedNumber : MINUS Number { $$ = -$2; }
702 | Number { $$ = $1; }
705 Number : FLOAT { $$ = $1; }
706 | INTEGER { $$ = $1; }
709 Float : FLOAT { $$ = 0; }
712 Integer : INTEGER { $$ = $1; }
715 KeyCode : INTEGER { $$ = $1; }
718 Ident : IDENT { $$ = xkb_atom_steal(param->ctx, $1); }
719 | DEFAULT { $$ = xkb_atom_intern(param->ctx, "default"); }
722 String : STRING { $$ = xkb_atom_steal(param->ctx, $1); }
725 OptMapName : MapName { $$ = $1; }
729 MapName : STRING { $$ = $1; }