Imported Upstream version 2.8.9
[platform/upstream/cmake.git] / Source / cmCommandArgumentLexer.in.l
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 flex like this:
18
19   flex --prefix=cmCommandArgument_yy --header-file=cmCommandArgumentLexer.h -ocmCommandArgumentLexer.cxx cmCommandArgumentLexer.in.l
20
21 Modify cmCommandArgumentLexer.cxx:
22   - add #include "cmStandardIncludes.h" to top of file
23   - put header block at top of file
24   - remove TABs
25   - remove "yyscanner" argument from these methods:
26       yy_fatal_error, cmCommandArgument_yyalloc, cmCommandArgument_yyrealloc, cmCommandArgument_yyfree
27   - remove all YY_BREAK lines occurring right after return statements
28   - change while ( 1 ) to for(;;)
29   - add "return 0;" to end of cmCommandArgument_yylex
30
31 Modify cmCommandArgumentLexer.h:
32   - remove TABs
33   - remove the yy_init_globals function
34   - remove the block that includes unistd.h
35   - remove #line directives (avoids bogus warning on old Sun)
36
37 */
38
39 #include "cmStandardLexer.h"
40
41 #include "cmCommandArgumentParserHelper.h"
42
43 /* Replace the lexer input function.  */
44 #undef YY_INPUT
45 #define YY_INPUT(buf, result, max_size) \
46   { result = yyextra->LexInput(buf, max_size); }
47
48 /* Include the set of tokens from the parser.  */
49 #include "cmCommandArgumentParserTokens.h"
50
51 /*--------------------------------------------------------------------------*/
52 %}
53
54 %option reentrant
55 %option noyywrap
56 %option nounput
57 %pointer
58 %s ESCAPES
59 %s NOESCAPES
60
61 %%
62
63 \$ENV\{ {
64   //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
65   yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2);
66   return cal_ENVCURLY;
67 }
68
69 \$[A-Za-z0-9/_.+-]+\{ { 
70   //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
71   yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2); 
72   return cal_NCURLY; 
73
74
75 @[A-Za-z0-9/_.+-]+@ { 
76   //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
77   yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2); 
78   return cal_ATNAME; 
79
80
81 "${" {
82   //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
83   //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext)); 
84   yylvalp->str = yyextra->DCURLYVariable;
85   return cal_DCURLY;
86 }
87
88 "}" {
89   //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
90   //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext)); 
91   yylvalp->str = yyextra->RCURLYVariable;
92   return cal_RCURLY;
93 }
94
95 "@" {
96   //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
97   //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext)); 
98   yylvalp->str = yyextra->ATVariable;
99   return cal_AT;
100 }
101
102 [A-Za-z0-9/_.+-]+ { 
103   //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
104   yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext)); 
105   return cal_NAME; 
106 }
107
108 <ESCAPES>\\. {
109   if ( !yyextra->HandleEscapeSymbol(yylvalp, *(yytext+1)) )
110     {
111     return cal_ERROR;
112     }
113   return cal_SYMBOL; 
114 }
115
116 [^\${}\\@]+ { 
117   //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
118   yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext)); 
119   return cal_SYMBOL; 
120 }
121
122 "$" {
123   //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext)); 
124   yylvalp->str = yyextra->DOLLARVariable;
125   return cal_DOLLAR; 
126 }
127
128 "{" {
129   //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext)); 
130   yylvalp->str = yyextra->LCURLYVariable;
131   return cal_LCURLY; 
132 }
133
134 <ESCAPES>"\\" {
135   //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext)); 
136   yylvalp->str = yyextra->BSLASHVariable;
137   return cal_BSLASH; 
138 }
139
140 <NOESCAPES>"\\" {
141   //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
142   yylvalp->str = yyextra->BSLASHVariable;
143   return cal_SYMBOL;
144 }
145
146 %%
147
148 /*--------------------------------------------------------------------------*/
149 void cmCommandArgument_SetupEscapes(yyscan_t yyscanner, bool noEscapes)
150 {
151   /* Hack into the internal flex-generated scanner to set the state.  */
152   struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
153   if(noEscapes)
154     {
155     BEGIN(NOESCAPES);
156     }
157   else
158     {
159     BEGIN(ESCAPES);
160     }
161 }