cmFortranLexer.in.l 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 <erik.edelmann@iki.fi>
  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. #undef YY_NO_UNPUT
  22. #define cmFortranLexer_cxx
  23. #include "cmFortranParser.h" /* Interface to parser object. */
  24. /* Replace the lexer input function. */
  25. #undef YY_INPUT
  26. #define YY_INPUT(buf, result, max_size) \
  27. { result = cmFortranParser_Input(yyextra, buf, max_size); }
  28. /* Include the set of tokens from the parser. */
  29. #include "cmFortranParserTokens.h"
  30. /*--------------------------------------------------------------------------*/
  31. %}
  32. %option prefix="cmFortran_yy"
  33. %option reentrant
  34. %option noyywrap
  35. %pointer
  36. %s free_fmt fixed_fmt
  37. %x str_sq str_dq
  38. %%
  39. \" {
  40. cmFortranParser_StringStart(yyextra);
  41. cmFortranParser_SetOldStartcond(yyextra, YY_START);
  42. BEGIN(str_dq);
  43. }
  44. ' {
  45. cmFortranParser_StringStart(yyextra);
  46. cmFortranParser_SetOldStartcond(yyextra, YY_START);
  47. BEGIN(str_sq);
  48. }
  49. <str_dq>\" |
  50. <str_sq>' {
  51. BEGIN(cmFortranParser_GetOldStartcond(yyextra) );
  52. yylvalp->string = strdup(cmFortranParser_StringEnd(yyextra));
  53. return STRING;
  54. }
  55. <str_dq,str_sq>&[ \t]*\n |
  56. <str_dq,str_sq>&[ \t]*\n[ \t]*& /* Ignore (continued strings, free fmt) */
  57. <fixed_fmt,str_dq,str_sq>\n[ ]{5}[^ \t\n] {
  58. if (cmFortranParser_GetOldStartcond(yyextra) == fixed_fmt)
  59. ; /* Ignore (cont. strings, fixed fmt) */
  60. else
  61. {
  62. unput(yytext[strlen(yytext)-1]);
  63. }
  64. }
  65. <str_dq,str_sq>\n {
  66. unput ('\n');
  67. BEGIN(INITIAL);
  68. return UNTERMINATED_STRING;
  69. }
  70. <str_sq,str_dq>. {
  71. cmFortranParser_StringAppend(yyextra, yytext[0]);
  72. }
  73. !.*\n { return EOSTMT; } /* Treat comments like */
  74. <fixed_fmt>^[cC*dD].*\n { return EOSTMT; } /* empty lines */
  75. ^[ \t]*#([ \t]*line)?[ \t]*[0-9]+[ \t]* { return CPP_LINE_DIRECTIVE; }
  76. ^[ \t]*#[ \t]*include[ \t]*<[^>]+> {
  77. yytext[yyleng-1] = 0;
  78. yylvalp->string = strdup(strchr(yytext, '<')+1);
  79. return CPP_INCLUDE_ANGLE;
  80. }
  81. ^[ \t]*#[ \t]*include { return CPP_INCLUDE; }
  82. \$[ \t]*include { return F90PPR_INCLUDE; }
  83. \?\?[ \t]*include { return COCO_INCLUDE; }
  84. ^[ \t]*#[ \t]*define { return CPP_DEFINE; }
  85. \$[ \t]*DEFINE { return F90PPR_DEFINE; }
  86. ^[ \t]*#[ \t]*undef { return CPP_UNDEF; }
  87. \$[ \t]*UNDEF { return F90PPR_UNDEF; }
  88. ^[ \t]*#[ \t]*ifdef { return CPP_IFDEF; }
  89. ^[ \t]*#[ \t]*ifndef { return CPP_IFNDEF; }
  90. ^[ \t]*#[ \t]*if { return CPP_IF; }
  91. ^[ \t]*#[ \t]*elif { return CPP_ELIF; }
  92. ^[ \t]*#[ \t]*else { return CPP_ELSE; }
  93. ^[ \t]*#[ \t]*endif { return CPP_ENDIF; }
  94. $[ \t]*ifdef { return F90PPR_IFDEF; }
  95. $[ \t]*ifndef { return F90PPR_IFNDEF; }
  96. $[ \t]*if { return F90PPR_IF; }
  97. $[ \t]*elif { return F90PPR_ELIF; }
  98. $[ \t]*else { return F90PPR_ELSE; }
  99. $[ \t]*endif { return F90PPR_ENDIF; }
  100. /* Line continuations, possible involving comments. */
  101. &([ \t\n]*|!.*)*
  102. &([ \t\n]*|!.*)*&
  103. , { return COMMA; }
  104. :: { return DCOLON; }
  105. : { return COLON; }
  106. <fixed_fmt>\n[ ]{5}[^ ] { return GARBAGE; }
  107. =|=> { return ASSIGNMENT_OP; }
  108. [Ee][Nn][Dd] { return END; }
  109. [Ii][Nn][Cc][Ll][Uu][Dd][Ee] { return INCLUDE; }
  110. [Ii][Nn][Tt][Ee][Rr][Ff][Aa][Cc][Ee] { return INTERFACE; }
  111. [Mm][Oo][Dd][Uu][Ll][Ee] { return MODULE; }
  112. [Ss][Uu][bb][Mm][Oo][Dd][Uu][Ll][Ee] { return SUBMODULE; }
  113. [Uu][Ss][Ee] { return USE; }
  114. [a-zA-Z_][a-zA-Z_0-9]* {
  115. yylvalp->string = strdup(yytext);
  116. return WORD;
  117. }
  118. \( { return LPAREN; }
  119. \) { return RPAREN; }
  120. [^ \t\n\r:;,!'"a-zA-Z=&()]+ { return GARBAGE; }
  121. ;|\n { return EOSTMT; }
  122. [ \t\r,] /* Ignore */
  123. \\[ \t]*\n /* Ignore line-endings preceded by \ */
  124. . { return *yytext; }
  125. <<EOF>> {
  126. if(!cmFortranParser_FilePop(yyextra) )
  127. {
  128. return YY_NULL;
  129. }
  130. }
  131. %%
  132. /*--------------------------------------------------------------------------*/
  133. YY_BUFFER_STATE cmFortranLexer_GetCurrentBuffer(yyscan_t yyscanner)
  134. {
  135. /* Hack into the internal flex-generated scanner to get the buffer. */
  136. struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  137. return YY_CURRENT_BUFFER;
  138. }