packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmCommandArgumentParser.y
1 %{
2 /*============================================================================
3   CMake - Cross Platform Makefile Generator
4   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5
6   Distributed under the OSI-approved BSD License (the "License");
7   see accompanying file Copyright.txt for details.
8
9   This software is distributed WITHOUT ANY WARRANTY; without even the
10   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11   See the License for more information.
12 ============================================================================*/
13 /*
14
15 This file must be translated to C and modified to build everywhere.
16
17 Run bison like this:
18
19   bison --yacc --name-prefix=cmCommandArgument_yy --defines=cmCommandArgumentParserTokens.h -ocmCommandArgumentParser.cxx cmCommandArgumentParser.y
20
21 Modify cmCommandArgumentParser.cxx:
22   - remove TABs
23   - remove use of the 'register' storage class specifier
24   - put header block at top of file
25
26 */
27
28 #include "cmStandardIncludes.h"
29
30 /* Configure the parser to use a lexer object.  */
31 #define YYPARSE_PARAM yyscanner
32 #define YYLEX_PARAM yyscanner
33 #define YYERROR_VERBOSE 1
34 #define cmCommandArgument_yyerror(x) \
35         cmCommandArgumentError(yyscanner, x)
36 #define yyGetParser (cmCommandArgument_yyget_extra(yyscanner))
37
38 /* Make sure malloc and free are available on QNX.  */
39 #ifdef __QNX__
40 # include <malloc.h>
41 #endif
42
43 /* Make sure the parser uses standard memory allocation.  The default
44    generated parser malloc/free declarations do not work on all
45    platforms.  */
46 #include <stdlib.h>
47 #define YYMALLOC malloc
48 #define YYFREE free
49
50 /*-------------------------------------------------------------------------*/
51 #include "cmCommandArgumentParserHelper.h" /* Interface to parser object.  */
52 #include "cmCommandArgumentLexer.h"  /* Interface to lexer object.  */
53 #include "cmCommandArgumentParserTokens.h" /* Need YYSTYPE for YY_DECL.  */
54
55 /* Forward declare the lexer entry point.  */
56 YY_DECL;
57
58 /* Internal utility functions.  */
59 static void cmCommandArgumentError(yyscan_t yyscanner, const char* message);
60
61 #define YYDEBUG 1
62 /* Configure the parser to support large input.  */
63 #define YYMAXDEPTH 100000
64 #define YYINITDEPTH 10000
65
66 /* Disable some warnings in the generated code.  */
67 #ifdef __BORLANDC__
68 # pragma warn -8004 /* Variable assigned a value that is not used.  */
69 # pragma warn -8008 /* condition always returns true */
70 # pragma warn -8060 /* possibly incorrect assignment */
71 # pragma warn -8066 /* unreachable code */
72 #endif
73 #ifdef _MSC_VER
74 # pragma warning (disable: 4102) /* Unused goto label.  */
75 # pragma warning (disable: 4065) /* Switch statement contains default but no
76                                     case. */
77 # pragma warning (disable: 4244) /* loss of precision */
78 # pragma warning (disable: 4702) /* unreachable code */
79 #endif
80 %}
81
82 /* Generate a reentrant parser object.  */
83 %pure_parser
84
85 /*
86 %union {
87   char* string;
88 }
89 */
90
91 /*-------------------------------------------------------------------------*/
92 /* Tokens */
93 %token cal_ENVCURLY
94 %token cal_NCURLY
95 %token cal_DCURLY
96 %token cal_DOLLAR "$"
97 %token cal_LCURLY "{"
98 %token cal_RCURLY "}"
99 %token cal_NAME
100 %token cal_BSLASH "\\"
101 %token cal_SYMBOL
102 %token cal_AT     "@"
103 %token cal_ERROR
104 %token cal_ATNAME
105
106 /*-------------------------------------------------------------------------*/
107 /* grammar */
108 %%
109
110
111 Start:
112 GoalWithOptionalBackSlash
113 {
114   $<str>$ = 0;
115   yyGetParser->SetResult($<str>1);
116 }
117
118 GoalWithOptionalBackSlash:
119 Goal
120 {
121   $<str>$ = $<str>1;
122 }
123 |
124 Goal cal_BSLASH
125 {
126   $<str>$ = yyGetParser->CombineUnions($<str>1, $<str>2);
127 }
128
129 Goal:
130 {
131   $<str>$ = 0;
132 }
133 |
134 String Goal
135 {
136   $<str>$ = yyGetParser->CombineUnions($<str>1, $<str>2);
137 }
138
139 String:
140 OuterText
141 {
142   $<str>$ = $<str>1;
143 }
144 |
145 Variable
146 {
147   $<str>$ = $<str>1;
148 }
149
150 OuterText:
151 cal_NAME
152 {
153   $<str>$ = $<str>1;
154 }
155 |
156 cal_AT
157 {
158   $<str>$ = $<str>1;
159 }
160 |
161 cal_DOLLAR
162 {
163   $<str>$ = $<str>1;
164 }
165 |
166 cal_LCURLY
167 {
168   $<str>$ = $<str>1;
169 }
170 |
171 cal_RCURLY
172 {
173   $<str>$ = $<str>1;
174 }
175 |
176 cal_SYMBOL
177 {
178   $<str>$ = $<str>1;
179 }
180
181 Variable:
182 cal_ENVCURLY EnvVarName cal_RCURLY
183 {
184   $<str>$ = yyGetParser->ExpandSpecialVariable($<str>1,$<str>2);
185   //std::cerr << __LINE__ << " here: [" << $<str>1 << "] [" << $<str>2 << "] [" << $<str>3 << "]" << std::endl;
186 }
187 |
188 cal_NCURLY MultipleIds cal_RCURLY
189 {
190   $<str>$ = yyGetParser->ExpandSpecialVariable($<str>1,$<str>2);
191   //std::cerr << __LINE__ << " here: [" << $<str>1 << "] [" << $<str>2 << "] [" << $<str>3 << "]" << std::endl;
192 }
193 |
194 cal_DCURLY MultipleIds cal_RCURLY
195 {
196   $<str>$ = yyGetParser->ExpandVariable($<str>2);
197   //std::cerr << __LINE__ << " here: [" << $<str>1 << "] [" << $<str>2 << "] [" << $<str>3 << "]" << std::endl;
198 }
199 |
200 cal_ATNAME
201 {
202   $<str>$ = yyGetParser->ExpandVariableForAt($<str>1);
203 }
204
205 EnvVarName:
206 MultipleIds
207 {
208   $<str>$ = $<str>1;
209 }
210 |
211 cal_SYMBOL EnvVarName
212 {
213   $<str>$ = $<str>1;
214 }
215
216 MultipleIds:
217 {
218   $<str>$ = 0;
219 }
220 |
221 ID MultipleIds
222 {
223   $<str>$ = yyGetParser->CombineUnions($<str>1, $<str>2);
224 }
225
226 ID:
227 cal_NAME
228 {
229   $<str>$ = $<str>1;
230 }
231 |
232 Variable
233 {
234   $<str>$ = $<str>1;
235 }
236
237
238 %%
239 /* End of grammar */
240
241 /*--------------------------------------------------------------------------*/
242 void cmCommandArgumentError(yyscan_t yyscanner, const char* message)
243 {
244   yyGetParser->Error(message);
245 }
246