cmFortranLexer.in.l 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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=cmFortran_yy --header-file=cmFortranLexer.h -ocmFortranLexer.cxx cmFortranLexer.in.l
  22. Modify cmFortranLexer.cxx:
  23. - remove TABs
  24. - remove use of the 'register' storage class specifier
  25. - remove "yyscanner" argument from these methods:
  26. yy_fatal_error, cmFortran_yyalloc, cmFortran_yyrealloc, cmFortran_yyfree
  27. - remove "yyscanner = NULL" from end of cmFortran_yylex_destroy
  28. - remove all YY_BREAK lines occurring right after return statements
  29. - change while ( 1 ) to for(;;)
  30. Modify cmFortranLexer.h:
  31. - remove TABs
  32. - remove the yy_init_globals function
  33. - remove the block that includes unistd.h
  34. - remove #line directives (avoids bogus warning on old Sun)
  35. */
  36. #include "cmStandardLexer.h"
  37. #define cmFortranLexer_cxx
  38. #include "cmFortranParser.h" /* Interface to parser object. */
  39. /* Replace the lexer input function. */
  40. #undef YY_INPUT
  41. #define YY_INPUT(buf, result, max_size) \
  42. { result = cmFortranParser_Input(yyextra, buf, max_size); }
  43. /* Include the set of tokens from the parser. */
  44. #include "cmFortranParserTokens.h"
  45. /*--------------------------------------------------------------------------*/
  46. %}
  47. %option reentrant
  48. %option noyywrap
  49. %pointer
  50. %s free_fmt fixed_fmt
  51. %x str_sq str_dq
  52. %%
  53. \" {
  54. cmFortranParser_StringStart(yyextra);
  55. cmFortranParser_SetOldStartcond(yyextra, YY_START);
  56. BEGIN(str_dq);
  57. }
  58. ' {
  59. cmFortranParser_StringStart(yyextra);
  60. cmFortranParser_SetOldStartcond(yyextra, YY_START);
  61. BEGIN(str_sq);
  62. }
  63. <str_dq>\" |
  64. <str_sq>' {
  65. BEGIN(cmFortranParser_GetOldStartcond(yyextra) );
  66. yylvalp->string = strdup(cmFortranParser_StringEnd(yyextra));
  67. return STRING;
  68. }
  69. <str_dq,str_sq>&[ \t]*\n |
  70. <str_dq,str_sq>&[ \t]*\n[ \t]*& /* Ignore (continued strings, free fmt) */
  71. <fixed_fmt,str_dq,str_sq>\n[ ]{5}[^ \t\n] {
  72. if (cmFortranParser_GetOldStartcond(yyextra) == fixed_fmt)
  73. ; /* Ignore (cont. strings, fixed fmt) */
  74. else
  75. {
  76. unput(yytext[strlen(yytext)-1]);
  77. }
  78. }
  79. <str_dq,str_sq>\n {
  80. unput ('\n');
  81. BEGIN(INITIAL);
  82. return UNTERMINATED_STRING;
  83. }
  84. <str_sq,str_dq>. {
  85. cmFortranParser_StringAppend(yyextra, yytext[0]);
  86. }
  87. !.*\n { return EOSTMT; } /* Treat comments like */
  88. <fixed_fmt>^[cC*dD].*\n { return EOSTMT; } /* empty lines */
  89. ^[ \t]*#[ \t]*include[ \t]*<[^>]+> {
  90. yytext[yyleng-1] = 0;
  91. yylvalp->string = strdup(strchr(yytext, '<')+1);
  92. return CPP_INCLUDE_ANGLE;
  93. }
  94. ^[ \t]*#[ \t]*include { return CPP_INCLUDE; }
  95. \$[ \t]*include { return F90PPR_INCLUDE; }
  96. \?\?[ \t]*include { return COCO_INCLUDE; }
  97. ^[ \t]*#[ \t]*define { return CPP_DEFINE; }
  98. \$[ \t]*DEFINE { return F90PPR_DEFINE; }
  99. ^[ \t]*#[ \t]*undef { return CPP_UNDEF; }
  100. \$[ \t]*UNDEF { return F90PPR_UNDEF; }
  101. ^[ \t]*#[ \t]*ifdef { return CPP_IFDEF; }
  102. ^[ \t]*#[ \t]*ifndef { return CPP_IFNDEF; }
  103. ^[ \t]*#[ \t]*if { return CPP_IF; }
  104. ^[ \t]*#[ \t]*elif { return CPP_ELIF; }
  105. ^[ \t]*#[ \t]*else { return CPP_ELSE; }
  106. ^[ \t]*#[ \t]*endif { return CPP_ENDIF; }
  107. $[ \t]*ifdef { return F90PPR_IFDEF; }
  108. $[ \t]*ifndef { return F90PPR_IFNDEF; }
  109. $[ \t]*if { return F90PPR_IF; }
  110. $[ \t]*elif { return F90PPR_ELIF; }
  111. $[ \t]*else { return F90PPR_ELSE; }
  112. $[ \t]*endif { return F90PPR_ENDIF; }
  113. /* Line continuations, possible involving comments. */
  114. &([ \t\n]*|!.*)*
  115. &([ \t\n]*|!.*)*&
  116. , { return COMMA; }
  117. :: { return DCOLON; }
  118. <fixed_fmt>\n[ ]{5}[^ ] { return GARBAGE; }
  119. =|=> { return ASSIGNMENT_OP; }
  120. [a-zA-Z_][a-zA-Z_0-9]* {
  121. yylvalp->string = strdup(yytext);
  122. return WORD;
  123. }
  124. [^ \t\n\r;,!'"a-zA-Z=&]+ { return GARBAGE; }
  125. ;|\n { return EOSTMT; }
  126. [ \t\r,] /* Ignore */
  127. \\[ \t]*\n /* Ignore line-endings preceeded by \ */
  128. . { return *yytext; }
  129. <<EOF>> {
  130. if(!cmFortranParser_FilePop(yyextra) )
  131. {
  132. return YY_NULL;
  133. }
  134. }
  135. %%
  136. /*--------------------------------------------------------------------------*/
  137. YY_BUFFER_STATE cmFortranLexer_GetCurrentBuffer(yyscan_t yyscanner)
  138. {
  139. /* Hack into the internal flex-generated scanner to get the buffer. */
  140. struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  141. return YY_CURRENT_BUFFER;
  142. }