2 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
3 file Copyright.txt or https://cmake.org/licensing for details. */
4 /*-------------------------------------------------------------------------
5 Portions of this source have been derived from makedepf90 version 2.8.8,
7 Copyright (C) 2000--2006 Erik Edelmann <erik.edelmann@iki.fi>
9 The code was originally distributed under the GPL but permission
10 from the copyright holder has been obtained to distribute this
11 derived work under the CMake license.
12 -------------------------------------------------------------------------*/
16 This file must be translated to C++ and modified to build everywhere.
18 Run flex >= 2.6 like this:
20 flex -i --nounistd -DFLEXINT_H --noline --header-file=cmFortranLexer.h -ocmFortranLexer.cxx cmFortranLexer.in.l
22 Modify cmFortranLexer.cxx:
23 - remove trailing whitespace: sed -i 's/\s*$//' cmFortranLexer.h cmFortranLexer.cxx
24 - remove blank lines at end of file: sed -i '${/^$/d;}' cmFortranLexer.h cmFortranLexer.cxx
25 - #include "cmStandardLexer.h" at the top: sed -i '1i#include "cmStandardLexer.h"' cmFortranLexer.cxx
28 /* IWYU pragma: no_forward_declare yyguts_t */
30 #ifndef __clang_analyzer__ /* Suppress clang-analyzer warnings */
34 #define cmFortranLexer_cxx
35 #include "cmFortranParser.h" /* Interface to parser object. */
37 /* Replace the lexer input function. */
39 #define YY_INPUT(buf, result, max_size) \
40 do { result = cmFortranParser_Input(yyextra, buf, max_size); } while (0)
42 /* Include the set of tokens from the parser. */
43 #include "cmFortranParserTokens.h"
45 /*--------------------------------------------------------------------------*/
48 %option prefix="cmFortran_yy"
60 cmFortranParser_StringStart(yyextra);
61 cmFortranParser_SetOldStartcond(yyextra, YY_START);
66 cmFortranParser_StringStart(yyextra);
67 cmFortranParser_SetOldStartcond(yyextra, YY_START);
73 BEGIN(cmFortranParser_GetOldStartcond(yyextra) );
74 yylvalp->string = strdup(cmFortranParser_StringEnd(yyextra));
78 <str_dq,str_sq>&[ \t]*\r?\n |
79 <str_dq,str_sq>&[ \t]*\r?\n[ \t]*& /* Ignore (continued strings, free fmt) */
81 <fixed_fmt,str_dq,str_sq>\r?\n[ ]{5}[^ \t\r\n] {
82 if (cmFortranParser_GetOldStartcond(yyextra) == fixed_fmt)
83 ; /* Ignore (cont. strings, fixed fmt) */
86 unput(yytext[strlen(yytext)-1]);
94 return UNTERMINATED_STRING;
98 cmFortranParser_StringAppend(yyextra, yytext[0]);
101 !.*\n { return EOSTMT; } /* Treat comments like */
102 <fixed_fmt>^[cC*dD].*\n { return EOSTMT; } /* empty lines */
104 ^[ \t]*#([ \t]*line)?[ \t]*[0-9]+[ \t]* { return CPP_LINE_DIRECTIVE; }
105 ^[ \t]*#[ \t]*include[ \t]*<[^>]+> {
106 yytext[yyleng-1] = 0;
107 yylvalp->string = strdup(strchr(yytext, '<')+1);
108 return CPP_INCLUDE_ANGLE;
110 ^[ \t]*#[ \t]*include { return CPP_INCLUDE; }
111 \$[ \t]*include { return F90PPR_INCLUDE; }
112 \?\?[ \t]*include { return COCO_INCLUDE; }
114 ^[ \t]*#[ \t]*define { return CPP_DEFINE; }
115 \$[ \t]*DEFINE { return F90PPR_DEFINE; }
117 ^[ \t]*#[ \t]*undef { return CPP_UNDEF; }
118 \$[ \t]*UNDEF { return F90PPR_UNDEF; }
120 ^[ \t]*#[ \t]*ifdef { return CPP_IFDEF; }
121 ^[ \t]*#[ \t]*ifndef { return CPP_IFNDEF; }
122 ^[ \t]*#[ \t]*if { return CPP_IF; }
123 ^[ \t]*#[ \t]*elif { return CPP_ELIF; }
124 ^[ \t]*#[ \t]*else { return CPP_ELSE; }
125 ^[ \t]*#[ \t]*endif { return CPP_ENDIF; }
127 $[ \t]*ifdef { return F90PPR_IFDEF; }
128 $[ \t]*ifndef { return F90PPR_IFNDEF; }
129 $[ \t]*if { return F90PPR_IF; }
130 $[ \t]*elif { return F90PPR_ELIF; }
131 $[ \t]*else { return F90PPR_ELSE; }
132 $[ \t]*endif { return F90PPR_ENDIF; }
134 /* Line continuations, possible involving comments. */
140 :: { return DCOLON; }
143 <fixed_fmt>\r?\n[ ]{5}[^ ] { return GARBAGE; }
145 =|=> { return ASSIGNMENT_OP; }
147 [Ee][Nn][Dd] { return END; }
148 [Ii][Nn][Cc][Ll][Uu][Dd][Ee] { return INCLUDE; }
149 [Ii][Nn][Tt][Ee][Rr][Ff][Aa][Cc][Ee] { return INTERFACE; }
150 [Mm][Oo][Dd][Uu][Ll][Ee] { return MODULE; }
151 [Ss][Uu][Bb][Mm][Oo][Dd][Uu][Ll][Ee] { return SUBMODULE; }
152 [Uu][Ss][Ee] { return USE; }
154 [a-zA-Z_][a-zA-Z_0-9]* {
155 yylvalp->string = strdup(yytext);
159 \( { return LPAREN; }
160 \) { return RPAREN; }
162 [^ \t\r\n:;,!'"a-zA-Z=&()]+ { return GARBAGE; }
164 ;|\n { return EOSTMT; }
167 [ \t\r,] /* Ignore */
168 \\[ \t]*\r?\n /* Ignore line-endings preceded by \ */
170 . { return *yytext; }
173 if(!cmFortranParser_FilePop(yyextra) )
181 /*--------------------------------------------------------------------------*/
182 YY_BUFFER_STATE cmFortranLexer_GetCurrentBuffer(yyscan_t yyscanner)
184 /* Hack into the internal flex-generated scanner to get the buffer. */
185 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
186 return YY_CURRENT_BUFFER;
189 #endif /* __clang_analyzer__ */