xref: /OK3568_Linux_fs/external/xserver/hw/dmx/config/parser.y (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* $XFree86$ */
2 /*
3  * Copyright 2002-2003 Red Hat Inc., Durham, North Carolina.
4  *
5  * All Rights Reserved.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation on the rights to use, copy, modify, merge,
11  * publish, distribute, sublicense, and/or sell copies of the Software,
12  * and to permit persons to whom the Software is furnished to do so,
13  * subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice (including the
16  * next paragraph) shall be included in all copies or substantial
17  * portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22  * NON-INFRINGEMENT.  IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
23  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
24  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26  * SOFTWARE.
27  */
28 
29 /*
30  * Authors:
31  *   Rickard E. (Rik) Faith <faith@redhat.com>
32  *
33  */
34 
35 %{
36 #ifdef HAVE_DMX_CONFIG_H
37 #include <dmx-config.h>
38 #endif
39 
40 #include "dmxparse.h"
41 #include <string.h>
42 #include <stdlib.h>
43 #define YYDEBUG 1
44 #define YYERROR_VERBOSE
45 #define YY_USE_PROTOS
46 
47 extern int yylex(void);
48 DMXConfigEntryPtr dmxConfigEntry = NULL;
49 #define APPEND(type, h, t)                 \
50 {                                          \
51     type pt;                               \
52     for (pt = h; pt->next; pt = pt->next); \
53     pt->next = t;                          \
54 }
55 %}
56 
57 %union {
58     DMXConfigTokenPtr      token;
59     DMXConfigStringPtr     string;
60     DMXConfigNumberPtr     number;
61     DMXConfigPairPtr       pair;
62     DMXConfigFullDimPtr    fdim;
63     DMXConfigPartDimPtr    pdim;
64     DMXConfigDisplayPtr    display;
65     DMXConfigWallPtr       wall;
66     DMXConfigOptionPtr     option;
67     DMXConfigParamPtr      param;
68     DMXConfigCommentPtr    comment;
69     DMXConfigSubPtr        subentry;
70     DMXConfigVirtualPtr    virtual;
71     DMXConfigEntryPtr      entry;
72 }
73 
74 				/* Terminals */
75 %token <token>   '{' '}' ';' '/' T_VIRTUAL T_DISPLAY T_WALL T_OPTION T_PARAM
76 %token <string>  T_STRING
77 %token <pair>    T_DIMENSION T_OFFSET T_ORIGIN
78 %token <comment> T_COMMENT T_LINE_COMMENT
79 
80                                 /* Non-termials */
81 %type  <token>    Display Wall Terminal Open Close
82 %type  <string>   NameList Name
83 %type  <pair>     Dimension Offset Origin
84 %type  <pdim>     PartialDim
85 %type  <fdim>     FullDim
86 %type  <display>  DisplayEntry
87 %type  <option>   OptionEntry
88 %type  <param>    ParamEntry ParamList Param
89 %type  <subentry> SubList Sub
90 %type  <wall>     WallEntry
91 %type  <virtual>  Virtual
92 %type  <entry>    Program EntryList Entry
93 
94 %%
95 
96 Program : EntryList { dmxConfigEntry = $1; }
97         ;
98 
99 EntryList : Entry
100           | EntryList Entry { APPEND(DMXConfigEntryPtr,$1,$2); $$ = $1; }
101           ;
102 
103 Entry : Virtual        { $$ = dmxConfigEntryVirtual($1); }
104       | T_LINE_COMMENT { $$ = dmxConfigEntryComment($1); }
105       ;
106 
107 Virtual : T_VIRTUAL Open SubList Close
108           { $$ = dmxConfigCreateVirtual($1, NULL, NULL, $2, $3, $4); }
109         | T_VIRTUAL Dimension Open SubList Close
110           { $$ = dmxConfigCreateVirtual($1, NULL, $2, $3, $4, $5); }
111         | T_VIRTUAL Name Open SubList Close
112           { $$ = dmxConfigCreateVirtual($1, $2, NULL, $3, $4, $5); }
113         | T_VIRTUAL Name Dimension Open SubList Close
114           { $$ = dmxConfigCreateVirtual($1, $2, $3, $4, $5, $6 ); }
115         ;
116 
117 SubList : Sub
118         | SubList Sub { APPEND(DMXConfigSubPtr,$1,$2); $$ = $1; }
119         ;
120 
121 Sub : T_LINE_COMMENT { $$ = dmxConfigSubComment($1); }
122     | DisplayEntry   { $$ = dmxConfigSubDisplay($1); }
123     | WallEntry      { $$ = dmxConfigSubWall($1); }
124     | OptionEntry    { $$ = dmxConfigSubOption($1); }
125     | ParamEntry     { $$ = dmxConfigSubParam($1); }
126     ;
127 
128 OptionEntry : T_OPTION NameList Terminal
129               { $$ = dmxConfigCreateOption($1, $2, $3); }
130             ;
131 
132 ParamEntry : T_PARAM NameList Terminal
133              { $$ = dmxConfigCreateParam($1, NULL, $2, NULL, $3); }
134            | T_PARAM Open ParamList Close
135              { $$ = dmxConfigCreateParam($1, $2, NULL, $4, NULL);
136                $$->next = $3;
137              }
138            ;
139 
140 ParamList : Param
141           | ParamList Param { APPEND(DMXConfigParamPtr,$1,$2); $$ = $1; }
142           ;
143 
144 Param : NameList Terminal
145         { $$ = dmxConfigCreateParam(NULL, NULL, $1, NULL, $2); }
146       ;
147 
148 PartialDim : Dimension Offset
149              { $$ = dmxConfigCreatePartDim($1, $2); }
150            | Dimension
151              { $$ = dmxConfigCreatePartDim($1, NULL); }
152            | Offset
153              { $$ = dmxConfigCreatePartDim(NULL, $1); }
154            ;
155 
156 FullDim : PartialDim '/' PartialDim
157           { $$ = dmxConfigCreateFullDim($1, $3); }
158         | '/' PartialDim
159           { $$ = dmxConfigCreateFullDim(NULL, $2); }
160         | PartialDim
161           { $$ = dmxConfigCreateFullDim($1, NULL); }
162         ;
163 
164 DisplayEntry : Display Name FullDim Origin Terminal
165                { $$ = dmxConfigCreateDisplay($1, $2, $3, $4, $5); }
166              | Display FullDim Origin Terminal
167                { $$ = dmxConfigCreateDisplay($1, NULL, $2, $3, $4); }
168              | Display Name Origin Terminal
169                { $$ = dmxConfigCreateDisplay($1, $2, NULL, $3, $4); }
170 
171              | Display Name FullDim Terminal
172                { $$ = dmxConfigCreateDisplay($1, $2, $3, NULL, $4); }
173              | Display FullDim Terminal
174                { $$ = dmxConfigCreateDisplay($1, NULL, $2, NULL, $3); }
175              | Display Name Terminal
176                { $$ = dmxConfigCreateDisplay($1, $2, NULL, NULL, $3); }
177              | Display Terminal
178                { $$ = dmxConfigCreateDisplay($1, NULL, NULL, NULL, $2); }
179              ;
180 
181 WallEntry : Wall Dimension Dimension NameList Terminal
182             { $$ = dmxConfigCreateWall($1, $2, $3, $4, $5); }
183           | Wall Dimension NameList Terminal
184             { $$ = dmxConfigCreateWall($1, $2, NULL, $3, $4); }
185           | Wall NameList Terminal
186             { $$ = dmxConfigCreateWall($1, NULL, NULL, $2, $3); }
187           ;
188 
189 Display : T_DISPLAY
190         | T_DISPLAY T_COMMENT { $$ = $1; $$->comment = $2->comment; }
191         ;
192 
193 Name : T_STRING
194      | T_STRING T_COMMENT { $$ = $1; $$->comment = $2->comment; }
195      ;
196 
197 Dimension : T_DIMENSION
198           | T_DIMENSION T_COMMENT { $$ = $1; $$->comment = $2->comment; }
199           ;
200 
201 Offset : T_OFFSET
202        | T_OFFSET T_COMMENT { $$ = $1; $$->comment = $2->comment; }
203        ;
204 
205 Origin : T_ORIGIN
206        | T_ORIGIN T_COMMENT { $$ = $1; $$->comment = $2->comment; }
207        ;
208 
209 Terminal : ';'
210          | ';' T_COMMENT { $$ = $1; $$->comment = $2->comment; }
211          ;
212 
213 Open : '{'
214      | '{' T_COMMENT { $$ = $1; $$->comment = $2->comment; }
215      ;
216 
217 Close : '}'
218       | '}' T_COMMENT { $$ = $1; $$->comment = $2->comment; }
219       ;
220 
221 Wall : T_WALL
222      | T_WALL T_COMMENT { $$ = $1; $$->comment = $2->comment; }
223      ;
224 
225 NameList : Name
226          | NameList Name { APPEND(DMXConfigStringPtr, $1, $2); $$ = $1; }
227          ;
228