Imported Upstream version 2.8.12.2
[platform/upstream/cmake.git] / Source / cmDependsFortranLexer.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   Portions of this source have been derived from makedepf90 version 2.8.8,
15
16    Copyright (C) 2000--2006 Erik Edelmann <erik.edelmann@iki.fi>
17
18   The code was originally distributed under the GPL but permission
19   from the copyright holder has been obtained to distribute this
20   derived work under the CMake license.
21 -------------------------------------------------------------------------*/
22
23 /*
24
25 This file must be translated to C and modified to build everywhere.
26
27 Run flex like this:
28
29   flex -i --prefix=cmDependsFortran_yy --header-file=cmDependsFortranLexer.h -ocmDependsFortranLexer.cxx cmDependsFortranLexer.in.l
30
31 Modify cmDependsFortranLexer.cxx:
32   - remove TABs
33   - remove use of the 'register' storage class specifier
34   - remove "yyscanner" argument from these methods:
35       yy_fatal_error, cmDependsFortran_yyalloc, cmDependsFortran_yyrealloc, cmDependsFortran_yyfree
36   - remove "yyscanner = NULL" from end of cmDependsFortran_yylex_destroy
37   - remove all YY_BREAK lines occurring right after return statements
38   - change while ( 1 ) to for(;;)
39
40 Modify cmDependsFortranLexer.h:
41   - remove TABs
42   - remove the yy_init_globals function
43   - remove the block that includes unistd.h
44   - remove #line directives (avoids bogus warning on old Sun)
45
46 */
47
48 #include "cmStandardLexer.h"
49
50 #define cmDependsFortranLexer_cxx
51 #include "cmDependsFortranParser.h" /* Interface to parser object.  */
52
53 /* Replace the lexer input function.  */
54 #undef YY_INPUT
55 #define YY_INPUT(buf, result, max_size) \
56   { result = cmDependsFortranParser_Input(yyextra, buf, max_size); }
57
58 /* Include the set of tokens from the parser.  */
59 #include "cmDependsFortranParserTokens.h"
60
61 /*--------------------------------------------------------------------------*/
62 %}
63
64
65 %option reentrant
66 %option noyywrap
67 %pointer
68
69 %s free_fmt fixed_fmt
70 %x str_sq str_dq
71
72 %%
73
74 \"              {
75   cmDependsFortranParser_StringStart(yyextra);
76   cmDependsFortranParser_SetOldStartcond(yyextra, YY_START);
77   BEGIN(str_dq);
78 }
79
80 '               {
81   cmDependsFortranParser_StringStart(yyextra);
82   cmDependsFortranParser_SetOldStartcond(yyextra, YY_START);
83   BEGIN(str_sq);
84 }
85
86 <str_dq>\" |
87 <str_sq>'  {
88   BEGIN(cmDependsFortranParser_GetOldStartcond(yyextra) );
89   yylvalp->string = strdup(cmDependsFortranParser_StringEnd(yyextra));
90   return STRING;
91 }
92
93 <str_dq,str_sq>&[ \t]*\n |
94 <str_dq,str_sq>&[ \t]*\n[ \t]*&  /* Ignore (continued strings, free fmt) */
95
96 <fixed_fmt,str_dq,str_sq>\n[ ]{5}[^ \t\n] {
97   if (cmDependsFortranParser_GetOldStartcond(yyextra) == fixed_fmt)
98     ; /* Ignore (cont. strings, fixed fmt) */
99   else
100     {
101     unput(yytext[strlen(yytext)-1]);
102     }
103 }
104
105
106 <str_dq,str_sq>\n {
107   unput ('\n');
108   BEGIN(INITIAL);
109   return UNTERMINATED_STRING;
110 }
111
112 <str_sq,str_dq>. {
113   cmDependsFortranParser_StringAppend(yyextra, yytext[0]);
114 }
115
116 !.*\n                   { return EOSTMT; } /* Treat comments like */
117 <fixed_fmt>^[cC*dD].*\n { return EOSTMT; } /* empty lines */
118
119 ^[ \t]*#[ \t]*include[ \t]*<[^>]+> {
120   yytext[yyleng-1] = 0;
121   yylvalp->string = strdup(strchr(yytext, '<')+1);
122   return CPP_INCLUDE_ANGLE;
123 }
124 ^[ \t]*#[ \t]*include  { return CPP_INCLUDE; }
125 \$[ \t]*include { return F90PPR_INCLUDE; }
126 \?\?[ \t]*include { return COCO_INCLUDE; }
127
128 ^[ \t]*#[ \t]*define   { return CPP_DEFINE; }
129 \$[ \t]*DEFINE   { return F90PPR_DEFINE; }
130
131 ^[ \t]*#[ \t]*undef    { return CPP_UNDEF; }
132 \$[ \t]*UNDEF   { return F90PPR_UNDEF; }
133
134 ^[ \t]*#[ \t]*ifdef    { return CPP_IFDEF; }
135 ^[ \t]*#[ \t]*ifndef   { return CPP_IFNDEF; }
136 ^[ \t]*#[ \t]*if       { return CPP_IF; }
137 ^[ \t]*#[ \t]*elif     { return CPP_ELIF; }
138 ^[ \t]*#[ \t]*else     { return CPP_ELSE; }
139 ^[ \t]*#[ \t]*endif    { return CPP_ENDIF; }
140
141 $[ \t]*ifdef    { return F90PPR_IFDEF; }
142 $[ \t]*ifndef   { return F90PPR_IFNDEF; }
143 $[ \t]*if       { return F90PPR_IF; }
144 $[ \t]*elif     { return F90PPR_ELIF; }
145 $[ \t]*else     { return F90PPR_ELSE; }
146 $[ \t]*endif    { return F90PPR_ENDIF; }
147
148  /* Line continuations, possible involving comments.  */
149 &([ \t\n]*|!.*)*
150 &([ \t\n]*|!.*)*&
151
152 , { return COMMA; }
153
154 :: { return DCOLON; }
155
156 <fixed_fmt>\n[ ]{5}[^ ]  { return GARBAGE; }
157
158 =|=>                     { return ASSIGNMENT_OP; }
159
160 [a-zA-Z_][a-zA-Z_0-9]* {
161   yylvalp->string = strdup(yytext);
162   return WORD;
163 }
164
165 [^ \t\n\r;,!'"a-zA-Z=&]+ { return GARBAGE; }
166
167 ;|\n { return EOSTMT; }
168
169
170 [ \t\r,]         /* Ignore */
171 \\[ \t]*\n       /* Ignore line-endings preceeded by \ */
172
173 . { return *yytext; }
174
175 <<EOF>> {
176   if(!cmDependsFortranParser_FilePop(yyextra) )
177     {
178     return YY_NULL;
179     }
180 }
181
182 %%
183
184 /*--------------------------------------------------------------------------*/
185 YY_BUFFER_STATE cmDependsFortranLexer_GetCurrentBuffer(yyscan_t yyscanner)
186 {
187   /* Hack into the internal flex-generated scanner to get the buffer.  */
188   struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
189   return YY_CURRENT_BUFFER;
190 }