cmCommandArgumentLexer.in.l 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 -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. #include "cmCommandArgumentParserHelper.h"
  15. /* Replace the lexer input function. */
  16. #undef YY_INPUT
  17. #define YY_INPUT(buf, result, max_size) \
  18. { result = yyextra->LexInput(buf, max_size); }
  19. /* Include the set of tokens from the parser. */
  20. #include "cmCommandArgumentParserTokens.h"
  21. static const char *DCURLYVariable = "${";
  22. static const char *RCURLYVariable = "}";
  23. static const char *ATVariable = "@";
  24. static const char *DOLLARVariable = "$";
  25. static const char *LCURLYVariable = "{";
  26. static const char *BSLASHVariable = "\\";
  27. /*--------------------------------------------------------------------------*/
  28. %}
  29. %option prefix="cmCommandArgument_yy"
  30. %option reentrant
  31. %option noyywrap
  32. %option nounput
  33. %pointer
  34. %s ESCAPES
  35. %s NOESCAPES
  36. %%
  37. \$ENV\{ {
  38. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  39. yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2);
  40. return cal_ENVCURLY;
  41. }
  42. \$[A-Za-z0-9/_.+-]+\{ {
  43. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  44. yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2);
  45. return cal_NCURLY;
  46. }
  47. @[A-Za-z0-9/_.+-]+@ {
  48. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  49. yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2);
  50. return cal_ATNAME;
  51. }
  52. "${" {
  53. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  54. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  55. yylvalp->str = DCURLYVariable;
  56. return cal_DCURLY;
  57. }
  58. "}" {
  59. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  60. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  61. yylvalp->str = RCURLYVariable;
  62. return cal_RCURLY;
  63. }
  64. "@" {
  65. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  66. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  67. yylvalp->str = ATVariable;
  68. return cal_AT;
  69. }
  70. [A-Za-z0-9/_.+-]+ {
  71. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  72. yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  73. return cal_NAME;
  74. }
  75. <ESCAPES>\\. {
  76. if ( !yyextra->HandleEscapeSymbol(yylvalp, *(yytext+1)) )
  77. {
  78. return cal_ERROR;
  79. }
  80. return cal_SYMBOL;
  81. }
  82. [^\${}\\@]+ {
  83. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  84. yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  85. return cal_SYMBOL;
  86. }
  87. "$" {
  88. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  89. yylvalp->str = DOLLARVariable;
  90. return cal_DOLLAR;
  91. }
  92. "{" {
  93. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  94. yylvalp->str = LCURLYVariable;
  95. return cal_LCURLY;
  96. }
  97. <ESCAPES>"\\" {
  98. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  99. yylvalp->str = BSLASHVariable;
  100. return cal_BSLASH;
  101. }
  102. <NOESCAPES>"\\" {
  103. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  104. yylvalp->str = BSLASHVariable;
  105. return cal_SYMBOL;
  106. }
  107. %%
  108. /*--------------------------------------------------------------------------*/
  109. void cmCommandArgument_SetupEscapes(yyscan_t yyscanner, bool noEscapes)
  110. {
  111. /* Hack into the internal flex-generated scanner to set the state. */
  112. struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  113. if(noEscapes) {
  114. BEGIN(NOESCAPES);
  115. } else {
  116. BEGIN(ESCAPES);
  117. }
  118. }