05769a1e31f470788371fb6ab8ac159d464764dd
[platform/upstream/cmake.git] / Source / LexerParser / cmFortranLexer.in.l
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,
6
7    Copyright (C) 2000--2006 Erik Edelmann <erik.edelmann@iki.fi>
8
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 -------------------------------------------------------------------------*/
13
14 /*
15
16 This file must be translated to C++ and modified to build everywhere.
17
18 Run flex >= 2.6 like this:
19
20   flex -i --nounistd -DFLEXINT_H --noline --header-file=cmFortranLexer.h -ocmFortranLexer.cxx cmFortranLexer.in.l
21
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
26 */
27
28 /* IWYU pragma: no_forward_declare yyguts_t */
29
30 #ifndef __clang_analyzer__ /* Suppress clang-analyzer warnings */
31
32 #undef YY_NO_UNPUT
33
34 #define cmFortranLexer_cxx
35 #include "cmFortranParser.h" /* Interface to parser object.  */
36
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)
41
42 /* Include the set of tokens from the parser.  */
43 #include "cmFortranParserTokens.h"
44
45 /*--------------------------------------------------------------------------*/
46 %}
47
48 %option prefix="cmFortran_yy"
49
50 %option reentrant
51 %option noyywrap
52 %pointer
53
54 %s free_fmt fixed_fmt
55 %x str_sq str_dq
56
57 %%
58
59 \"              {
60   cmFortranParser_StringStart(yyextra);
61   cmFortranParser_SetOldStartcond(yyextra, YY_START);
62   BEGIN(str_dq);
63 }
64
65 '               {
66   cmFortranParser_StringStart(yyextra);
67   cmFortranParser_SetOldStartcond(yyextra, YY_START);
68   BEGIN(str_sq);
69 }
70
71 <str_dq>\" |
72 <str_sq>'  {
73   BEGIN(cmFortranParser_GetOldStartcond(yyextra) );
74   yylvalp->string = strdup(cmFortranParser_StringEnd(yyextra));
75   return STRING;
76 }
77
78 <str_dq,str_sq>&[ \t]*\n |
79 <str_dq,str_sq>&[ \t]*\n[ \t]*&  /* Ignore (continued strings, free fmt) */
80
81 <fixed_fmt,str_dq,str_sq>\n[ ]{5}[^ \t\n] {
82   if (cmFortranParser_GetOldStartcond(yyextra) == fixed_fmt)
83     ; /* Ignore (cont. strings, fixed fmt) */
84   else
85     {
86     unput(yytext[strlen(yytext)-1]);
87     }
88 }
89
90
91 <str_dq,str_sq>\n {
92   unput ('\n');
93   BEGIN(INITIAL);
94   return UNTERMINATED_STRING;
95 }
96
97 <str_sq,str_dq>. {
98   cmFortranParser_StringAppend(yyextra, yytext[0]);
99 }
100
101 !.*\n                   { return EOSTMT; } /* Treat comments like */
102 <fixed_fmt>^[cC*dD].*\n { return EOSTMT; } /* empty lines */
103
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;
109 }
110 ^[ \t]*#[ \t]*include  { return CPP_INCLUDE; }
111 \$[ \t]*include { return F90PPR_INCLUDE; }
112 \?\?[ \t]*include { return COCO_INCLUDE; }
113
114 ^[ \t]*#[ \t]*define   { return CPP_DEFINE; }
115 \$[ \t]*DEFINE   { return F90PPR_DEFINE; }
116
117 ^[ \t]*#[ \t]*undef    { return CPP_UNDEF; }
118 \$[ \t]*UNDEF   { return F90PPR_UNDEF; }
119
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; }
126
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; }
133
134  /* Line continuations, possible involving comments.  */
135 &([ \t\n]*|!.*)*
136 &([ \t\n]*|!.*)*&
137
138 , { return COMMA; }
139
140 :: { return DCOLON; }
141 : { return COLON; }
142
143 <fixed_fmt>\n[ ]{5}[^ ]  { return GARBAGE; }
144
145 =|=>                     { return ASSIGNMENT_OP; }
146
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; }
153
154 [a-zA-Z_][a-zA-Z_0-9]* {
155   yylvalp->string = strdup(yytext);
156   return WORD;
157 }
158
159 \( { return LPAREN; }
160 \) { return RPAREN; }
161
162 [^ \t\n\r:;,!'"a-zA-Z=&()]+ { return GARBAGE; }
163
164 ;|\n { return EOSTMT; }
165
166
167 [ \t\r,]         /* Ignore */
168 \\[ \t]*\n       /* Ignore line-endings preceded by \ */
169
170 . { return *yytext; }
171
172 <<EOF>> {
173   if(!cmFortranParser_FilePop(yyextra) )
174     {
175     return YY_NULL;
176     }
177 }
178
179 %%
180
181 /*--------------------------------------------------------------------------*/
182 YY_BUFFER_STATE cmFortranLexer_GetCurrentBuffer(yyscan_t yyscanner)
183 {
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;
187 }
188
189 #endif /* __clang_analyzer__ */