cmCommandArgumentLexer.in.l 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. This file must be translated to C++ and modified to build everywhere.
  6. Run flex >= 2.6 like this:
  7. flex --nounistd --never-interactive --batch -DFLEXINT_H --noline --header-file=cmCommandArgumentLexer.h -ocmCommandArgumentLexer.cxx cmCommandArgumentLexer.in.l
  8. Modify cmCommandArgumentLexer.cxx:
  9. - remove trailing whitespace: sed -i 's/\s*$//' cmCommandArgumentLexer.h cmCommandArgumentLexer.cxx
  10. - remove blank lines at end of file: sed -i '${/^$/d;}' cmCommandArgumentLexer.h cmCommandArgumentLexer.cxx
  11. - #include "cmStandardLexer.h" at the top: sed -i '1i#include "cmStandardLexer.h"' cmCommandArgumentLexer.cxx
  12. */
  13. /* IWYU pragma: no_forward_declare yyguts_t */
  14. #ifndef __clang_analyzer__ /* Suppress clang scan-build warnings */
  15. #include "cmCommandArgumentParserHelper.h"
  16. #define YY_USER_ACTION yyextra->UpdateInputPosition(yyleng);
  17. /* Include the set of tokens from the parser. */
  18. #include "cmCommandArgumentParserTokens.h"
  19. static const char *DCURLYVariable = "${";
  20. static const char *RCURLYVariable = "}";
  21. static const char *ATVariable = "@";
  22. static const char *DOLLARVariable = "$";
  23. static const char *LCURLYVariable = "{";
  24. static const char *BSLASHVariable = "\\";
  25. /*--------------------------------------------------------------------------*/
  26. %}
  27. %option prefix="cmCommandArgument_yy"
  28. %option reentrant
  29. %option noyywrap
  30. %option nounput
  31. %pointer
  32. %s ESCAPES
  33. %s NOESCAPES
  34. %%
  35. \$ENV\{ {
  36. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  37. yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2);
  38. return cal_ENVCURLY;
  39. }
  40. \$[A-Za-z0-9/_.+-]+\{ {
  41. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  42. yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2);
  43. return cal_NCURLY;
  44. }
  45. @[A-Za-z0-9/_.+-]+@ {
  46. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  47. yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2);
  48. return cal_ATNAME;
  49. }
  50. "${" {
  51. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  52. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  53. yylvalp->str = DCURLYVariable;
  54. return cal_DCURLY;
  55. }
  56. "}" {
  57. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  58. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  59. yylvalp->str = RCURLYVariable;
  60. return cal_RCURLY;
  61. }
  62. "@" {
  63. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  64. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  65. yylvalp->str = ATVariable;
  66. return cal_AT;
  67. }
  68. [A-Za-z0-9/_.+-]+ {
  69. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  70. yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  71. return cal_NAME;
  72. }
  73. <ESCAPES>\\. {
  74. if ( !yyextra->HandleEscapeSymbol(yylvalp, *(yytext+1)) )
  75. {
  76. return cal_ERROR;
  77. }
  78. return cal_SYMBOL;
  79. }
  80. [^\${}\\@]+ {
  81. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  82. yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  83. return cal_SYMBOL;
  84. }
  85. "$" {
  86. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  87. yylvalp->str = DOLLARVariable;
  88. return cal_DOLLAR;
  89. }
  90. "{" {
  91. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  92. yylvalp->str = LCURLYVariable;
  93. return cal_LCURLY;
  94. }
  95. <ESCAPES>"\\" {
  96. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  97. yylvalp->str = BSLASHVariable;
  98. return cal_BSLASH;
  99. }
  100. <NOESCAPES>"\\" {
  101. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  102. yylvalp->str = BSLASHVariable;
  103. return cal_SYMBOL;
  104. }
  105. %%
  106. /*--------------------------------------------------------------------------*/
  107. void cmCommandArgument_SetupEscapes(yyscan_t yyscanner, bool noEscapes)
  108. {
  109. /* Hack into the internal flex-generated scanner to set the state. */
  110. struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  111. if(noEscapes) {
  112. BEGIN(NOESCAPES);
  113. } else {
  114. BEGIN(ESCAPES);
  115. }
  116. }
  117. #endif /* __clang_analyzer__ */