cmDependsFortranLexer.in.l 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. %{
  2. /*============================================================================
  3. CMake - Cross Platform Makefile Generator
  4. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  5. Distributed under the OSI-approved BSD License (the "License");
  6. see accompanying file Copyright.txt for details.
  7. This software is distributed WITHOUT ANY WARRANTY; without even the
  8. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. See the License for more information.
  10. ============================================================================*/
  11. /*-------------------------------------------------------------------------
  12. Portions of this source have been derived from makedepf90 version 2.8.8,
  13. Copyright (C) 2000--2006 Erik Edelmann <[email protected]>
  14. The code was originally distributed under the GPL but permission
  15. from the copyright holder has been obtained to distribute this
  16. derived work under the CMake license.
  17. -------------------------------------------------------------------------*/
  18. /*
  19. This file must be translated to C and modified to build everywhere.
  20. Run flex like this:
  21. flex -i --prefix=cmDependsFortran_yy --header-file=cmDependsFortranLexer.h -ocmDependsFortranLexer.cxx cmDependsFortranLexer.in.l
  22. Modify cmDependsFortranLexer.cxx:
  23. - remove TABs
  24. - remove "yyscanner" argument from these methods:
  25. yy_fatal_error, cmDependsFortran_yyalloc, cmDependsFortran_yyrealloc, cmDependsFortran_yyfree
  26. - remove "yyscanner = NULL" from end of cmDependsFortran_yylex_destroy
  27. - remove all YY_BREAK lines occurring right after return statements
  28. - change while ( 1 ) to for(;;)
  29. Modify cmDependsFortranLexer.h:
  30. - remove TABs
  31. - remove the yy_init_globals function
  32. - remove the block that includes unistd.h
  33. - remove #line directives (avoids bogus warning on old Sun)
  34. */
  35. #include "cmStandardLexer.h"
  36. #define cmDependsFortranLexer_cxx
  37. #include "cmDependsFortranParser.h" /* Interface to parser object. */
  38. /* Replace the lexer input function. */
  39. #undef YY_INPUT
  40. #define YY_INPUT(buf, result, max_size) \
  41. { result = cmDependsFortranParser_Input(yyextra, buf, max_size); }
  42. /* Include the set of tokens from the parser. */
  43. #include "cmDependsFortranParserTokens.h"
  44. /*--------------------------------------------------------------------------*/
  45. %}
  46. %option reentrant
  47. %option noyywrap
  48. %pointer
  49. %s free_fmt fixed_fmt
  50. %x str_sq str_dq
  51. %%
  52. \" {
  53. cmDependsFortranParser_StringStart(yyextra);
  54. cmDependsFortranParser_SetOldStartcond(yyextra, YY_START);
  55. BEGIN(str_dq);
  56. }
  57. ' {
  58. cmDependsFortranParser_StringStart(yyextra);
  59. cmDependsFortranParser_SetOldStartcond(yyextra, YY_START);
  60. BEGIN(str_sq);
  61. }
  62. <str_dq>\" |
  63. <str_sq>' {
  64. BEGIN(cmDependsFortranParser_GetOldStartcond(yyextra) );
  65. yylvalp->string = strdup(cmDependsFortranParser_StringEnd(yyextra));
  66. return STRING;
  67. }
  68. <str_dq,str_sq>&[ \t]*\n |
  69. <str_dq,str_sq>&[ \t]*\n[ \t]*& /* Ignore (continued strings, free fmt) */
  70. <fixed_fmt,str_dq,str_sq>\n[ ]{5}[^ \t\n] {
  71. if (cmDependsFortranParser_GetOldStartcond(yyextra) == fixed_fmt)
  72. ; /* Ignore (cont. strings, fixed fmt) */
  73. else
  74. {
  75. unput(yytext[strlen(yytext)-1]);
  76. }
  77. }
  78. <str_dq,str_sq>\n {
  79. unput ('\n');
  80. BEGIN(INITIAL);
  81. return UNTERMINATED_STRING;
  82. }
  83. <str_sq,str_dq>. {
  84. cmDependsFortranParser_StringAppend(yyextra, yytext[0]);
  85. }
  86. !.*\n { return EOSTMT; } /* Treat comments like */
  87. <fixed_fmt>^[cC*dD].*\n { return EOSTMT; } /* empty lines */
  88. ^[ \t]*#[ \t]*include[ \t]*<[^>]+> {
  89. yytext[yyleng-1] = 0;
  90. yylvalp->string = strdup(strchr(yytext, '<')+1);
  91. return CPP_INCLUDE_ANGLE;
  92. }
  93. ^[ \t]*#[ \t]*include { return CPP_INCLUDE; }
  94. \$[ \t]*include { return F90PPR_INCLUDE; }
  95. \?\?[ \t]*include { return COCO_INCLUDE; }
  96. ^[ \t]*#[ \t]*define { return CPP_DEFINE; }
  97. \$[ \t]*DEFINE { return F90PPR_DEFINE; }
  98. ^[ \t]*#[ \t]*undef { return CPP_UNDEF; }
  99. \$[ \t]*UNDEF { return F90PPR_UNDEF; }
  100. ^[ \t]*#[ \t]*ifdef { return CPP_IFDEF; }
  101. ^[ \t]*#[ \t]*ifndef { return CPP_IFNDEF; }
  102. ^[ \t]*#[ \t]*if { return CPP_IF; }
  103. ^[ \t]*#[ \t]*elif { return CPP_ELIF; }
  104. ^[ \t]*#[ \t]*else { return CPP_ELSE; }
  105. ^[ \t]*#[ \t]*endif { return CPP_ENDIF; }
  106. $[ \t]*ifdef { return F90PPR_IFDEF; }
  107. $[ \t]*ifndef { return F90PPR_IFNDEF; }
  108. $[ \t]*if { return F90PPR_IF; }
  109. $[ \t]*elif { return F90PPR_ELIF; }
  110. $[ \t]*else { return F90PPR_ELSE; }
  111. $[ \t]*endif { return F90PPR_ENDIF; }
  112. /* Line continuations, possible involving comments. */
  113. &([ \t\n]*|!.*)*
  114. &([ \t\n]*|!.*)*&
  115. , { return COMMA; }
  116. :: { return DCOLON; }
  117. <fixed_fmt>\n[ ]{5}[^ ] { return GARBAGE; }
  118. =|=> { return ASSIGNMENT_OP; }
  119. [a-zA-Z_][a-zA-Z_0-9]* {
  120. yylvalp->string = strdup(yytext);
  121. return WORD;
  122. }
  123. [^ \t\n\r;,!'"a-zA-Z=&]+ { return GARBAGE; }
  124. ;|\n { return EOSTMT; }
  125. [ \t\r,] /* Ignore */
  126. \\[ \t]*\n /* Ignore line-endings preceeded by \ */
  127. . { return *yytext; }
  128. <<EOF>> {
  129. if(!cmDependsFortranParser_FilePop(yyextra) )
  130. {
  131. return YY_NULL;
  132. }
  133. }
  134. %%
  135. /*--------------------------------------------------------------------------*/
  136. YY_BUFFER_STATE cmDependsFortranLexer_GetCurrentBuffer(yyscan_t yyscanner)
  137. {
  138. /* Hack into the internal flex-generated scanner to get the buffer. */
  139. struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  140. return YY_CURRENT_BUFFER;
  141. }