cmFortranLexer.in.l 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. Copyright (C) 2000--2006 Erik Edelmann <[email protected]>
  7. The code was originally distributed under the GPL but permission
  8. from the copyright holder has been obtained to distribute this
  9. derived work under the CMake license.
  10. -------------------------------------------------------------------------*/
  11. /*
  12. This file must be translated to C++ and modified to build everywhere.
  13. Run flex >= 2.6 like this:
  14. flex -i --nounistd -DFLEXINT_H --noline --header-file=cmFortranLexer.h -ocmFortranLexer.cxx cmFortranLexer.in.l
  15. Modify cmFortranLexer.cxx:
  16. - remove trailing whitespace: sed -i 's/\s*$//' cmFortranLexer.h cmFortranLexer.cxx
  17. - remove blank lines at end of file: sed -i '${/^$/d;}' cmFortranLexer.h cmFortranLexer.cxx
  18. - #include "cmStandardLexer.h" at the top: sed -i '1i#include "cmStandardLexer.h"' cmFortranLexer.cxx
  19. */
  20. /* IWYU pragma: no_forward_declare yyguts_t */
  21. #ifndef __clang_analyzer__ /* Suppress clang scan-build warnings */
  22. #undef YY_NO_UNPUT
  23. #define cmFortranLexer_cxx
  24. #include "cmFortranParser.h" /* Interface to parser object. */
  25. /* Replace the lexer input function. */
  26. #undef YY_INPUT
  27. #define YY_INPUT(buf, result, max_size) \
  28. { result = cmFortranParser_Input(yyextra, buf, max_size); }
  29. /* Include the set of tokens from the parser. */
  30. #include "cmFortranParserTokens.h"
  31. /*--------------------------------------------------------------------------*/
  32. %}
  33. %option prefix="cmFortran_yy"
  34. %option reentrant
  35. %option noyywrap
  36. %pointer
  37. %s free_fmt fixed_fmt
  38. %x str_sq str_dq
  39. %%
  40. \" {
  41. cmFortranParser_StringStart(yyextra);
  42. cmFortranParser_SetOldStartcond(yyextra, YY_START);
  43. BEGIN(str_dq);
  44. }
  45. ' {
  46. cmFortranParser_StringStart(yyextra);
  47. cmFortranParser_SetOldStartcond(yyextra, YY_START);
  48. BEGIN(str_sq);
  49. }
  50. <str_dq>\" |
  51. <str_sq>' {
  52. BEGIN(cmFortranParser_GetOldStartcond(yyextra) );
  53. yylvalp->string = strdup(cmFortranParser_StringEnd(yyextra));
  54. return STRING;
  55. }
  56. <str_dq,str_sq>&[ \t]*\n |
  57. <str_dq,str_sq>&[ \t]*\n[ \t]*& /* Ignore (continued strings, free fmt) */
  58. <fixed_fmt,str_dq,str_sq>\n[ ]{5}[^ \t\n] {
  59. if (cmFortranParser_GetOldStartcond(yyextra) == fixed_fmt)
  60. ; /* Ignore (cont. strings, fixed fmt) */
  61. else
  62. {
  63. unput(yytext[strlen(yytext)-1]);
  64. }
  65. }
  66. <str_dq,str_sq>\n {
  67. unput ('\n');
  68. BEGIN(INITIAL);
  69. return UNTERMINATED_STRING;
  70. }
  71. <str_sq,str_dq>. {
  72. cmFortranParser_StringAppend(yyextra, yytext[0]);
  73. }
  74. !.*\n { return EOSTMT; } /* Treat comments like */
  75. <fixed_fmt>^[cC*dD].*\n { return EOSTMT; } /* empty lines */
  76. ^[ \t]*#([ \t]*line)?[ \t]*[0-9]+[ \t]* { return CPP_LINE_DIRECTIVE; }
  77. ^[ \t]*#[ \t]*include[ \t]*<[^>]+> {
  78. yytext[yyleng-1] = 0;
  79. yylvalp->string = strdup(strchr(yytext, '<')+1);
  80. return CPP_INCLUDE_ANGLE;
  81. }
  82. ^[ \t]*#[ \t]*include { return CPP_INCLUDE; }
  83. \$[ \t]*include { return F90PPR_INCLUDE; }
  84. \?\?[ \t]*include { return COCO_INCLUDE; }
  85. ^[ \t]*#[ \t]*define { return CPP_DEFINE; }
  86. \$[ \t]*DEFINE { return F90PPR_DEFINE; }
  87. ^[ \t]*#[ \t]*undef { return CPP_UNDEF; }
  88. \$[ \t]*UNDEF { return F90PPR_UNDEF; }
  89. ^[ \t]*#[ \t]*ifdef { return CPP_IFDEF; }
  90. ^[ \t]*#[ \t]*ifndef { return CPP_IFNDEF; }
  91. ^[ \t]*#[ \t]*if { return CPP_IF; }
  92. ^[ \t]*#[ \t]*elif { return CPP_ELIF; }
  93. ^[ \t]*#[ \t]*else { return CPP_ELSE; }
  94. ^[ \t]*#[ \t]*endif { return CPP_ENDIF; }
  95. $[ \t]*ifdef { return F90PPR_IFDEF; }
  96. $[ \t]*ifndef { return F90PPR_IFNDEF; }
  97. $[ \t]*if { return F90PPR_IF; }
  98. $[ \t]*elif { return F90PPR_ELIF; }
  99. $[ \t]*else { return F90PPR_ELSE; }
  100. $[ \t]*endif { return F90PPR_ENDIF; }
  101. /* Line continuations, possible involving comments. */
  102. &([ \t\n]*|!.*)*
  103. &([ \t\n]*|!.*)*&
  104. , { return COMMA; }
  105. :: { return DCOLON; }
  106. : { return COLON; }
  107. <fixed_fmt>\n[ ]{5}[^ ] { return GARBAGE; }
  108. =|=> { return ASSIGNMENT_OP; }
  109. [Ee][Nn][Dd] { return END; }
  110. [Ii][Nn][Cc][Ll][Uu][Dd][Ee] { return INCLUDE; }
  111. [Ii][Nn][Tt][Ee][Rr][Ff][Aa][Cc][Ee] { return INTERFACE; }
  112. [Mm][Oo][Dd][Uu][Ll][Ee] { return MODULE; }
  113. [Ss][Uu][Bb][Mm][Oo][Dd][Uu][Ll][Ee] { return SUBMODULE; }
  114. [Uu][Ss][Ee] { return USE; }
  115. [a-zA-Z_][a-zA-Z_0-9]* {
  116. yylvalp->string = strdup(yytext);
  117. return WORD;
  118. }
  119. \( { return LPAREN; }
  120. \) { return RPAREN; }
  121. [^ \t\n\r:;,!'"a-zA-Z=&()]+ { return GARBAGE; }
  122. ;|\n { return EOSTMT; }
  123. [ \t\r,] /* Ignore */
  124. \\[ \t]*\n /* Ignore line-endings preceded by \ */
  125. . { return *yytext; }
  126. <<EOF>> {
  127. if(!cmFortranParser_FilePop(yyextra) )
  128. {
  129. return YY_NULL;
  130. }
  131. }
  132. %%
  133. /*--------------------------------------------------------------------------*/
  134. YY_BUFFER_STATE cmFortranLexer_GetCurrentBuffer(yyscan_t yyscanner)
  135. {
  136. /* Hack into the internal flex-generated scanner to get the buffer. */
  137. struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  138. return YY_CURRENT_BUFFER;
  139. }
  140. #endif /* __clang_analyzer__ */