cmCommandArgumentLexer.in.l 3.8 KB

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