CMake Nightly Date Stamp
[kiteware-cmake.git] / Source / LexerParser / cmFortranLexer.in.l
blob7d97699c9fadc4bd705e06734d6147d0f5de808f
1 %{
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 */
32 #undef YY_NO_UNPUT
34 #define cmFortranLexer_cxx
35 #include "cmFortranParser.h" /* Interface to parser object.  */
37 /* Replace the lexer input function.  */
38 #undef YY_INPUT
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"
50 %option reentrant
51 %option noyywrap
52 %pointer
54 %s free_fmt fixed_fmt
55 %x str_sq str_dq
59 \"              {
60   cmFortranParser_StringStart(yyextra);
61   cmFortranParser_SetOldStartcond(yyextra, YY_START);
62   BEGIN(str_dq);
65 '               {
66   cmFortranParser_StringStart(yyextra);
67   cmFortranParser_SetOldStartcond(yyextra, YY_START);
68   BEGIN(str_sq);
71 <str_dq>\" |
72 <str_sq>'  {
73   BEGIN(cmFortranParser_GetOldStartcond(yyextra) );
74   yylvalp->string = strdup(cmFortranParser_StringEnd(yyextra));
75   return STRING;
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) */
84   else
85     {
86     unput(yytext[strlen(yytext)-1]);
87     }
91 <str_dq,str_sq>\n {
92   unput ('\n');
93   BEGIN(INITIAL);
94   return UNTERMINATED_STRING;
97 <str_sq,str_dq>. {
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]*line[ \t]* { return CPP_LINE_DIRECTIVE; }
106 ^[ \t]*#[ \t]*include[ \t]*<[^>]+> {
107   yytext[yyleng-1] = 0;
108   yylvalp->string = strdup(strchr(yytext, '<')+1);
109   return CPP_INCLUDE_ANGLE;
111 ^[ \t]*#[ \t]*include  { return CPP_INCLUDE; }
112 \$[ \t]*include { return F90PPR_INCLUDE; }
113 \?\?[ \t]*include { return COCO_INCLUDE; }
115 ^[ \t]*#[ \t]*define   { return CPP_DEFINE; }
116 \$[ \t]*DEFINE   { return F90PPR_DEFINE; }
118 ^[ \t]*#[ \t]*undef    { return CPP_UNDEF; }
119 \$[ \t]*UNDEF   { return F90PPR_UNDEF; }
121 ^[ \t]*#[ \t]*ifdef    { return CPP_IFDEF; }
122 ^[ \t]*#[ \t]*ifndef   { return CPP_IFNDEF; }
123 ^[ \t]*#[ \t]*if       { return CPP_IF; }
124 ^[ \t]*#[ \t]*elif     { return CPP_ELIF; }
125 ^[ \t]*#[ \t]*else     { return CPP_ELSE; }
126 ^[ \t]*#[ \t]*endif    { return CPP_ENDIF; }
128 $[ \t]*ifdef    { return F90PPR_IFDEF; }
129 $[ \t]*ifndef   { return F90PPR_IFNDEF; }
130 $[ \t]*if       { return F90PPR_IF; }
131 $[ \t]*elif     { return F90PPR_ELIF; }
132 $[ \t]*else     { return F90PPR_ELSE; }
133 $[ \t]*endif    { return F90PPR_ENDIF; }
135  /* Line continuations, possible involving comments.  */
136 &([ \t\r\n]*|!.*)*
137 &([ \t\r\n]*|!.*)*&
139 , { return COMMA; }
141 :: { return DCOLON; }
142 : { return COLON; }
144 <fixed_fmt>\r?\n[ ]{5}[^ ]  { return GARBAGE; }
146 =|=>                     { return ASSIGNMENT_OP; }
148 [Ee][Nn][Dd] { return END; }
149 [Ii][Nn][Cc][Ll][Uu][Dd][Ee] { return INCLUDE; }
150 [Ii][Nn][Tt][Ee][Rr][Ff][Aa][Cc][Ee] { return INTERFACE; }
151 [Mm][Oo][Dd][Uu][Ll][Ee] { return MODULE; }
152 [Ss][Uu][Bb][Mm][Oo][Dd][Uu][Ll][Ee] { return SUBMODULE; }
153 [Uu][Ss][Ee] { return USE; }
155 [a-zA-Z_][a-zA-Z_0-9]* {
156   yylvalp->string = strdup(yytext);
157   return WORD;
160 \( { return LPAREN; }
161 \) { return RPAREN; }
163 [^ \t\r\n:;,!'"a-zA-Z=&()]+ { return GARBAGE; }
165 ;|\n { return EOSTMT; }
168 [ \t\r,]         /* Ignore */
169 \\[ \t]*\r?\n       /* Ignore line-endings preceded by \ */
171 . { return *yytext; }
173 <<EOF>> {
174   if(!cmFortranParser_FilePop(yyextra) )
175     {
176     return YY_NULL;
177     }
182 /*--------------------------------------------------------------------------*/
183 YY_BUFFER_STATE cmFortranLexer_GetCurrentBuffer(yyscan_t yyscanner)
185   /* Hack into the internal flex-generated scanner to get the buffer.  */
186   struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
187   return YY_CURRENT_BUFFER;
190 #endif /* __clang_analyzer__ */