cmCommandArgumentLexer.in.l 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. This file must be translated to C and modified to build everywhere.
  13. Run flex like this:
  14. flex --prefix=cmCommandArgument_yy --header-file=cmCommandArgumentLexer.h -ocmCommandArgumentLexer.cxx cmCommandArgumentLexer.in.l
  15. Modify cmCommandArgumentLexer.cxx:
  16. - add #include "cmStandardIncludes.h" to top of file
  17. - put header block at top of file
  18. - remove TABs
  19. - remove "yyscanner" argument from these methods:
  20. yy_fatal_error, cmCommandArgument_yyalloc, cmCommandArgument_yyrealloc, cmCommandArgument_yyfree
  21. - remove all YY_BREAK lines occurring right after return statements
  22. - change while ( 1 ) to for(;;)
  23. - add "return 0;" to end of cmCommandArgument_yylex
  24. Modify cmCommandArgumentLexer.h:
  25. - remove TABs
  26. - remove the yy_init_globals function
  27. - remove the block that includes unistd.h
  28. - remove #line directives (avoids bogus warning on old Sun)
  29. */
  30. #include "cmStandardLexer.h"
  31. #include "cmCommandArgumentParserHelper.h"
  32. /* Replace the lexer input function. */
  33. #undef YY_INPUT
  34. #define YY_INPUT(buf, result, max_size) \
  35. { result = yyextra->LexInput(buf, max_size); }
  36. /* Include the set of tokens from the parser. */
  37. #include "cmCommandArgumentParserTokens.h"
  38. /*--------------------------------------------------------------------------*/
  39. %}
  40. %option reentrant
  41. %option noyywrap
  42. %option nounput
  43. %pointer
  44. %s ESCAPES
  45. %s NOESCAPES
  46. %%
  47. \$ENV\{ {
  48. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  49. yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2);
  50. return cal_ENVCURLY;
  51. }
  52. \$[A-Za-z0-9/_.+-]+\{ {
  53. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  54. yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2);
  55. return cal_NCURLY;
  56. }
  57. @[A-Za-z0-9/_.+-]+@ {
  58. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  59. yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2);
  60. return cal_ATNAME;
  61. }
  62. "${" {
  63. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  64. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  65. yylvalp->str = yyextra->DCURLYVariable;
  66. return cal_DCURLY;
  67. }
  68. "}" {
  69. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  70. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  71. yylvalp->str = yyextra->RCURLYVariable;
  72. return cal_RCURLY;
  73. }
  74. "@" {
  75. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  76. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  77. yylvalp->str = yyextra->ATVariable;
  78. return cal_AT;
  79. }
  80. [A-Za-z0-9/_.+-]+ {
  81. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  82. yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  83. return cal_NAME;
  84. }
  85. <ESCAPES>\\. {
  86. if ( !yyextra->HandleEscapeSymbol(yylvalp, *(yytext+1)) )
  87. {
  88. return cal_ERROR;
  89. }
  90. return cal_SYMBOL;
  91. }
  92. [^\${}\\@]+ {
  93. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  94. yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  95. return cal_SYMBOL;
  96. }
  97. "$" {
  98. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  99. yylvalp->str = yyextra->DOLLARVariable;
  100. return cal_DOLLAR;
  101. }
  102. "{" {
  103. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  104. yylvalp->str = yyextra->LCURLYVariable;
  105. return cal_LCURLY;
  106. }
  107. <ESCAPES>"\\" {
  108. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  109. yylvalp->str = yyextra->BSLASHVariable;
  110. return cal_BSLASH;
  111. }
  112. <NOESCAPES>"\\" {
  113. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  114. yylvalp->str = yyextra->BSLASHVariable;
  115. return cal_SYMBOL;
  116. }
  117. %%
  118. /*--------------------------------------------------------------------------*/
  119. void cmCommandArgument_SetupEscapes(yyscan_t yyscanner, bool noEscapes)
  120. {
  121. /* Hack into the internal flex-generated scanner to set the state. */
  122. struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  123. if(noEscapes)
  124. {
  125. BEGIN(NOESCAPES);
  126. }
  127. else
  128. {
  129. BEGIN(ESCAPES);
  130. }
  131. }