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