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